solution link:

https://www.codechef.com/viewsolution/15933921

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.

Thanks:)

Stupid mistake

Guys, any idea what test case I have missed: https://www.codechef.com/viewsolution/15941870?

Thanks,

Dhruv

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).

now

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: https://ideone.com/lpSXiA . 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.