Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป
๋ฐ˜์‘ํ˜•

Algorithm 237

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์™„์ „ํƒ์ƒ‰ - ๋ชจ์˜๊ณ ์‚ฌ (feat. cycle ํ•จ์ˆ˜)

๋ฌธ์ œ๋งํฌ ๋‚˜์˜ ํ’€์ด 1,2,3๋ฒˆ์˜ ๋‹ต๋ณ€์ž๋Š” ๊ทœ์น™์ ์ธ ๋‹ต๋ณ€์„ ์ฐ์Œ --> ๋ฏธ๋ฆฌ ๋‹ต๋ณ€ list๋ฅผ ๊ตฌ์„ฑ 1,2,3๋ฒˆ์˜ ๋‹ต๋ณ€์ž๋Š” ๊ฐ๊ฐ a,b,c์˜ ๋ณ€์ˆ˜๋กœ ์ €์žฅํ•˜์—ฌ ์‚ฌ์šฉํ•  ๊ฒƒ์ž„ input๋˜๋Š” answers์˜ ๊ธธ์ด๋Š” 10000๊นŒ์ง€ ํ™•์žฅ๋  ์ˆ˜ ์žˆ์Œ. 1๋ฒˆ ๋‹ต๋ณ€์ž๊ฐ€ 5๊ฐœ๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๊ทœ์น™์„ ํ˜•์„ฑํ•˜๋ฏ€๋กœ, ๊ฐ€์žฅ ์ ์€ ๊ธธ์ด์ธ 1๋ฒˆ ๋‹ต๋ณ€์ž๋ฅผ ๊ธฐ์ค€์œผ๋กœ len(answers)์™€ ๊ธธ์ด๋ฅผ ๋งž์ถฐ์ฃผ์—ˆ์Œ. for ๋ฐ˜๋ณต๋ฌธ์„ ํ™œ์šฉํ•ด์„œ answers ์˜ ์ •๋‹ต๊ณผ ๋น„๊ต ์ •๋‹ต๋“ค์˜ max๊ฐ’์„ ๊ตฌํ•˜๊ณ  ๋™์ ์ž๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ, for๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ max๊ฐ’๊ณผ ๋™์ผํ•œ ๋‹ต๋ณ€์ž๋ฅผ index๋กœ ์ถ”์ถœ (abc๋กœ ์ง€์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์›ํ•˜๋Š” ๋‹ต๋ณ€์„ ์–ป์œผ๋ ค๋ฉด ์ธ๋ฑ์Šค๋กœ ์ถ”์ถœํ•ด์•ผํ•จ) ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ return def solution(answers): a = [1,..

[์•Œ๊ณ ๋ฆฌ์ฆ˜] ํƒ์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜ DFS, BFS

-- ๋ณธ ํฌ์ŠคํŒ…์€ ์ด๊ฒƒ์ด ์ทจ์—…์„ ์œ„ํ•œ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋‹ค with ํŒŒ์ด์ฌ ์ฑ…์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 1. DFS Depth First Search, ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰ ๊ทธ๋ž˜ํ”„์˜ ๊นŠ์€ ๋ถ€๋ถ„์„ ์šฐ์„ ์ ์œผ๋กœ ํƒ์ƒ‰ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฃผ๋กœ ์Šคํƒ์„ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ์‹์ž„ ์Šคํƒ : ํ›„์ž…ํ›„์ถœ) ๋™์ž‘๋ฐฉ์‹ ํƒ์ƒ‰ ์‹œ์ž‘ ๋…ธ๋“œ๋ฅผ ์Šคํƒ์— ์‚ฝ์ž…ํ•˜๊ณ  ๋ฐฉ๋ฌธ์ฒ˜๋ฆฌ๋ฅผ ํ•œ๋‹ค. ์Šคํƒ์˜ ์ตœ ์ƒ๋‹จ ๋…ธ๋“œ์— ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ์ธ์ ‘๋…ธ๋“œ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ทธ ์ธ์ ‘๋…ธ๋“œ๋ฅผ ์Šคํƒ์— ๋„ฃ๊ณ  ๋ฐฉ๋ฌธ์ฒ˜๋ฆฌ๋ฅผ ํ•œ๋‹ค. ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ์ธ์ ‘๋…ธ๋“œ๊ฐ€ ์—†์œผ๋ฉด ์Šคํƒ์—์„œ ์ตœ์ƒ๋‹จ ๋…ธ๋“œ๋ฅผ ๊บผ๋‚ธ๋‹ค. 2๋ฒˆ์˜ ๊ณผ์ •์„ ๋” ์ด์ƒ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์—†์„ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค. ๋™์ž‘๋ฐฉ์‹์„ ์•„๋ž˜ ๊ทธ๋ž˜ํ”„๋ฅผ ์˜ˆ์‹œ๋กœ ์‚ดํŽด๋ณด์ž. ๋งˆ์ง€๋ง‰์— "์Šคํƒ์ด ๋“ค์–ด๊ฐ„ ์ˆœ์„œ" ๋ฅผ ํ•œ๋ฐ ๋ชจ์•„๋ณด๋ฉด, 1,2,7,6,8,3,4,5 ๊ฐ€ ๋œ๋‹ค. โ–ถ DFS๋ฅผ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๊ธฐ ์œ„์™€..

Algorithm/Basic 2021.07.23

[์•Œ๊ณ ๋ฆฌ์ฆ˜] ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๊ทธ๋ž˜ํ”„๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ์‹ (์ธ์ ‘ํ–‰๋ ฌ ๋ฐฉ์‹, ์ธ์ ‘๋ฆฌ์ŠคํŠธ ๋ฐฉ์‹)

-- ๋ณธ ํฌ์ŠคํŒ…์€ ์ด๊ฒƒ์ด ์ทจ์—…์„ ์œ„ํ•œ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋‹ค with ํŒŒ์ด์ฌ ์ฑ…์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 1. ํƒ์ƒ‰์ด๋ž€ ๋งŽ์€ ์–‘์˜ ๋ฐ์ดํ„ฐ ์ค‘์—์„œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ๋Š” ๊ณผ์ • ๋Œ€ํ‘œ์ ์ธ ํƒ์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ DFS ์™€ BFS๊ฐ€ ์žˆ์Œ 2. ๊ทธ๋ž˜ํ”„ ํ‘œํ˜„ ๋ฐฉ์‹ ๊ทธ๋ž˜ํ”„์˜ ๊ตฌ์„ฑ : ๋…ธ๋“œ(์ •์ ), ๊ฐ„์„ (Edge) ๊ทธ๋ž˜ํ”„๋ฅผ ์ฝ”๋“œ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค 2.1 ์ธ์ ‘ํ–‰๋ ฌ ํ‘œํ˜„ ๋ฐฉ์‹ 2์ฐจ์› ๋ฐฐ์—ด๋กœ ๊ทธ๋ž˜ํ”„์˜ ์—ฐ๊ฒฐ๊ด€๊ณ„๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ์•„๋ž˜ ๊ทธ๋ž˜ํ”„๋ฅผ ํ‘œ๋กœ ํ‘œํ˜„ํ•˜๋ฉด ์˜ค๋ฅธ์ชฝ์˜ ํ‘œ์ฒ˜๋Ÿผ ํ‘œํ˜„์ด ๋  ๊ฒƒ์ด๋‹ค. ์ด ๊ทธ๋ž˜ํ”„๋ฅผ 2์ฐจ์› ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌ์„ฑํ•˜๊ฒŒ ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค INF = 999999 #๋ฌดํ•œ๋Œ€์˜ ๋น„์šฉ ์„ ์–ธ #2์ฐจ์› ๋ฐฐ์—ด์„ ํ™œ์šฉํ•˜์—ฌ ๊ทธ๋ž˜ํ”„๋ฅผ ํ‘œํ˜„ graph = [ [0, 7, 5], [7, 0 INF], [5, INF, 0] ] print(..

Algorithm/Basic 2021.07.23

[MySQL] HackerRank - Occupations

โ–ถ ๋ฌธ์ œ Occupation ํ…Œ์ด๋ธ”์€ ์•„๋ž˜์˜ ํ˜•ํƒœ๋ฅผ ๊ฐ€์ง„๋‹ค. ์กฐ๊ฑด1) ์ถœ๋ ฅ๋˜๋Š” ์ปฌ๋Ÿผ์˜ headers๋Š” Doctor, Professor, Singer, Actor ์ด์–ด์•ผ ํ•œ๋‹ค. ์กฐ๊ฑด2) ๋”์ด์ƒ ์ถœ๋ ฅ๋  ์ด๋ฆ„์ด ์—†์œผ๋ฉด NULL ์ด๋ผ๊ณ  ์ถœ๋ ฅ๋˜์–ด์•ผ ํ•œ๋‹ค. >> ์ถœ๋ ฅ์˜ˆ์ƒ ํ™”๋ฉด >> ์ถœ๋ ฅ์— ๋Œ€ํ•œ ์ถ”๊ฐ€ Explanation The first column is an alphabetically ordered list of Doctor names. The second column is an alphabetically ordered list of Professor names. The third column is an alphabetically ordered list of Singer names. The fourth colum..

[MySQL] HackerRank - Weather Observation Station 10

๋ฌธ์ œ https://www.hackerrank.com/challenges/weather-observation-station-10/problem Weather Observation Station 10 | HackerRank Query a list of CITY names not ending in vowels. www.hackerrank.com Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates. Input Format The STATION table is described as follows: where LAT_N is the northern latitude and..

[MySQL] HackerRank - Weather Observation Station 9

๋ฌธ์ œ https://www.hackerrank.com/challenges/weather-observation-station-9/problem Weather Observation Station 9 | HackerRank Query an alphabetically ordered list of CITY names not starting with vowels. www.hackerrank.com Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates. Input Format The STATION table is described as follows: where LAT_N ..

[MySQL] HackerRank - Weather Observation Station 8

๋ฌธ์ œ https://www.hackerrank.com/challenges/weather-observation-station-8/problem Weather Observation Station 8 | HackerRank Query CITY names that start AND end with vowels. www.hackerrank.com Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates. Input Format The STATION table is describe..

[MySQL] HackerRank - Weather Observation Station 7

๋ฌธ์ œ https://www.hackerrank.com/challenges/weather-observation-station-7/problem Weather Observation Station 7 | HackerRank Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. www.hackerrank.com Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates. Input Format The STATION table is described as follows: where ..

[MySQL] HackerRank - Weather Observation Station 6

๋ฌธ์ œ https://www.hackerrank.com/challenges/weather-observation-station-6/problem Weather Observation Station 6 | HackerRank Query a list of CITY names beginning with vowels (a, e, i, o, u). www.hackerrank.com Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates. Input Format The STATION table is described as follows: where L..

๋ฐ˜์‘ํ˜•