Missing in a Sorted Array of Natural Numbers#1340
Missing in a Sorted Array of Natural Numbers#1340sundeep4sandy wants to merge 1 commit intosuper30admin:masterfrom
Conversation
Interview Problem: Find Missing Number in a sorted array (FindMissingNumberInSortedArray.js)Your solution uses binary search correctly in terms of time and space complexity, but it has a logical flaw that causes it to fail in certain cases. Specifically, it does not account for the missing number being the first or last element in the range. Consider these cases:
Your current code only checks if the value at mid equals mid+1. This works correctly when the missing number is in the middle, but not at the boundaries. To fix this, you should:
Alternatively, you can adjust the binary search to account for these cases. The reference solution does this by comparing the difference between the value and the index. In a correct sequence without missing numbers, ar[i] should be i+1. So ar[i] - i should be constant (1). When a number is missing, this difference changes. In the reference solution, it checks:
This handles all cases including the boundaries. I suggest you revise your solution to include these checks. Also, improve the code readability by using more descriptive variable names and a more descriptive function name. VERDICT: NEEDS_IMPROVEMENT Interview Problem: Design Min HeapIt seems there might have been a misunderstanding. The problem was to design a Min Heap in Java, but your solution is written in JavaScript and solves a different problem (finding a missing number in a sorted array). To solve the Min Heap problem, you need to:
Your current solution does not address any of these requirements. Please review the problem statement again and implement the Min Heap as described. You can refer to the reference solution provided for guidance on how to structure your code. VERDICT: NEEDS_IMPROVEMENT |
No description provided.