Skip to content

[njngwn] WEEK 06 Solutions - #2786 - #2787

Open
njngwn wants to merge 5 commits into
DaleStudy:mainfrom
njngwn:main
Open

[njngwn] WEEK 06 Solutions - #2786#2787
njngwn wants to merge 5 commits into
DaleStudy:mainfrom
njngwn:main

Conversation

@njngwn

@njngwn njngwn commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Greedy
  • 설명: 좌우 포인터를 이동시키며 최댓값을 갱신하는 방식으로 면적을 계산하는 이중 포인터 패턴과, 매 단계에서 더 작은 벽을 포기하는 결정으로 최적 해를 점진적으로 탐색하는 그리디 성격이 보입니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n) O(n)
Space O(1) O(1)

피드백: 좌우 포인터를 한 칸씩 이동시키며 전체를 한 번만 훑는 방법으로 최댓값을 구한다.

개선 제안: 현재 구현이 적절해 보입니다.

@dalestudy

dalestudy Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

📊 njngwn 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
container-with-most-water Medium ✅ 의도한 유형
design-add-and-search-words-data-structure Medium ✅ 의도한 유형
longest-increasing-subsequence Medium ✅ 의도한 유형
spiral-matrix Medium ✅ 의도한 유형
valid-parentheses Easy ✅ 의도한 유형

누적 학습 요약

  • 풀이한 문제: 11 / 75개
  • 이번 주 유형 일치율: 100% (5문제 중 5문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Heap ■■□□□□□ 1 / 3 (Medium 1)
Array ■■□□□□□ 3 / 10 (Easy 3)
String ■■□□□□□ 3 / 10 (Medium 2, Easy 1)
Dynamic Programming ■■□□□□□ 3 / 11 (Easy 1, Medium 2)
Graph ■□□□□□□ 1 / 8 (Medium 1)
Binary □□□□□□□ 0 / 5 ← 아직 시작 안 함
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함
Linked List □□□□□□□ 0 / 6 ← 아직 시작 안 함
Matrix □□□□□□□ 0 / 4 ← 아직 시작 안 함
Tree □□□□□□□ 0 / 14 ← 아직 시작 안 함

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 2,078 220 2,298 $0.000192

@github-actions github-actions Bot added the py label Jul 31, 2026

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Trie, Depth-First Search, Backtracking
  • 설명: Trie를 이용해 단어를 저장하고 탐색하며, '.' 와일드카드를 재귀 DFS로 처리하는 구조로 패턴은 Trie와 DFS(Backtracking의 한 형태) 입니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: WordDictionary.addWord — Time: O(L) / Space: O(TotalNodes)
복잡도
Time O(L)
Space O(TotalNodes)

피드백: 트라이를 이용해 문자열 삽입 및 탐색을 구현했다. 삽입/공간 비용은 단어 길이에 비례한다.

개선 제안: 현재 구현이 적절해 보입니다.

풀이 2: WordDictionary.search — Time: O(Branching^W) / Space: O(H)
복잡도
Time O(Branching^W)
Space O(H)

피드백: 와일드카드 탐색으로 최악의 경우 다수의 경로를 탐색할 수 있다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

@njngwn njngwn moved this to In Review in 리트코드 스터디 8기 Jul 31, 2026

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search, Dynamic Programming, Greedy
  • 설명: 수열의 증가 부분수열 길이를 이분 탐색으로 갱신하는 패턴으로, LIS 문제에서 부분수열의 길이를 유지하며 최적화를 위해 이분 탐색을 사용합니다. DP 요소와 이분 탐색의 결합으로 O(n log n) 구현이 가능합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n*log(n)) O(n log n)
Space O(1) O(n)

피드백: 이분 탐색으로 최적의 증가 부분 수열의 길이를 유지한다.

개선 제안: 현재 구현이 적절해 보입니다.

Comment thread spiral-matrix/njngwn.py

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Monotonic Stack, Greedy, Divide and Conquer, Dynamic Programming
  • 설명: 스파이럴 순회는 방향 전환 및 경계 업데이트로 배열을 순차적으로 접근하는 패턴으로, 두 포인터를 이용한 연속 탐색과 경계 업데이트가 핵심이다. 방향 벡터와 네 방향으로의 순차 접근이 특징이다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n*m) O(m*n)
Space O(1) 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Stack / Queue (implemented as Deque), Greedy
  • 설명: 스택을 사용해 여는 괄호를 쌓고 닫는 괄호와 매칭하는 방식으로 구현되며, 올바른 함수 결과를 보장하기 위해 짝의 매칭 여부를 즉시 판단합니다. 이를 통해 선형 시간과 선형 공간 복잡도를 달성합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 짝이 맞지 않으면 즉시 False를 반환하도록 구현되어 있다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

@ICE0208
ICE0208 self-requested a review August 1, 2026 04:40

@ICE0208 ICE0208 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

안녕하세요. 이번 주 코드 리뷰를 맡은 ICE0208입니다.

전반적으로 깔끔하게 작성해 주셨고, 주석이 조금 더 추가되면 이해에 도움이 될 것 같습니다.

추가 의견과 질문은 코멘트로 남겨두었습니다. 이번 주도 고생 많으셨습니다!

Comment on lines +8 to +9
if len(s) % 2 != 0:
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

길이가 홀수인 경우 미리 반환해 불필요한 연산을 줄인 점이 좋네요!

Comment on lines +30 to +36
return True
return False
else:
if ch not in node.children:
return False
return dfs(node.children[ch], idx + 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ch == '.'인 경우 마지막에 return False로 종료되므로, else를 제거하면 중첩 깊이를 줄여 코드를 조금 더 간결하게 작성할 수 있을 것 같습니다!

Comment thread spiral-matrix/njngwn.py
Comment on lines +9 to +10

while left <= right and top <= bottom and 0 <= i < len(matrix) and 0 <= j < len(matrix[0]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

현재 방향 전환과 경계 갱신 로직이 정상적으로 동작한다면 i, j가 행렬 범위를 벗어날 일은 없을 것 같은데, while 조건에 좌표 범위 검사까지 추가하신 이유가 따로 있을까요? 어떤 의도로 작성하셨는지 궁금합니다!

Comment thread spiral-matrix/njngwn.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

오른쪽, 아래, 왼쪽, 위 순서로 이동하면서 경계 범위를 점차 줄여 나가는 방식이 인상적이었습니다. 좋은 로직 잘 보고갑니다!

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

수고하셨습니다. 복잡도 표기와 주석 수정이 필요해 보여서 request-changed로 남겨두었습니다.

Comment on lines +2 to +3
# Time Complexity: O(n*log(n)), n: len(nums)
# Space Complexity: 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.

seq가 최악의 경우 길이 n만큼 되서 SC는 O(n)이지 않을까요? ex. [1, 2, 3, 4, 5]

Comment on lines +13 to +19
left, right = 0, len(seq)
while left < right:
mid = (left + right) // 2
if seq[mid] < num:
left = mid + 1
else:
right = mid

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.

오 python bisect_left 랑 동일하게 구현하셨는데 원래 bisect_left 알고 계셨는지 궁금하네요. https://github.com/python/cpython/blob/7ce7f0bd8511410bf7c42cc5fc88dfafe07874b6/Lib/bisect.py#L74

seq.append(num)
continue

# insert with binary search

@parkhojeong parkhojeong Aug 1, 2026

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.

로직은 찾는 값보다 큰 값 중 가장 작은 데에 덮어 쓰는 동작으로 보이는데요. 주석을 insert, binary search 용어를 사용해서 적으신 이유가 있을까요? 지금 주석은 해당 값을 찾아서(탐색) 그 인덱스에 insert(python) 하는 동작으로 읽혀서요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants