Skip to content
41 changes: 41 additions & 0 deletions coin-change/sangbeenmoon.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Hash Map / Hash Set
  • 설명: 동전 교환 문제의 최소 동전 개수를 구하기 위해 하위 문제를 재귀적으로 해결하고, 결과를 메모이제이션으로 저장하는 DP 접근이며, 보조적으로 해시맵을 사용해 이미 계산한 타깃을 저장합니다.

📊 시간/공간 복잡도 분석

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

풀이 1: Solution.coinChange (first implementation) — Time: O(amount * len(coins)) / Space: O(amount)
복잡도
Time O(amount * len(coins))
Space O(amount)

피드백: 점화식을 재귀로 풀고 캐시를 사용해 중복 계산을 줄였지만 amount에 비례한 재귀 깊이가 필요하며, 최악의 경우 지수적 탐색을 피하기 어렵다.

개선 제안: 동적계획법의 순수한 바텀업(Bottom-Up) 접근이나 BFS 기반 풀이로 시간복잡도를 개선할 수 있다.

풀이 2: Solution.coinChange (second implementation) — Time: O(amount * len(coins)) / Space: O(amount)
복잡도
Time O(amount * len(coins))
Space O(amount)

피드백: 초기화된 memo에 목표 금액과 관련된 중간 결과를 저장해 중복 계산을 줄인다.

개선 제안: 반복적 DP(Bottom-Up)로 구현하면 함수 재귀 호출 오버헤드를 줄일 수 있다.

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

Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,44 @@ def go(self, x: int, coins: List[int]) -> int:
self.dp[x] = mm if mm != 100000 else -1 # memoization

return self.dp[x]








# --------

class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
memo = {}


for coin in coins:
memo[coin] = 1

def go(target: int) -> int:
if target < 0:
return -1

if target in memo:
return memo[target]

min_val = 10001

for coin in coins:
res = go(target - coin)
if res >= 0:
min_val = min(min_val, res)

memo[target] = (min_val + 1 if min_val != 10001 else -1)

return memo[target]

if amount == 0:
return 0

return go(amount)

22 changes: 22 additions & 0 deletions find-minimum-in-rotated-sorted-array/sangbeenmoon.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search
  • 설명: 회전된 정렬 배열에서 최솟값을 이진 탐색으로 찾는 방식으로, 중간 인덱스와 양 끝의 값 비교를 통해 탐색 범위를 반으로 축소합니다.

📊 시간/공간 복잡도 분석

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

풀이 1: Solution.findMin (first solution) — Time: O(log n) / Space: O(1)
복잡도
Time O(log n)
Space O(1)

피드백: 마지막 종료 조건이 명시적이지 않으나 일반적인 회전 배열 이진 탐색 패턴과 일치한다.

개선 제안: 특정 예외 케이스(중간값이 경계에 위치하는 경우)에 대한 명확한 처리 주석을 추가하면 가독성이 높아진다.

풀이 2: Solution.findMin (second solution) — Time: O(log n) / Space: O(1)
복잡도
Time O(log n)
Space O(1)

피드백: 조건 비교를 통해 경계를 엄밀하게 좁히도록 구현되어 있다.

개선 제안: 동일 로직의 중복 제거를 통해 코드 중복을 줄이면 좋다.

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

Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ def findMin(self, nums: List[int]) -> int:
right = mid

return nums[left]

# -----------

# TC : O(logN)
# SC : 1

class Solution:
def findMin(self, nums: List[int]) -> int:

left = 0
right = len(nums) - 1
mid = (left + right) // 2
Comment on lines +32 to +34

@parkhojeong parkhojeong Jul 18, 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.

이 부분 mid 할당은 중복으로 보여서 지워도 될 거 같습니다.


while left < right:
mid = (left + right) // 2

if nums[mid] > nums[right]:
Comment on lines +36 to +39

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.

탐색 중간에 정답인 경우 미리 리턴해보도록 해보셔도 좋을 거 같습니다.

left = mid + 1
else:
right = mid

return nums[left]
40 changes: 40 additions & 0 deletions word-search/sangbeenmoon.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Backtracking
  • 설명: 단어의 각 문자 위치를 탐색하면서 방향을 따라 방문 여부를 관리하는 재귀 DFS와, 실패 지점에서 다시 이전 상태로 되돌리는 백트래킹 패턴이 핵심이다.

📊 시간/공간 복잡도 분석

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

풀이 1: Solution.exist (첫 번째 구현) — Time: O(m * n * 4^L) / Space: O(m * n)
복잡도
Time O(m * n * 4^L)
Space O(m * n)

피드백: 백트래킹과 방문 기록을 통해 중복 경로를 제거하지만 최악의 경우 지수적 시간 복잡도가 발생할 수 있다.

개선 제안: 효율을 위해 감소된 상태 공간에서의 가지치기 조건 강화와 시간 복잡도 분석 명시가 필요하다.

풀이 2: Solution.exist (두 번째 구현) — Time: O(m * n * 4^L) / Space: O(m * n)
복잡도
Time O(m * n * 4^L)
Space O(m * n)

피드백: 각 위치에서 시작해 DFS를 진행하고 종료 조건을 명확히 처리한다.

개선 제안: 반복적 구현이나 최적화된 가지치기, 사전 인덱스 매핑 등을 통해 성능을 개선할 수 있다.

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

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.

요거 돌려보니 3000ms 정도 나오는데 최적화 좀더 해보셔도 좋을 거 같습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,43 @@ def dfs(self, board, word, cx, cy, idx):
self.visited[ny][nx] = True
self.dfs(board, word, nx, ny, idx + 1)
self.visited[ny][nx] = False


# ---

class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:

dx = [0,0,-1,1]
dy = [-1,1,0,0]

x_len , y_len = len(board[0]) , len(board)

visited = [[False] * x_len for _ in range(y_len)]

def go(xx: int, yy: int, pos: int) -> bool:

if pos >= len(word) - 1:
return True

for d in range(4):
nx = xx + dx[d]
ny = yy + dy[d]

if 0 <= nx and nx < x_len and 0 <= ny and ny < y_len:
if not visited[ny][nx] and board[ny][nx] == word[pos + 1]:
visited[ny][nx] = True
if go(nx,ny,pos+1):
return True
visited[ny][nx] = False
return False

for y in range(y_len):
for x in range(x_len):
if board[y][x] == word[0]:
visited[y][x] = True
if go(x,y,0):
return True
visited[y][x] = False

return False
Loading