Skip to content

Conversation

@ppxyn1
Copy link
Contributor

@ppxyn1 ppxyn1 commented Nov 16, 2025

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

def isAnagram(self, s: str, t: str) -> bool:
s_dic = Counter(sorted(s))
t_dic = Counter(sorted(t))
print(s_dic, t_dic)
Copy link
Contributor

Choose a reason for hiding this comment

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

probably better to remove print statement to reduce IO time

Suggested change
print(s_dic, t_dic)

Comment on lines +7 to +16
if n <= 2:
return n
dp = [0] * (n+1)
dp[2], dp[3] = 2, 3

#for i in range(4, n): error when n=4
for i in range(4, n+1):
dp[i] = dp[i-1] + dp[i-2]

return dp[n]
Copy link
Contributor

Choose a reason for hiding this comment

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

you can simplify it a bit

Suggested change
if n <= 2:
return n
dp = [0] * (n+1)
dp[2], dp[3] = 2, 3
#for i in range(4, n): error when n=4
for i in range(4, n+1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]
dp = [0] * (n+1)
dp[0], dp[1] = 1, 1
for i in range(2, n + 1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]

Comment on lines +1 to +3
# idea: DP
# I'm not always sure how to approach DP problems. I just try working through a few examples step by step and then check that it would be DP.
# If you have any suggestions for how I can come up with DP, I would appreciate your comments :)
Copy link
Contributor

@samcho0608 samcho0608 Nov 16, 2025

Choose a reason for hiding this comment

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

my rule of thumb is checking if current value(aka value at index) can be determined using the previous.

for instance, both #230 and #264 are both similar in that desired value at index can be determined using previous values.

  • Climbing Stairs #230 :
    • f(i) = # of possible combinations to reach i
    • can take 1 or 2 steps means that f(i) can be reached using:
      • f(i-1)—taking 1 step—and
      • f(i-2)—taking 2 steps—
    • thus, f(i) = f(i-1) + f(i-2)
  • House Robber #264 :
    • f(i) = max possible amount that can be robbed to reach i
    • cannot rob adjacent houses means that f(i) can be calculated using the max between:
      • f(i-1)—choosing not to rob house[i]—and
      • f(i-2)—choosing to rob house[i]
    • f(i) = max(f(i-1), f(i-2)) + house[i]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your detailed explanation! it was really helpful:)
I haven’t solved that many problems yet, so this might be why I have one more question: isn’t it easy to miss that a value can be determined using previous values when the step size is larger? For instance, dp[6] could be obtained from dp[1] and dp[5].

Copy link
Contributor

@samcho0608 samcho0608 Nov 20, 2025

Choose a reason for hiding this comment

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

@ppxyn1

That's why you gotta focus on the current affected by previous part (kinda like Induction proof from discrete math courses)

Begin with smaller n's and see if there is a pattern.

Take #230 with max step size up to 4 as an example(6 is too big for a written explanation of patterns).

  1. n=0: There's only one way (0)
  2. n=1: There's only one way (0->1)
  3. n=2: 2 because (0 -> 2 or 0 -> 1 -> 2)
    • f(0): 0 -> 2
    • f(1): 0 -> 1 -> 2
    • Already kinda seeing the pattern since we're seeing f(2) = f(0) + f(1)
  4. n=3: 4
    • f(0): 0 -> 3
    • f(1): 0 -> 1 -> 3
    • f(2):
      • 0 -> 2 -> 3
      • 0 -> 1 -> 2 -> 3
  5. n=4: 8
    • f(0): 0 -> 4
    • f(1): 0 -> 1 -> 4
    • f(2):
      • 0 -> 2 -> 4
      • 0 -> 1 -> 2 -> 4
    • f(3):
      • 0 -> 3 -> 4
      • 0 -> 1 -> 3 -> 4
      • 0 -> 2 -> 3 -> 4
      • 0 -> 1 -> 2 -> 3 -> 4

So the pattern is:
f(n) = f(n-1) + f(n-2) + .... f(n-k), where k is the step size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Appreciate it!

Copy link
Contributor

@dalestudy dalestudy bot left a comment

Choose a reason for hiding this comment

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

현재 주차가 종료되어 자동으로 승인되었습니다. PR을 병합해주세요!

@ppxyn1 ppxyn1 moved this from Solving to In Review in 리트코드 스터디 6기 Nov 21, 2025
@ppxyn1 ppxyn1 merged commit 1d0bf6d into DaleStudy:main Nov 21, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 6기 Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

2 participants