Skip to content

Competitive-Coding-1#1335

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

Competitive-Coding-1#1335
PritPanchani wants to merge 1 commit intosuper30admin:masterfrom
PritPanchani:master

Conversation

@PritPanchani
Copy link

No description provided.

@super30admin
Copy link
Owner

Your solution for the missing number problem is well-implemented. It correctly uses binary search to achieve O(log n) time and O(1) space. The logic is clear and concise. However, consider adding comments to explain the approach, especially since the problem is medium difficulty. For example, you could note that the array is expected to start at 1 and be consecutive except for one missing number, so the index (0-indexed) plus one should equal the value at that index until the missing point. This would make your code more understandable.

Also, while your solution handles edge cases correctly, it's always good to test with various scenarios (e.g., missing at start, end, or middle). You might want to write a few test cases to ensure robustness.

Regarding the min heap implementation: Although not required for this problem, it shows you are practicing data structures. However, for the purpose of this evaluation, we focus only on the missing number problem.

@super30admin
Copy link
Owner

Your solution for finding the missing number is correct and efficient. It correctly implements binary search to achieve O(log n) time complexity and O(1) space complexity. The code is clean and easy to understand. Well done!

However, consider adding comments to explain the logic, especially since the problem is medium difficulty. For example, you could note that the array is expected to start at 1 and be consecutive except for one missing number, and that the index (0-indexed) plus 1 should equal the value at that index until the missing number is encountered.

Also, note that the problem states the array is sorted and contains integers from 1 to n with one missing. Your solution assumes that the array is exactly as described, which is correct.

One minor point: in the binary search condition, you have while(low<=high), which is standard. However, the reference solution uses while ((b - a) > 1), which is a different condition. Both are correct, but your condition might lead to one more iteration in some cases, but it is still logarithmic.

Overall, excellent job.

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