Help me with the code

Hey @raj.verma5454
Your logic was completely correct. Great work. The only issue was variable type. You used int but you had to use long data type, since input range is 10^9, int works upto 10^5 only.

Hey @Aarnav-Jindal-1059677350830863 according to c++ documentation, size of int in ILP32 and above data models is 32 bits, which means that max range of int would be 2^32 - 1, which translates to -2147483648 to 2147483647. So int should work fine with 10^9 as well.

Buddy @Shadow_Flash I submitted this code with long data type and it passed all test cases but failed with int data type.

Furthermore different compilers have different range for data types. Try to print INT_MAX on compiler to check it.

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.