Why is this showing wrong answer

problem link : https://www.codechef.com/problems/STONES

link to my solution : https://www.codechef.com/viewsolution/24468259

Can u share ur approch, it might help to understand the code.

For solution you can simply create a unordered_set, then traverse through the string s and check if the particular character exist in set.
PS: If you need I can implement the code in python.

1 Like

I created two boolean arrays for size 54 for storing each character as true or false
1 to 26 stores ‘a’ to ‘z’ and 27 to 52 stores ‘A’ to ‘Z’ as true or false.
Then both the array’s are compared and the number of common character’s is found.

I guess you misread the question
The question is, “How many characters of S occur in J?”
So you have to consider your count variable for every character in the entire string S, i.e, not just the character set out of which S is constructed.

For example:
If J = “aaaaa” and S=“aaa”
The output is 3 and not 1.

Hope you understood! :slight_smile: