Skip to content

Competative Coding 3#1183

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

Competative Coding 3#1183
MeghaN28 wants to merge 1 commit intosuper30admin:masterfrom
MeghaN28:master

Conversation

@MeghaN28
Copy link
Copy Markdown

@MeghaN28 MeghaN28 commented May 5, 2026

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

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

Your solution is correct and efficient. You've correctly identified the time and space complexity. The code is well-structured and follows good practices with clear comments explaining the approach. One minor improvement: instead of using Arrays.asList(1) for the first row, which creates a fixed-size list, you are wrapping it in a new ArrayList which is good to avoid potential issues with fixed-size lists. However, note that Arrays.asList(1) returns a list containing a single integer 1, which is exactly what we need. Another small point: in the inner loop, you are iterating from j=0 to j<=i, which is correct for the row index i (which has i+1 elements). This is efficient and straightforward. Overall, excellent job!

VERDICT: PASS


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

Your solution is well-written and efficient. You correctly identified the use of a frequency map to count unique pairs. The code is clean and well-commented. However, there is one minor improvement: you can avoid using the variable "value" in the loop when k != 0, since it is only used for k=0. You can restructure the loop to only use the frequency for k=0. For example:

if (k == 0) {
if (entry.getValue() > 1) count++;
} else {
if (map.containsKey(entry.getKey() + k)) count++;
}

This is exactly what you did. So it's fine.

Another point: your solution is actually more efficient than the reference solution in terms of space because you don't store the pairs but only count them. The reference solution uses a set of vectors which might be less efficient.

Overall, great job!

VERDICT: PASS

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