i was trying to solve it by looking to geeks for geeks and many more site, but could not understood. Way you have explained is just commendable. Thank you so much
Wrong time complexity. In between you are sorting the array of frequencies. Best sorting algorithm will take O(NLog(N)) times at worst case. So, that will be dominant.
I agree, we have sorted the array. But the maximum number of integers in the array can be just 26. That is because of the length of english alphabet. So, sorting actually happens in linear time.
Can you please clarify why we need "first == 1" in if(first == 1 && second == last) return "YES". Because, with the previous condition, if(first == last), we will get to know that if first and last are matching. Now first is not matching. That's why we come to the second condition. At this point, first can have either 1 or 3. So checking first == 1 , is it valid? I checked in HackerRun without "first==1" and it runs fine for all testcases
I was trying to solve this Q only using strings and arrays...but I guess it is not possible, right? ( can we somehow do till the step where we receive an array "arr" with just using strings and arrays?)
I agree that this problem looks like a "string" problem but from what I learned while solving, it is more of a logical puzzle which involves a little math. Using string algorithms are usually slow and won't be solvable in the given time constraints.
Hello Sir, you have some great videos. But I have one question, as we use array.sort() : best time complexity that would give us is nlogn by quick sort. So, how is your whole solution is n??
Also sir, in our last if, we decided first==second and second == secondlast, why did you used second and secondlast rather than just first == secondlast ??
I agree, we have sorted the array. But the maximum number of integers in the array can be just 26. That is because of the length of english alphabet. So, sorting actually happens in linear time.
I agree, we have sorted the array. But the maximum number of integers in the array can be just 26. That is because of the length of english alphabet. So, sorting actually happens in linear time.
I guess we missed something in the questions here. The problem statement says - "remove just 1 character at **1 index** in the string", and we considered removing any 1 character from every index it appears. Or at least, that's what I understood.