Skip to content

Complete Competitive_Coding-3#1180

Open
dhruvil15 wants to merge 1 commit intosuper30admin:masterfrom
dhruvil15:master
Open

Complete Competitive_Coding-3#1180
dhruvil15 wants to merge 1 commit intosuper30admin:masterfrom
dhruvil15:master

Conversation

@dhruvil15
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Interview Problem : Pascal's Triangle (Problem42.java)

  1. Incorrect Problem Solution: You have solved a different problem (K-diff Pairs in an Array) instead of Pascal's Triangle. Please ensure you are addressing the correct problem statement.
  2. Misleading Comments: The comments mention time and space complexity as O(n), but this is for the wrong problem. For Pascal's Triangle, the correct complexity should be O(n^2) time and O(1) space (excluding output).
  3. Approach Mismatch: Your approach uses a HashMap and counts pairs, which is unrelated to generating Pascal's Triangle rows.
  4. Code Structure: While your code for the k-diff problem is structured well, it is not relevant here. For Pascal's Triangle, you need to generate each row based on the previous row using the property that each element is the sum of the two elements above it.

VERDICT: NEEDS_IMPROVEMENT


Interview Problem: Pairs with K difference (Problem43.java)

It appears that you have submitted a solution for a different problem (Pascal's Triangle) instead of the requested problem (Pairs with K difference). Please review the problem statement again and implement the correct solution.

For the k-diff pairs problem, you need to count unique pairs (i, j) such that the absolute difference between nums[i] and nums[j] is k. Note that pairs (a, b) and (b, a) are considered the same and should be counted only once.

Here are some hints for the correct approach:

  • You can use a hash map to store the frequency of numbers. This helps in quickly checking for complements.
  • For k > 0, you can iterate through the array and for each number, check if (number + k) exists in the map. Since k is positive, this is sufficient (because |a-b| = k implies either a = b + k or b = a + k).
  • For k = 0, you need to count pairs of the same number. So, you can count how many numbers have frequency greater than 1.
  • Alternatively, you can use a set to store unique pairs to avoid duplicates.

Please reimplement the solution for the correct problem. If you need help, refer to the reference solution provided.

VERDICT: NEEDS_IMPROVEMENT

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants