Thanks for walking us through the thought process. Great vid. I want to point out one thing though, your code works but not exactly in the way you're thinking ... your charCountsIdx is a simple integer which is immutable in python. After your first createString call, your charCountsIdx value is back to 0 when you call createString the second time.
Damn, you really do never stop learning! I didn't realize that in fact it was resetting back to 0, and I guess subsequently jumping back through all the characters until it reached the first occurrence of a non-zero-frequency character in the charCounts array. Thanks a lot for the correction. I'd like to pin this comment so people don't make the same mistake that I did :)
@@babybear-hq9yd seriously bro, it's a constant cycle of learning and losing sleep and hair in the process! i meant to post my regurgitation of your logic as well: def reorganizeString(self, S: str) -> str: charfreq = collections.Counter(S) n = len(S)
if max(charfreq.values()) > (n+1)/2: return ""
freqlist = list(charfreq.items()) freqlist.sort(key = lambda x: x[1], reverse=True) result = [""] * n writeidx = 0
for char, freq in freqlist: for i in range(freq): result[writeidx] = char writeidx += 2
Hello i need your help i want to ask you about a youtuber ( Amit Sengupta) how he make his video i mean which software or coding he is using to make these type of explanation video please help me.
Thanks for walking us through the thought process. Great vid. I want to point out one thing though, your code works but not exactly in the way you're thinking ... your charCountsIdx is a simple integer which is immutable in python. After your first createString call, your charCountsIdx value is back to 0 when you call createString the second time.
Damn, you really do never stop learning! I didn't realize that in fact it was resetting back to 0, and I guess subsequently jumping back through all the characters until it reached the first occurrence of a non-zero-frequency character in the charCounts array.
Thanks a lot for the correction. I'd like to pin this comment so people don't make the same mistake that I did :)
@@babybear-hq9yd seriously bro, it's a constant cycle of learning and losing sleep and hair in the process! i meant to post my regurgitation of your logic as well:
def reorganizeString(self, S: str) -> str:
charfreq = collections.Counter(S)
n = len(S)
if max(charfreq.values()) > (n+1)/2:
return ""
freqlist = list(charfreq.items())
freqlist.sort(key = lambda x: x[1], reverse=True)
result = [""] * n
writeidx = 0
for char, freq in freqlist:
for i in range(freq):
result[writeidx] = char
writeidx += 2
if writeidx >= n:
writeidx = 1
return "".join(result)
Please keep making videos. I really appreciate all your explanations. They are great!
thanks a lot :) so happy they help!
amazingly explained brother
thx man :)
Thanks so much for walking us through. I have a question in regards to this, why not use a maxheap to build the string?
This is exactly the same as distant barcodes right?
YES! That's the one, thank you! I knew I'd done a similar one but couldn't remember which one it was for the life in me. Hahah!
@@babybear-hq9yd hahaha yep I watched your distant barcodes video like 2 weeks ago and commented on it as well lol
@@babybear-hq9yd this is same as the Task Scheduler problem too
Hello i need your help i want to ask you about a youtuber ( Amit Sengupta) how he make his video i mean which software or coding he is using to make these type of explanation video please help me.