-
-
Notifications
You must be signed in to change notification settings - Fork 305
[imgolden77] WEEK 8 Solutions #2237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR contains Week 8 algorithm problem solutions covering 7 different LeetCode-style problems. The solutions demonstrate understanding of various data structures and algorithms including stacks, linked lists, bit manipulation, string processing, and graph traversal.
- Two implementations for valid-parentheses problem (initial and refactored)
- Solutions for linked list reversal, bit reversal, and palindrome counting
- Sliding window implementations for substring problems
- Graph cloning using DFS with memoization
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| valid-parentheses/imgolden77.py | Two implementations of parentheses validation using stack - first with explicit conditionals, second using dictionary mapping |
| reverse-linked-list/imgolden77.py | Iterative linked list reversal using three pointers (prev, curr, post) |
| reverse-bits/imgolden77.py | Bit manipulation solution to reverse 32-bit integer |
| palindromic-substrings/imgolden77.py | Expand-around-center approach to count palindromic substrings |
| longest-substring-without-repeating-characters/imgolden77.py | Two approaches - list-based and hash map-based sliding window |
| longest-repeating-character-replacement/imgolden77.py | Sliding window with character frequency tracking |
| clone-graph/imgolden77.py | DFS-based graph cloning with hash map for node mapping |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| elif i == ')': | ||
| if stack== []: | ||
| return False | ||
| elif stack[-1]== '(': |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around the equality operator. Should be 'stack[-1] == ' to match Python style conventions (PEP 8).
| else: | ||
| return False | ||
| elif i == '}': | ||
| if stack== []: |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around the equality operator. Should be 'stack == []' to match Python style conventions (PEP 8).
| elif i == '}': | ||
| if stack== []: | ||
| return False | ||
| elif stack[-1]== '{': |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around the equality operator. Should be 'stack[-1] == ' to match Python style conventions (PEP 8).
| elif i == ']': | ||
| if stack == []: | ||
| return False | ||
| elif stack[-1]== '[': |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around the equality operator. Should be 'stack[-1] == ' to match Python style conventions (PEP 8).
| if i in par_map.values(): | ||
| stack.append(i) | ||
| elif i in par_map: | ||
| if not stack or stack[-1] !=par_map[i]: |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around the inequality operator. Should be 'stack[-1] != par_map[i]' to match Python style conventions (PEP 8).
| if not stack or stack[-1] !=par_map[i]: | |
| if not stack or stack[-1] != par_map[i]: |
| for neighbors in curr_node.neighbors: | ||
| copy.neighbors.append(dfs(neighbors)) |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'neighbors' in the loop is misleading because it represents a single neighbor node, not multiple neighbors. It should be singular, like 'neighbor', to accurately reflect what it represents.
| for neighbors in curr_node.neighbors: | |
| copy.neighbors.append(dfs(neighbors)) | |
| for neighbor in curr_node.neighbors: | |
| copy.neighbors.append(dfs(neighbor)) |
| former= ['(', '{', '['] | ||
|
|
||
| for i in s: | ||
| if i in former: |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'former' should be 'opening' or 'opening_brackets' to better describe its purpose. The name 'former' is ambiguous and doesn't clearly convey that it contains opening parentheses.
| former= ['(', '{', '['] | |
| for i in s: | |
| if i in former: | |
| opening_brackets = ['(', '{', '['] | |
| for i in s: | |
| if i in opening_brackets: |
| seen[char] = seen.get(char, 0) + 1 | ||
| # what I wrote initially: | ||
| # if char not in seen: | ||
| # seen[char] = 1 | ||
| # else: | ||
| # seen[char] += 1 |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment appears to contain commented-out code.
| seen[char] = seen.get(char, 0) + 1 | |
| # what I wrote initially: | |
| # if char not in seen: | |
| # seen[char] = 1 | |
| # else: | |
| # seen[char] += 1 | |
| seen[char] = seen.get(char, 0) + 1 # update frequency of current character |
| class Solution: | ||
| def isValid(self, s: str) -> bool: | ||
| stack = [] | ||
| former= ['(', '{', '['] | ||
|
|
||
| for i in s: | ||
| if i in former: | ||
| stack.append(i) | ||
| elif i == ')': | ||
| if stack== []: | ||
| return False | ||
| elif stack[-1]== '(': | ||
| stack.pop() | ||
| else: | ||
| return False | ||
| elif i == '}': | ||
| if stack== []: | ||
| return False | ||
| elif stack[-1]== '{': | ||
| stack.pop() | ||
| else: | ||
| return False | ||
| elif i == ']': | ||
| if stack == []: | ||
| return False | ||
| elif stack[-1]== '[': | ||
| stack.pop() | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| if stack == []: | ||
| return True | ||
| else: | ||
| return False | ||
|
|
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to 'Solution' is unnecessary as it is redefined before this value is used.
| class Solution: | |
| def isValid(self, s: str) -> bool: | |
| stack = [] | |
| former= ['(', '{', '['] | |
| for i in s: | |
| if i in former: | |
| stack.append(i) | |
| elif i == ')': | |
| if stack== []: | |
| return False | |
| elif stack[-1]== '(': | |
| stack.pop() | |
| else: | |
| return False | |
| elif i == '}': | |
| if stack== []: | |
| return False | |
| elif stack[-1]== '{': | |
| stack.pop() | |
| else: | |
| return False | |
| elif i == ']': | |
| if stack == []: | |
| return False | |
| elif stack[-1]== '[': | |
| stack.pop() | |
| else: | |
| return False | |
| if stack == []: | |
| return True | |
| else: | |
| return False | |
| # (obsolete implementation removed; see the Solution class below) |
| h = [] | ||
| max_s = 0 | ||
| for i in s: | ||
| if i not in h: | ||
| h.append(i) | ||
| else: | ||
| h=h[h.index(i)+1:] | ||
| h.append(i) | ||
| #I reset h=[] but it had problemswith the cases like "dvdf" | ||
| #So I modified it to h=h[h.index(i)+1:] | ||
| max_s = max(max_s, len(h)) | ||
|
|
||
| return max_s | ||
|
|
||
| #O(N^2) time complexity due to "if i not in h" and O(min(m,n)) space complexity where m is the size of the charset and n is the size of the string s. | ||
|
|
||
| class Solution: | ||
| def lengthOfLongestSubstring(self, s: str) -> int: | ||
| seen = {} | ||
| start = 0 | ||
| max_len = 0 | ||
| for i, char in enumerate(s): | ||
| if char in seen and seen[char]>=start: | ||
| start= seen[char]+1 | ||
| seen[char]=i | ||
| max_len = max(max_len, i - start +1) | ||
|
|
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to 'Solution' is unnecessary as it is redefined before this value is used.
| h = [] | |
| max_s = 0 | |
| for i in s: | |
| if i not in h: | |
| h.append(i) | |
| else: | |
| h=h[h.index(i)+1:] | |
| h.append(i) | |
| #I reset h=[] but it had problemswith the cases like "dvdf" | |
| #So I modified it to h=h[h.index(i)+1:] | |
| max_s = max(max_s, len(h)) | |
| return max_s | |
| #O(N^2) time complexity due to "if i not in h" and O(min(m,n)) space complexity where m is the size of the charset and n is the size of the string s. | |
| class Solution: | |
| def lengthOfLongestSubstring(self, s: str) -> int: | |
| seen = {} | |
| start = 0 | |
| max_len = 0 | |
| for i, char in enumerate(s): | |
| if char in seen and seen[char]>=start: | |
| start= seen[char]+1 | |
| seen[char]=i | |
| max_len = max(max_len, i - start +1) | |
| seen = {} | |
| start = 0 | |
| max_len = 0 | |
| for i, char in enumerate(s): | |
| if char in seen and seen[char] >= start: | |
| start = seen[char] + 1 | |
| seen[char] = i | |
| max_len = max(max_len, i - start + 1) |
|
@DaleStudy 리뷰해줘 |
|
전체적으로 다양한 문제에 대해 깔끔하고 이해하기 쉬운 코드 구현이 돋보입니다. 다음은 몇 가지 건설적 피드백입니다.
전반적으로, 깔끔하고 효과적인 구현입니다. 약간의 스타일 개선과 더 명확한 복잡도 표기만 보완한다면 더욱 훌륭한 PR이 될 것 같습니다. 계속해서 좋은 코드 기대하겠습니다! |
TonyKim9401
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8주차 문제 풀이 고생하셨습니다.
연말&연초부터 여러 문제들 한번에 풀어주셨네요.
풀이들 모두 정석적으로 풀어주신것 같아습니다.
2026년 알고리즘 문제 풀이로 시작하신 만큼 커리어에서 원하는 쪽으로 더욱 승승장구 하시길 바라겠습니다.
9주차 문제풀이 파이팅입니다!
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!