Skip to content

[dolphinflow86] WEEK 12 Solutions - #2857

Merged
dolphinflow86 merged 5 commits into
DaleStudy:mainfrom
dolphinflow86:main
Sep 12, 2026
Merged

[dolphinflow86] WEEK 12 Solutions#2857
dolphinflow86 merged 5 commits into
DaleStudy:mainfrom
dolphinflow86:main

Conversation

@dolphinflow86

@dolphinflow86 dolphinflow86 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

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

  • same-tree
  • remove-nth-node-from-end-of-list
  • non-overlapping-intervals
  • number-of-connected-components-in-an-undirected-graph
  • serialize-and-deserialize-binary-tree

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

  • 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.

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

non-overlapping-intervals/dolphinflow86.py
# N is the number of intervals.
# TC: O(N log N) - sorts intervals by end time and performs a single pass
# SC: O(N) - space required for sorting


class Solution:

    def eraseOverlapIntervals(self, intervals: list[list[int]]) -> int:
        intervals.sort(key=lambda x: x[1])

        remove_count = 0
        prev_end = float("-inf")

        for start, end in intervals:
            if start < prev_end:
                remove_count += 1
            else:
                prev_end = end

        return remove_count
  • ํŒจํ„ด: Greedy, Sort / Order Statistics
  • ์„ค๋ช…: ๊ฐ„๊ฒฉ์„ ๋๋‚˜๋Š” ์‹œ์  ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ ๋’ค, ๊ฐ€๋Šฅํ•œ ํ•œ ๋งŽ์ด ๋‚จ๊ธฐ๋ ค๋Š” ์„ ํƒ์„ ํ•˜๋ฉฐ ์ถฉ๋Œ์„ ์ตœ์†Œํ™”ํ•˜๋Š” ๊ทธ๋ฆฌ๋”” ํŒจํ„ด์˜ ์ „ํ˜•์ ์ธ ์˜ˆ์ด๋‹ค. ๋์  ๊ธฐ์ค€ ์ •๋ ฌ๊ณผ ๋‹จ์ผ ์ˆœํšŒ๋กœ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ์ข…๋ฃŒ์ ์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ํ•œ ๋ฒˆ ์ˆœํšŒํ•˜์—ฌ ๊ฒน์น˜๋Š” ๊ตฌ๊ฐ„์˜ ์ˆ˜๋ฅผ ์„ผ๋‹ค. ์ถ”๊ฐ€ ๊ณต๊ฐ„์€ ์ƒ์ˆ˜๋กœ ์ถฉ๋ถ„ํ•˜๋‹ค.

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

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

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.

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

remove-nth-node-from-end-of-list/dolphinflow86.py
# N is the number of nodes in the linked list.
# TC: O(N) - single pass using two pointers with an (n + 1) gap
# SC: O(1) - modifies links in place using constant extra variables

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next


class Solution:

    def removeNthFromEnd(self, head, n: int):
        dummy = ListNode(0, head)
        fast = dummy
        slow = dummy

        for _ in range(n + 1):
            fast = fast.next

        while fast:
            fast = fast.next
            slow = slow.next

        slow.next = slow.next.next

        return dummy.next
  • ํŒจํ„ด: Two Pointers, Linked List
  • ์„ค๋ช…: ๋‘ ํฌ์ธํ„ฐ(๋‘ ์Šค์œ„์น˜ ํฌ์ธํ„ฐ)๋กœ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ํŒจํ„ด์ด๋ฉฐ, ํ•˜๋‚˜๋ฅผ n+1 ๋งŒํผ ์•ž์„œ ๋‘๊ณ , ๊ฐ™์ด ์›€์ง์—ฌ ์ œ๊ฑฐํ•  ๋…ธ๋“œ๋ฅผ ์ฐพ๋Š” ๋ฐฉ์‹์ด๋‹ค. ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ์—์„œ ๋์—์„œ k๋ฒˆ์งธ๋ฅผ ์ œ๊ฑฐํ•˜๋Š”ๅ…ธๅž‹ ๋ฌธ์ œ๋กœ O(N) ๋‹จ์ผ ํŒจ์Šค๋กœ ํ•ด๊ฒฐํ•œ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ๋”๋ธ” ํฌ์ธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด ํ•œ ๋ฒˆ์˜ ์ˆœํšŒ๋กœ ์ œ๊ฑฐ ๋Œ€์ƒ ์œ„์น˜๋ฅผ ์ฐพ๋Š”๋‹ค. ์ถ”๊ฐ€ ๊ณต๊ฐ„์€ ์ƒ์ˆ˜.

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

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

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.

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

same-tree/dolphinflow86.py
# N is the minimum number of nodes between trees p and q, and H is tree height.
# TC: O(N) - visits each node at most once comparing values
# SC: O(H) - recursion call stack proportional to tree height (O(N) in worst case)

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right


class Solution:

    def isSameTree(self, p, q) -> bool:
        if not p and not q:
            return True
        if not p or not q or p.val != q.val:
            return False

        return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
  • ํŒจํ„ด: Depth-First Search, Binary Search
  • ์„ค๋ช…: ๋‘ ์ด์ง„ํŠธ๋ฆฌ์˜ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ์žฌ๊ท€๋กœ ๋ฐฉ๋ฌธํ•˜๋ฉฐ ๋™์ผํ•œ์ง€ ๋น„๊ตํ•˜๋Š” DFS ํŒจํ„ด์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค. ํŠธ๋ฆฌ์˜ ์ขŒ์šฐ ์ž์‹์— ๋Œ€ํ•ด ๊ฐ™์€์ง€ ์žฌ๊ท€์ ์œผ๋กœ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ๊นŠ์ด์šฐ์„  ํƒ์ƒ‰์œผ๋กœ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•˜๋ฉฐ ๋น„๊ตํ•œ๋‹ค. ์ตœ์•…์˜ ๊ณต๊ฐ„์€ ํŠธ๋ฆฌ์˜ ๋†’์ด์— ๋น„๋ก€ํ•œ๋‹ค.

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

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

@dalestudy

dalestudy Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

๐Ÿ“Š dolphinflow86 ๋‹˜์˜ ํ•™์Šต ํ˜„ํ™ฉ

์ด๋ฒˆ ์ฃผ ์ œ์ถœ ๋ฌธ์ œ

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
alien-dictionary Hard โœ… ์˜๋„ํ•œ ์œ ํ˜•
meeting-rooms Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•
non-overlapping-intervals Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
remove-nth-node-from-end-of-list Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
same-tree Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•

๋ˆ„์  ํ•™์Šต ์š”์•ฝ

  • ํ’€์ดํ•œ ๋ฌธ์ œ: 55 / 75๊ฐœ
  • ์ด๋ฒˆ ์ฃผ ์œ ํ˜• ์ผ์น˜์œจ: 100% (5๋ฌธ์ œ ์ค‘ 5๋ฌธ์ œ ์ผ์น˜)

๋ฌธ์ œ ํ’€์ด ํ˜„ํ™ฉ

์นดํ…Œ๊ณ ๋ฆฌ ์ง„ํ–‰๋„ ์™„๋ฃŒ
Array โ– โ– โ– โ– โ– โ– โ–  10 / 10 (Medium 7, Easy 3)
Dynamic Programming โ– โ– โ– โ– โ– โ– โ–ก 10 / 11 (Easy 1, Medium 9)
String โ– โ– โ– โ– โ– โ– โ–ก 9 / 10 (Medium 5, Hard 1, Easy 3)
Linked List โ– โ– โ– โ– โ– โ– โ–ก 5 / 6 (Easy 3, Hard 1, Medium 1)
Binary โ– โ– โ– โ– โ– โ– โ–ก 4 / 5 (Easy 3, Medium 1)
Graph โ– โ– โ– โ– โ– โ–กโ–ก 6 / 8 (Medium 6)
Matrix โ– โ– โ– โ– โ– โ–กโ–ก 3 / 4 (Medium 3)
Heap โ– โ– โ– โ– โ– โ–กโ–ก 2 / 3 (Hard 1, Medium 1)
Tree โ– โ– โ– โ–กโ–กโ–กโ–ก 6 / 14 (Hard 1, Medium 3, Easy 2)
Interval โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 5 (Medium 1)

๐Ÿค– ์ด ๋Œ“๊ธ€์€ GitHub App์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ข API ์‚ฌ์šฉ๋Ÿ‰ (gpt-5-nano)
์š”์ฒญ ์ž…๋ ฅ ํ† ํฐ ์ถœ๋ ฅ ํ† ํฐ ํ•ฉ๊ณ„ ๋น„์šฉ
1 1,114 148 1,262 $0.000115
2 1,982 259 2,241 $0.000203
ํ•ฉ๊ณ„ 3,096 407 3,503 $0.000318

@parkhojeong parkhojeong left a comment

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.

์ด๋ฒˆ ์ฃผ๋„ ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

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.

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

alien-dictionary/dolphinflow86.py
# C is total length of all words, U is number of unique alien letters (<= 26).
# TC: O(C) - comparing adjacent words and processing topological sort graph
# SC: O(1) - unique letters and adjacency list bounded by 26 characters

from collections import deque


class Solution:

    def alienOrder(self, words) -> str:
        adj = {char: set() for word in words for char in word}
        indegree = {char: 0 for word in words for char in word}

        for i in range(len(words) - 1):
            w1, w2 = words[i], words[i + 1]
            min_len = min(len(w1), len(w2))

            if len(w1) > len(w2) and w1[:min_len] == w2[:min_len]:
                return ""

            for j in range(min_len):
                if w1[j] != w2[j]:
                    if w2[j] not in adj[w1[j]]:
                        adj[w1[j]].add(w2[j])
                        indegree[w2[j]] += 1
                    break

        queue = deque([char for char in indegree if indegree[char] == 0])
        result = []

        while queue:
            char = queue.popleft()
            result.append(char)

            for neighbor in adj[char]:
                indegree[neighbor] -= 1
                if indegree[neighbor] == 0:
                    queue.append(neighbor)

        if len(result) < len(indegree):
            return ""

        return "".join(result)
  • ํŒจํ„ด: Topological Sort, Hash Map / Hash Set, Breadth-First Search
  • ์„ค๋ช…: ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋Š” ์•ŒํŒŒ๋ฒณ ๊ฐ„ ์„ ํ›„๊ด€๊ณ„๋ฅผ ๊ทธ๋ž˜ํ”„๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์œ„์ƒ ์ •๋ ฌ์„ ํ†ตํ•ด ์ˆœ์„œ๋ฅผ ๊ตฌํ•œ๋‹ค. ๋˜ํ•œ ์ธ์ ‘ ๋ฆฌ์ŠคํŠธ์™€ indegree๋ฅผ ์ด์šฉํ•ด ๊ฐ„์„ ๊ณผ ๋…ธ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋ฏ€๋กœ ํ•ด์‹œ ๋งต/์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ BFS ์Šคํƒ€์ผ์˜ ํ๋ฅผ ์ด์šฉํ•œ ํƒ์ƒ‰์œผ๋กœ ์œ„์ƒ์ •๋ ฌ์„ ๊ตฌํ˜„ํ•œ๋‹ค.

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

๋ณต์žก๋„
Time O(N + E)
Space O(U + E)

ํ”ผ๋“œ๋ฐฑ: ๊ทธ๋ž˜ํ”„๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ์œ„์ƒ ์ •๋ ฌ(ํ ๊ธฐ๋ฐ˜ BFS)์„ ์ˆ˜ํ–‰ํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฌธ์ž์—ด์„ ์–ป๋Š”๋‹ค. ๋ชจ๋“  ๋ฌธ์ž์— ๋Œ€ํ•ด ๊ฐ„์„ ๊ณผ ์ง„์ž… ์ฐจ์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ ๋’ค, 0์ธ ๋…ธ๋“œ๋ถ€ํ„ฐ ์ฒ˜๋ฆฌํ•œ๋‹ค.

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

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

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.

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

meeting-rooms/dolphinflow86.py
# N is the number of intervals.
# TC: O(N log N) - sorting the intervals by start time
# SC: O(1) - constant extra space


class Solution:

    def canAttendMeetings(self, intervals) -> bool:
        intervals.sort(key=lambda x: x[0])

        for i in range(1, len(intervals)):
            if intervals[i][0] < intervals[i - 1][1]:
                return False

        return True
  • ํŒจํ„ด: Greedy, Binary Search, Two Pointers
  • ์„ค๋ช…: ํšŒ์˜์‹ค ๋ฐฐ์ • ๋ฌธ์ œ๋Š” ์‹œ์ž‘ ์‹œ๊ฐ„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ ๋’ค ์ธ์ ‘ ๊ฐ„๊ฒฉ์„ ๋น„๊ตํ•˜์—ฌ ๊ฒน์นจ์„ ํ™•์ธํ•œ๋‹ค. ๊ฐ„๋‹จํžˆ ํ•˜๋‚˜์˜ ์กฐ๊ฑด์„ ์ฒดํฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ตœ์ ์˜ ํƒ์ƒ‰ ์—†์ด๋„ ํ•ด๊ฒฐ๋˜๋‹ˆ Greedy๋กœ ๋ถ„๋ฅ˜๋˜๋ฉฐ, ์‹œ์ž‘์‹œ๊ฐ„ ์ •๋ ฌ์€ ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ์˜ ์„ ํ˜• ๊ฒ€์‚ฌ์— ํ•ด๋‹นํ•œ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ํšŒ์˜ ๊ฐ„์˜ ์ค‘๋ณต ์—ฌ๋ถ€๋ฅผ ์„ ํ˜• ์Šค์บ”์œผ๋กœ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์‹œ์ž‘ ์‹œ๊ฐ„์„ ๋จผ์ € ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

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

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

@dolphinflow86
dolphinflow86 merged commit 0e9c831 into DaleStudy:main Sep 12, 2026
1 check passed
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.

2 participants