Adding to @unlimited700 's answer . In Hackerrank , the feature is available , showing for which test case , the solution fails.
You are calculating same thing again and again. What you are doing is going through the entire string again and again h number of times where h is the number of â#â so that makes your algo O(hn) where n is length of string in worst cast n = 10000, h=10000 so clearly your code wonât run in the specified time limit. What you could have done is you could have stored the character frequency in each possible range when you were reading the input in O(n). And then calculate the frequency in each possible range in O(26). Hereâs my solution :- CodeChef: Practical coding for everyone
Third sample case was put there to drive home the condition. If it werenât there, I expect weâdâve got a LOT of âWhy is my code giving WAâ comments during the contest
that means for test case a#b#c#d#e, answer would be 7(Iâm still confused)
@devuy11 Had the same problem, I even misread it twice, when it appeared to be a lot simpler. Really need to focus more on constraints next time.
@pragrame It sure is harder to find, but my code, which I think would be correct without the constraint, still is pretty short(even shorter than what I submitted with the constraint) and very doable for most of the people who solved this problem by theirselfs I guess.
Yes, why donât you copy someoneâs AC solution and check for some self-generated tests to avoid your confusion.
@unlimited700, @tutulive - Is showing testcases for practice problems helpful or not is highly debatable. Without test cases you are forced to think of boundary conditions/cases which probably you wonât if you see them. It will prove helpful in the long run specially if you practice on SPOJ.
Hey, instead of posting your entire code here you can simply give the link to your solution here.
@r20rock the output for this test case
1
uuu####### yyy#yyy#yyy########### uuu
must be 15 whereas your code returns 0. Read the problem statement more carefully.