HackerRank - Sherlock and the Valid String | Full solution with examples and visuals

preview_player
Показать описание
Sherlock and the valid string is a programming challenge on HackerRank. A string is said to be valid if all the characters of the string appear the same number of times. It is also valid if one can remove any 1 character from the string and the remaining characters occur the same number of times.
Watch the video to understand the problem in a simplified manner. I then work along with you to solve it first using a Brute Force approach, and then an efficient approach. All along with visuals and explanations.

00:00 - Intro
01:12 - Problem Statement and Test Case
03:42 - Brute Force Solution
05:52 - Efficient Solution
10:36 - Dry-run of code
13:55 - Final thoughts

📚 Links I talk about in the video:

💻 Get Social 💻

#hackerrank #programming #interview
Рекомендации по теме
Комментарии
Автор

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

divyagupta
Автор

Awesome Explanation sir.
I am very eager to see more videos on your problem solving

surendharv
Автор

must say
really great explanation!!!!

amansharma-wwtv
Автор

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.

nilabhrabhattacharjee
Автор

very good Explanation and easy to understand

chandrakumara
Автор

Did your complexity analysis account for the sort for both time and space?

buuzinta
Автор

bhaiya mtbl gajab mindblowing, very impressive, zabardast

shantanu
Автор

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

jjoelthomas
Автор

Since we used Hashmap, I think the space will be O(n)?

srinivas
Автор

I agree with the others. You explained it very well.

tusharchandra
Автор

In which programming language sir r u explain

dineshchoudhary-yxun
Автор

Time complexity: O(n²) ?

Bcz, we sort the array

gokulakannan
Автор

i nearly got it on my own, but didnt know how to traverse values in map associated to key in java.

anubhavnegi
Автор

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?)

aniketroy
Автор

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??

fagunraythatha
Автор

possible try to solve merge two sort array without extra space please its confusing

gopinath
Автор

Please make a video on maximum palindrome hackerrank bcz there is no video in that no one can make me understand like u

sealovingsoura
Автор

Bro, TC is O(n logn) you have sorted the array..

amansrivastava
Автор

Very nice but very less problem your Channel contain

himanshukrdiwedi
Автор

There are 18 errors in your code when i run in cpp language

dineshchoudhary-yxun