Hi! I couldn’t understand how to reach to an optimal approach in this leetcode question please help.
287. Find the Duplicate Number
hello @rachitbansal2500
let say x is sum of element of the array.
and y is the number that is repeated .
so we can write it as
x = (n)*(n+1)/2 + y
now
y=x- n*(n+1)/2
x is known ,n is know so using their values we can find y. efficiently
The question states that the number might be repeated more than once, what to do in that case?
refer floyd algorithm (that u have learnt in linked list)
also detailed solution is mention in the solution tab, so u can refer that as well.
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.