v1#1179
Conversation
Interview Problem : Pascal's Triangle (pascals-triangle.py)Your solution is correct for the given examples and has the right time and space complexity. However, there are a few areas where you can improve:
Here's a revised version of your code that addresses these points: class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = []
for i in range(1, numRows+1):
row = [1] * i
if i > 2:
prevRow = res[-1]
for j in range(1, i-1):
row[j] = prevRow[j-1] + prevRow[j]
res.append(row)
return resThis version is cleaner and easier to read. VERDICT: PASS Interview Problem: Pairs with K difference (k-diff-pairs.py)Your solution is efficient and correct. You have used a Counter to count frequencies and then iterated over the unique numbers. For k != 0, you check if x + k exists in the counter, which ensures each pair is counted exactly once. For k=0, you check if the count is at least 2. This is a clean and efficient approach. Strengths:
Areas for improvement:
Overall, this is a very good solution. VERDICT: PASS |
No description provided.