It says time limit exceeded. I am a beginner in java and don’t know java in detail. There might be ways to this ques in much less time using some advanced concepts. But please try to keep it simple and try to suggest ways to improve my program.
First while loop is for test cases.
Second while loop runs until length of s is greater than 0, such that the string gets examined multiple times till it becomes non reducible.
first check: if length of string is not even then no is printed and loop breaks.
if length is even then i cycle through the string creating all possible substrings of even length(using two nested for loops).
the variable boolean reduced signifies if any part of string has been reduced or not .
if boolean reduced remains false after iterating through complete string this implies nothing in the string was reduced and consequently i break the loop.
The function checkdual (string x) checks if all the characters in the string are repeated even number of times.
Each time the function responds true for any substring , then that part of string is reduced and boolean reduced is turned true. And lastly if after reduction the length of string becomes 0 then yes is printed.
I feel rest is understandable.
I respect your individual solutions but it would be so kind of you if you help me improve mine.
checkDual method is correct. Just apply this method on the input string only and not on its substrings.
And I see you made an array of size 256 in checkDual. Just make an array of 26 since it will be only lowercase a-z .
If I make array of 26 it will only be capable of storing lower case letters . But what if the string contains capital letters or special characters, its nowhere mentioned in the question that string will only comprise lower letters. Please correct me if I am missing anything.
Thanks a lot buddy I got it now. Thank you for investing your time . It was really a lengthy code I had written.