problem link:https://www.interviewbit.com/problems/repeat-and-missing-number-array/
Solution link:https://ide.codingblocks.com/s/108400
The code is failing for larger inputs.
Finding repeated and missing number
@vrindabansal05
As you have correctly identified yourself , your code fails for large inputs. This is because you are taking a cube in Line No. 6
long long int supposedsquare=(n*(n+1)(2n+1))/6;
In this problem , n would be very large hence they want us to solve it in Linear Time Complexity , probably as large as 10^7 or 10^8.
Now if we were to take the cube or such large values , our result would surely exceed the range of long long int . Your result overflows and gives you the wrong answer.
Hence this approach of yours doesn’t work.
My suggestion : The best approach I could think of was using the bitwise operator XOR. Try to figure something out. This approach is somewhat related to how we solved the problem “Unique Number 2”.
Try to think about it. If you are still stuck , let me know and I will give you further hints to solve this problem.