Skip to content

[hwi-middle] WEEK 14 solutions#2625

Closed
hwi-middle wants to merge 2 commits into
DaleStudy:mainfrom
hwi-middle:main
Closed

[hwi-middle] WEEK 14 solutions#2625
hwi-middle wants to merge 2 commits into
DaleStudy:mainfrom
hwi-middle:main

Conversation

@hwi-middle
Copy link
Copy Markdown
Contributor

@hwi-middle hwi-middle commented Jun 3, 2026

๋‹ต์•ˆ ์ œ์ถœ ๋ฌธ์ œ

์ž‘์„ฑ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In Review๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ์ฝ”๋“œ ๊ฒ€ํ† ์ž 1๋ถ„ ์ด์ƒ์œผ๋กœ๋ถ€ํ„ฐ ์Šน์ธ์„ ๋ฐ›์œผ์…จ๋‹ค๋ฉด PR์„ ๋ณ‘ํ•ฉํ•ด์ฃผ์„ธ์š”.

๊ฒ€ํ† ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

Important

๋ณธ์ธ ๋‹ต์•ˆ ์ œ์ถœ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋ถ„ PR ํ•˜๋‚˜ ์ด์ƒ์„ ๋ฐ˜๋“œ์‹œ ๊ฒ€ํ† ๋ฅผ ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!

  • ๋ฐ”๋กœ ์ด์ „์— ์˜ฌ๋ผ์˜จ PR์— ๋ณธ์ธ์„ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์–ด๋กœ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.
  • ๋ณธ์ธ์ด ๊ฒ€ํ† ํ•ด์•ผํ•˜๋Š” PR์˜ ๋‹ต์•ˆ ์ฝ”๋“œ์— ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ์„ธ์š”.
  • ํ† ์š”์ผ ์ „๊นŒ์ง€ PR์„ ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์Šน์ธํ•ด์ฃผ์„ธ์š”.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: BFS
  • ์„ค๋ช…: ์ด ์ฝ”๋“œ๋Š” ํ๋ฅผ ์ด์šฉํ•œ ๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰(BFS)๋กœ ํŠธ๋ฆฌ์˜ ๊ฐ ๋ ˆ๋ฒจ์„ ์ˆœํšŒํ•˜๋ฉฐ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ๋ ˆ๋ฒจ๋ณ„ ๋…ธ๋“œ ๋ฐฉ๋ฌธ์— ์ ํ•ฉํ•œ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
Space O(n)

ํ”ผ๋“œ๋ฐฑ: ํ๋ฅผ ์ด์šฉํ•œ BFS๋กœ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ํ•œ ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๋ฏ€๋กœ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(n). ํ์™€ ๊ฒฐ๊ณผ ๋ฒกํ„ฐ์— ๋…ธ๋“œ ์ˆ˜๋งŒํผ ์ €์žฅํ•˜๋ฏ€๋กœ ๊ณต๊ฐ„ ๋ณต์žก๋„๋„ O(n).

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Bit Manipulation
  • ์„ค๋ช…: ์ด ์ฝ”๋“œ๋Š” ๋น„ํŠธ ์กฐ์ž‘ ๊ธฐ๋ฒ•์ธ i & (i - 1)์„ ์ด์šฉํ•˜์—ฌ ๊ฐ ์ˆซ์ž์˜ 1 ๋น„ํŠธ ๊ฐœ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋น„ํŠธ ์กฐ์ž‘ ํŒจํ„ด์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
Space O(n)

ํ”ผ๋“œ๋ฐฑ: DP๋ฅผ ํ™œ์šฉํ•˜์—ฌ i & (i - 1) ์—ฐ์‚ฐ์œผ๋กœ ์ด์ „ ๊ฐ’์— 1์„ ๋”ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ณ„์‚ฐ, ๋ชจ๋“  ์ˆ˜์— ๋Œ€ํ•ด ํ•œ ๋ฒˆ์”ฉ ๊ณ„์‚ฐํ•˜๋ฏ€๋กœ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(n). ๋ฐฐ์—ด ํฌ๊ธฐ๋งŒํผ ์ €์žฅํ•˜๋ฏ€๋กœ ๊ณต๊ฐ„๋„ O(n).

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Heap / Priority Queue
  • ์„ค๋ช…: ์ด ์ฝ”๋“œ๋Š” ๋‘ ๊ฐœ์˜ ํž™์„ ์ด์šฉํ•˜์—ฌ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ค‘์•™๊ฐ’์„ ์ฐพ๋Š” ๋ฐฉ์‹์œผ๋กœ, ์šฐ์„ ์ˆœ์œ„ ํ(ํž™)๋ฅผ ํ™œ์šฉํ•˜๋Š” ํŒจํ„ด์— ์†ํ•ฉ๋‹ˆ๋‹ค. ํž™์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ์˜ ์ค‘์•™๊ฐ’์„ ํšจ์œจ์ ์œผ๋กœ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(log n)
Space O(n)

ํ”ผ๋“œ๋ฐฑ: ํž™์„ ์ด์šฉํ•œ ๊ท ํ˜• ์œ ์ง€๋กœ ์‚ฝ์ž…๊ณผ ์กฐํšŒ ๋ชจ๋‘ O(log n). ๊ณต๊ฐ„์€ ์ €์žฅ๋œ ์ˆซ์ž ๊ฐœ์ˆ˜์— ๋น„๋ก€ํ•˜์—ฌ O(n).

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Dynamic Programming
  • ์„ค๋ช…: ์ด ์ฝ”๋“œ๋Š” ์›ํ˜• ๋ฐฐ์—ด์—์„œ ์—ฐ์†๋œ ์ง‘์„ ํ„ธ ๋•Œ, ์ตœ์ ์˜ ํ•ด๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด DP ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด์ „ ์ƒํƒœ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ตœ๋Œ“๊ฐ’์„ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ์‹์ด ํŠน์ง•์ž…๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
Space O(n)

ํ”ผ๋“œ๋ฐฑ: ๋‘ ๊ฐœ์˜ ์„ ํ˜• ๋ฌธ์ œ๋กœ ๋‚˜๋ˆ„์–ด DP ๊ณ„์‚ฐ, ๊ฐ๊ฐ O(n). ์ „์ฒด ์‹œ๊ฐ„์€ O(n). ๊ณต๊ฐ„๋„ DP ๋ฐฐ์—ด ํฌ๊ธฐ๋งŒํผ ์‚ฌ์šฉ.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

@hwi-middle hwi-middle closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant