Question from geeks for geeks

Hi , i could not solve this question from geeks for geeks,.
Here is the question link

https://practice.geeksforgeeks.org/problems/find-missing-and-repeating/0

and here is my solution .

https://ide.geeksforgeeks.org/dAo9aYhgYc

Kindly help me debug my code

The logic you used is not understandable, instead I would suggest you to make a temp array and use this logic


Hope this would help :grinning:

hey actually the space requirement is constant and time complexity required is O(n) therefore i tried to solve the question this way . Making an array or a map as such would not meet the space constraints specified in the question

Hey @imsharan0105, what you can do is iterate on elements of an array for eg : 1 3 3
And check :
if a[i+1] - a[i] > 1
Then a[i]+1 is your answer
else
Iterate on next element
Whereas iterate all element from [0,n-1]
Also check for side case like 1 2 2
In this one answer should be 3

Rest i will provide you with the code too , just have a little patience

Sure , thanks a lot for the help

Here’s the code :https://ide.codingblocks.com/s/330927
Hope it will hep you understand the concept better, moreover if there’s still any doubt about my approach you can also refer to this editorial https://www.geeksforgeeks.org/find-a-repeating-and-a-missing-number/
Hope now this will help :smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.