codeforces icon indicating copy to clipboard operation
codeforces copied to clipboard

Update 236A - Boy or Girl.cpp

Open mandeepish opened this issue 3 years ago • 0 comments

Instead of using nested for loops and comparing each element of the string with every other element, I used sets (#include). Since we don't care about the order of the distinct alphabets, we simply use a set (sets1) to store distinct (since set only takes unique values) alphabets from the string. Then we apply the basic s1.size() function to get the size of the distinct string and whether it's even or odd. This saves a lot of Time complexity and is a much cleaner approach.

PS : kindly ignore -> int = 0; It doesn't do anything.

mandeepish avatar Aug 24 '22 10:08 mandeepish