Good explanation, really simple solutions as well and supper easy to understand. Once you said Stack I pretty much came up with the same solution. :) thank you Nikhil !
I can’t provide the solution in JS but you can check the complete code in the video description…if you understand the logic correctly..writing in JS shouldn’t be a problem.
def short(s): #s=aaabccddd a=list(s) b=set(s) for i in b: c=s.count(i) if c%2==1: for j in range(c-1): a.remove(i) else: for j in range(c): a.remove(i) d=''.join(a) if len(d)==0: return "empty string" else: return d s="aabbb" print(short(s)) I wrote this but 6 test cases failed
What code did you come up with? I can help you understand your error. If I give you the solution right away, you wouldn’t learn. That is just the teacher in me speaking 🙂
this guy speaks with confidence
Eloquent solutions as usual.
The best solution I've seen. Thanks man : )
You're welcome!
Wow! I like your explanations! It certainly helps a lot!
Great video sir. Looking for more.
You got it!
Good explanation, really simple solutions as well and supper easy to understand. Once you said Stack I pretty much came up with the same solution. :) thank you Nikhil !
So happy I could help you out.
same here i was doing iteration first.
Thank you sir...💗
Good explanation
Can we use xor operations between characters of the string and get result for this?
Thank you ❤
public static String superReducedString(String s) {
Map charCount = new HashMap();
for (char c : s.toCharArray()) {
charCount.put(c, charCount.getOrDefault(c, 0) + 1);
}
Set set = new TreeSet();
for (char c : s.toCharArray()) {
if (charCount.get(c) % 2 == 1) {
set.add(c);
}
}
return (!set.isEmpty()) ? set.toString() : "Empty String";
}
Hi Sir, it would be great if you have JS version of the code.
I can’t provide the solution in JS but you can check the complete code in the video description…if you understand the logic correctly..writing in JS shouldn’t be a problem.
def short(s):
#s=aaabccddd
a=list(s)
b=set(s)
for i in b:
c=s.count(i)
if c%2==1:
for j in range(c-1):
a.remove(i)
else:
for j in range(c):
a.remove(i)
d=''.join(a)
if len(d)==0:
return "empty string"
else:
return d
s="aabbb"
print(short(s))
I wrote this but 6 test cases failed
have you tried debugging?
Sir Code for final thought
What code did you come up with? I can help you understand your error.
If I give you the solution right away, you wouldn’t learn. That is just the teacher in me speaking 🙂
@@nikoo28 Great Teacher😄
But this Approach will not work with this type of string ---> "abbxayzz" !
what output are you expecting for this particular string?
for the string "abbxayzz" the output will be -> "axay"...and the code works as expected.
Please clarify the doubt you are facing.
@@nikoo28 Output should be "xy" only.
abbxayzz
-> (remove b) axayzz
-> (remove z) axay
That’s it…you cannot remove ‘a’ because they are not consecutive
@@nikoo28 got it, thank you