๐ŸŒžAlgorithm/๐Ÿ”ฅprogrammers 43

[programmers] String, Date๋ฌธ - SQL ๊ณ ๋“์  Kit

5๋ฌธ์ œ๋ฅผ ์ ‘ํ•˜๋ฉฐ or, Like, CASE, DATEํ˜•์— ๊ด€ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋ฉฐ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์ด ์ค‘์—์„œ Like์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌํ•ด๋ณด์ž-! https://melody-coding.tistory.com/200 Like โ“Like - ํŠน์ • ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋œ ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰ # ex) EL์ด ๋“ค์–ด๊ฐ„ ๊ฒƒ ์ฐพ๊ธฐ SELECT [์ปฌ๋Ÿผ ๋ช…] FROM [ํ…Œ์ด๋ธ” ๋ช…] WHERE [์ปฌ๋Ÿผ ๋ช…] Like '%EL%' โ“์ข…๋ฅ˜ %๋ธ”๋ผ : ๋ธ”๋ผ๋กœ ๋๋‚˜๋Š” ๊ฒƒ์„ ๋ชจ๋‘ ์กฐํšŒ ๋ธ”๋ผ% : ๋ธ”๋ผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ melody-coding.tistory.com

[programmers] JOIN๋ฌธ - SQL ๊ณ ๋“์  Kit

์ฒ˜์Œ JOIN๋ฌธ์„ ์ ‘ํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ํ’€์–ด์•ผ ํ• ์ง€ ๋ชฐ๋ผ ์ฐพ์•„๋ดค์—ˆ๋‹ค. JOIN๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณธ ํ›„ ๋ฌธ์ œ์— ์ ์šฉํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ‘ธ๋Š” ๊ฒƒ์ธ์ง€ ๋งž๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ 4๋ฌธ์ œ๋ฅผ ํ†ต๊ณผํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ๋ถ€์กฑํ•˜์ง€๋งŒ ์•„์ฃผ ๊ฐ„๋‹จํ•˜๊ฒŒ JOIN์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด์ž! https://melody-coding.tistory.com/199 JOIN โ“JOIN SELECT A.๋ณ€์ˆ˜, A.๋ณ€์ˆ˜ from A JOIN B ON A.๋ณ€์ˆ˜ = B.๋ณ€์ˆ˜ WHERE B.๋ณ€์ˆ˜ ~~ โ“LEFT JOIN SELECT A.๋ณ€์ˆ˜, A.๋ณ€์ˆ˜ from A LEFT JOIN B ON A.๋ณ€์ˆ˜ = B.๋ณ€์ˆ˜ WHERE B.๋ณ€์ˆ˜ ~~~ JOIN๊ณผ LEFT JOIN ๋“ฑ ์ข…๋ฅ˜๊ฐ€ ๋‹ค์–‘.. melody-coding.tistory.com

[programmers] ๊ฐ€์žฅ ๋จผ ๋…ธ๋“œ

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ทธ๋ž˜ํ”„ ๋ฌธ์ œ ์„ค๋ช… n๊ฐœ์˜ ๋…ธ๋“œ๊ฐ€ ์žˆ๋Š” ๊ทธ๋ž˜ํ”„๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ๋…ธ๋“œ๋Š” 1๋ถ€ํ„ฐ n๊นŒ์ง€ ๋ฒˆํ˜ธ๊ฐ€ ์ ํ˜€์žˆ์Šต๋‹ˆ๋‹ค. 1๋ฒˆ ๋…ธ๋“œ์—์„œ ๊ฐ€์žฅ ๋ฉ€๋ฆฌ ๋–จ์–ด์ง„ ๋…ธ๋“œ์˜ ๊ฐฏ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๋ฉ€๋ฆฌ ๋–จ์–ด์ง„ ๋…ธ๋“œ๋ž€ ์ตœ๋‹จ๊ฒฝ๋กœ๋กœ ์ด๋™ํ–ˆ์„ ๋•Œ ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ๋…ธ๋“œ๋“ค์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋…ธ๋“œ์˜ ๊ฐœ์ˆ˜ n, ๊ฐ„์„ ์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ๋‹ด๊ธด 2์ฐจ์› ๋ฐฐ์—ด vertex๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, 1๋ฒˆ ๋…ธ๋“œ๋กœ๋ถ€ํ„ฐ ๊ฐ€์žฅ ๋ฉ€๋ฆฌ ๋–จ์–ด์ง„ ๋…ธ๋“œ๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ - ๋…ธ๋“œ์˜ ๊ฐœ์ˆ˜ n์€ 2 ์ด์ƒ 20,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. - ๊ฐ„์„ ์€ ์–‘๋ฐฉํ–ฅ์ด๋ฉฐ ์ด 1๊ฐœ ์ด์ƒ 50,000๊ฐœ ์ดํ•˜์˜ ๊ฐ„์„ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. - vertex ๋ฐฐ์—ด ๊ฐ ํ–‰ [a, b]๋Š” a๋ฒˆ ๋…ธ๋“œ์™€ b๋ฒˆ ๋…ธ๋“œ ์‚ฌ์ด์— ๊ฐ„์„ ์ด ์žˆ..

[programmers] ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ - 2022 KAKAO BLIND RECRUITMENT

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ์—ฐ์Šต - 2022 KAKAO BLIND RECRUITMENT ๋ฌธ์ œ ์„ค๋ช… ์ฃผ์ฐจ์žฅ์˜ ์š”๊ธˆํ‘œ์™€ ์ฐจ๋Ÿ‰์ด ๋“ค์–ด์˜ค๊ณ (์ž…์ฐจ) ๋‚˜๊ฐ„(์ถœ์ฐจ) ๊ธฐ๋ก์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ฐจ๋Ÿ‰๋ณ„๋กœ ์ฃผ์ฐจ ์š”๊ธˆ์„ ๊ณ„์‚ฐํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ํ•˜๋‚˜์˜ ์˜ˆ์‹œ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. (ํ‘œ ์ƒ๋žต) - ์–ด๋–ค ์ฐจ๋Ÿ‰์ด ์ž…์ฐจ ๋œ ํ›„์— ์ถœ์ฐจ๋œ ๋‚ด์—ญ์ด ์—†๋‹ค๋ฉด, 23:59์— ์ถœ์ฐจ๋œ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค. - 0000๋ฒˆ ์ฐจ๋Ÿ‰์€ 18:59์— ์ž…์ฐจ ๋œ ์ดํ›„, ์ถœ์ฐจ๋œ ๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, 23:59์— ์ถœ์ฐจ๋œ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค. - 00:00๋ถ€ํ„ฐ 23:59๊นŒ์ง€์˜ ์ž…/์ถœ์ฐจ ๋‚ด์—ญ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ฐจ๋Ÿ‰๋ณ„ ๋ˆ„์  ์ฃผ์ฐจ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•˜์—ฌ ์š”๊ธˆ์„ ์ผ๊ด„๋กœ ์ •์‚ฐํ•ฉ๋‹ˆ๋‹ค. - ๋ˆ„์  ์ฃผ์ฐจ ์‹œ๊ฐ„์ด ๊ธฐ๋ณธ ์‹œ๊ฐ„ ์ดํ•˜๋ผ๋ฉด, ๊ธฐ๋ณธ์š”๊ธˆ์„ ์ฒญ๊ตฌํ•ฉ๋‹ˆ๋‹ค. - ๋ˆ„์  ์ฃผ์ฐจ ์‹œ๊ฐ„์ด ๊ธฐ๋ณธ ์‹œ๊ฐ„์„ ์ดˆ๊ณผํ•˜๋ฉด, ๊ธฐ๋ณธ์š”๊ธˆ์— ๋”ํ•ด์„œ,..

[programmers] ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ - 2022 KAKAO BLIND RECRUITMENT

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ์—ฐ์Šต - 2022 KAKAO BLIND RECRUITMENT ๋ฌธ์ œ ์„ค๋ช… ์‹ ์ž…์‚ฌ์› ๋ฌด์ง€๋Š” ๊ฒŒ์‹œํŒ ๋ถˆ๋Ÿ‰ ์ด์šฉ์ž๋ฅผ ์‹ ๊ณ ํ•˜๊ณ  ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ฐœ๋ฐœํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ง€๊ฐ€ ๊ฐœ๋ฐœํ•˜๋ ค๋Š” ์‹œ์Šคํ…œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ์œ ์ €๋Š” ํ•œ ๋ฒˆ์— ํ•œ ๋ช…์˜ ์œ ์ €๋ฅผ ์‹ ๊ณ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. -์‹ ๊ณ  ํšŸ์ˆ˜์— ์ œํ•œ์€ ์—†์Šต๋‹ˆ๋‹ค. ์„œ๋กœ ๋‹ค๋ฅธ ์œ ์ €๋ฅผ ๊ณ„์†ํ•ด์„œ ์‹ ๊ณ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. -ํ•œ ์œ ์ €๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ์‹ ๊ณ ํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ๋™์ผํ•œ ์œ ์ €์— ๋Œ€ํ•œ ์‹ ๊ณ  ํšŸ์ˆ˜๋Š” 1ํšŒ๋กœ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค. k๋ฒˆ ์ด์ƒ ์‹ ๊ณ ๋œ ์œ ์ €๋Š” ๊ฒŒ์‹œํŒ ์ด์šฉ์ด ์ •์ง€๋˜๋ฉฐ, ํ•ด๋‹น ์œ ์ €๋ฅผ ์‹ ๊ณ ํ•œ ๋ชจ๋“  ์œ ์ €์—๊ฒŒ ์ •์ง€ ์‚ฌ์‹ค์„ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•ฉ๋‹ˆ๋‹ค. -์œ ์ €๊ฐ€ ์‹ ๊ณ ํ•œ ๋ชจ๋“  ๋‚ด์šฉ์„ ์ทจํ•ฉํ•˜์—ฌ ๋งˆ์ง€๋ง‰์— ํ•œ๊บผ๋ฒˆ์— ๊ฒŒ์‹œํŒ ์ด์šฉ ์ •์ง€๋ฅผ ์‹œํ‚ค๋ฉด์„œ ์ •์ง€ ๋ฉ”์ผ์„ ๋ฐœ์†กํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์ „์ฒด ์œ ์ € ๋ชฉ๋ก์ด..

[programmers] GROUP BY๋ฌธ - SQL ๊ณ ๋“์  Kit

4๋ฒˆ์งธ ๋ฌธ์ œ์—์„œ ์–ด๋ ค์›Œ ํ•œ์ฐธ ์ฐพ์•„๋ดค์—ˆ๋‹ค.. ๊ฒ€์ƒ‰์˜ ํž˜ ๐Ÿ‘Š ์ œ๋Œ€๋กœ ์ดํ•ดํ•œ ๊ฒƒ์ธ์ง€๋„ ๋ชจ๋ฅด๊ฒ ๋‹ค ๊ฐ‘์ž๊ธฐ Level 4๋ผ๋‹ˆ... ์ผ๋‹จ... ๋ฌธ์ œ ํ‘ผ ๊ฒƒ์„ ๋ฐ”ํƒ•์œผ๋กœ GROUP BY์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด์ž! https://melody-coding.tistory.com/181 GROUP BY, HAVING โ“GROUP BY - ๋ฐ์ดํ„ฐ๋ฅผ ์›ํ•˜๋Š” ๊ทธ๋ฃน์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Œ GROUP BY (์—ด) โ“HAVING - GROUP BY์™€ ํ•จ๊ป˜ ์“ฐ์ž„ - GROUP ์ค‘ ์กฐ๊ฑด์— ๋งž๋Š” GROUP๋งŒ ๋‚จ๊น€ SELECT (์—ด) FROM (ํ…Œ์ด๋ธ” ๋ช…) GROUP BY (์—ด) HAVING (์กฐ๊ฑด) โ“์ถ”๊ฐ€.. melody-coding.tistory.com

[programmers] IS NULL๋ฌธ - SQL ๊ณ ๋“์  Kit

๋ฌธ์ œ ํ‘ผ ๊ฒƒ์„ ๋ฐ”ํƒ•์œผ๋กœ NULL์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด์ž! https://melody-coding.tistory.com/179 IS NULL โ“NULL์ธ ๊ฒƒ์„ ์กฐํšŒ WHERE (์—ด) is NULL โ“NULL์ด ์•„๋‹Œ ๊ฒƒ์„ ์กฐํšŒ WHERE (์—ด) is not null โ“NULL๊ฐ’ ์น˜ํ™˜ SELECT IFNULL((์—ด), '๋ธ”๋ผ๋ธ”๋ผ') FROM (ํ…Œ์ด๋ธ” ๋ช…) melody-coding.tistory.com

[programmers] SUM,MAX,MIN๋ฌธ - SQL ๊ณ ๋“์  Kit

๋ฌธ์ œ ํ‘ผ ๊ฒƒ์„ ๋ฐ”ํƒ•์œผ๋กœ MAX, MIN, COUNT, DISTINCT๋ฅผ ์ •๋ฆฌํ•ด๋ณด์ž! https://melody-coding.tistory.com/177 MAX, MIN, COUNT, DISTINCT โ“MAX SELECT max(์—ด) FROM (ํ…Œ์ด๋ธ”) โ“MIN SELECT min(์—ด) FROM (ํ…Œ์ด๋ธ”) โ“COUNT SELECT count(*) as (์—ด ์ด๋ฆ„) FROM (ํ…Œ์ด๋ธ”) count(*) : ํ…Œ์ด๋ธ” ์ „์ฒด์˜ ํ–‰ ๊ฐœ์ˆ˜, null ํฌํ•จ count(์—ด): ํŠน์ • ์—ด์˜ ๊ฐœ์ˆ˜, null.. melody-coding.tistory.com

[programmers] SELECT๋ฌธ - SQL ๊ณ ๋“์  Kit

programmers ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ์—ฐ์Šต์— SQL ๊ณ ๋“์ ‘ Kit๊ฐ€ ์žˆ์–ด ์˜ค๋Š˜ ํ•œ๋ฒˆ ๋„์ „ํ•ด๋ดค๋‹ค. SQL๋ฌธ์€ ์•ˆ์“ด์ง€ ์˜ค๋ž˜ ๋˜์–ด SELECT๋ฌธ์„ ์ฐพ์•„์„œ ์ •๋ฆฌํ•ด๋‘” ๊ฒƒ์„ ์‚ดํŽด๋ณธ ํ›„ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ดค๋‹ค. ๋ฌธ์ œ ํ‘ผ ๊ฒƒ์„ ๋ฐ”ํƒ•์œผ๋กœ SELECT๋ฌธ์„ ์ •๋ฆฌํ•ด๋ณด์ž! https://melody-coding.tistory.com/174 SELECT SELECT [์—ด] FROM [Table ์ด๋ฆ„] WHERE [์กฐ๊ฑด] ORDER BY [์—ด] [ASC/DESC ์˜ค๋ฆ„,๋‚ด๋ฆผ์ฐจ์ˆœ] [limit n ์ƒ์œ„ n๊ฐœ] SELECT [์—ด] FROM [Table ์ด๋ฆ„] : ํ…Œ์ด๋ธ”์—์„œ ์กฐํšŒํ•  ์—ด์„ ์„ ํƒํ•œ๋‹ค. WHERE [์กฐ๊ฑด] : ์กฐํšŒํ•  ์กฐ๊ฑด์„ ์ž….. melody-coding.tistory.com

[programmers] ๊ฐ€์žฅ ๊ธด ํŒฐ๋ฆฐ๋“œ๋กฌ - ์—ฐ์Šต๋ฌธ์ œ

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ์—ฐ์Šต ๋ฌธ์ œ ์„ค๋ช… ์•ž๋’ค๋ฅผ ๋’ค์ง‘์–ด๋„ ๋˜‘๊ฐ™์€ ๋ฌธ์ž์—ด์„ ํŒฐ๋ฆฐ๋“œ๋กฌ(palindrome)์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด s๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, s์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด(Substring)์ค‘ ๊ฐ€์žฅ ๊ธด ํŒฐ๋ฆฐ๋“œ๋กฌ์˜ ๊ธธ์ด๋ฅผ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ๋ฌธ์ž์—ด s๊ฐ€ "abcdcba"์ด๋ฉด 7์„ return ํ•˜๊ณ  "abacde"์ด๋ฉด 3์„ return ํ•ฉ๋‹ˆ๋‹ค. ์ œํ•œ์‚ฌํ•ญ -๋ฌธ์ž์—ด s์˜ ๊ธธ์ด : 2,500 ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜ -๋ฌธ์ž์—ด s๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ๋ฌธ์ œ ํ’€์ด - my solution def solution(s): answer = 1 # ๋ฌธ์ž์—ด ๊ธธ์ด 1 for i in range(len(s)-1): # ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜ - ๋ฌธ์ž์—ด for j in range(i,len(s)): temp=s[i:j..