solution link:
what is wrong with the solution

Hey @viralivora

Your code fails for this test case.

You have not considered the possibility of integer overflow. The length of the string can be equal to 10^5 and in these cases your count variable can also be equal to 10^5 and then count*(count+1) will result in integer overflow condition. Try using long long int.

1 Like

Stupid mistake

Guys, any idea what test case I have missed:

Hey guys, please anyone solve my doubt.

when I make variable β€œi”, β€œj” and β€œn” type of integer(refer codes given below) then error occurs(wrong answer).


when I make variable β€œi”, β€œj” and β€œn” type of long then solution got accepted.

now question is that how can value of these variable exceeds the capacity of integer(in JAVA 64-bit), as in question they have provided that maximum possible length of the string is only 100000 (|A| <= 10^5).

thanks for help.

my solution link which gives wrong answer - wrong solution

my solution link which gives write answer - write solution

Hey @pvimal816

Have a look at this code: . This might clear your doubt. When you are multiplying two int values and then dividing it by 2, at that step you will get the integer overflow condition. There are two ways to solve this problem, either by using long values as input or typecasting the variable at the time of multiplication.

Hey Dhruv, did you find the problem with the solution or do you still need some debugging? I don’t know how I missed reading this answer.