Important Interview Question: How to Print count of duplicate characters from String? ||

  Рет қаралды 92,894

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер: 69
@sridharlanka2721
@sridharlanka2721 3 жыл бұрын
Truly an "Approach" for Problem solving , and i just learned it!
@AshutoshMishra-qc7nl
@AshutoshMishra-qc7nl 3 жыл бұрын
I got this question in TechnoManagerial interview today only. But I didnt solved in this way. I used your previous tutorial login, did a split of string and kept it in a list, ran 2 for loops for i and i+1 checking and printing any repetitive keywords. Will keep this also in mind
@santoshkumarvlogs3753
@santoshkumarvlogs3753 8 ай бұрын
can you put that solution here @ashutoshMishra
@bhuvanabaskaran8063
@bhuvanabaskaran8063 3 жыл бұрын
Crystal and clear explanation... Thank you so much Naveen..keep up the great work.. wishing you all success...you will be blessed forever...Thanks a tonneeee
@Tidda420
@Tidda420 3 жыл бұрын
We can use ctrl + 1 + Enter after ; to get automatic assignment variable but this is applicable only if using eclipse otherwise we have to write it on our own.
@vishnuchandar7073
@vishnuchandar7073 3 жыл бұрын
Naveen, as you are the Master of Masters. Thanks for helping me alot in learning. If i want to know what else should i study in Automation , i dont need Google, i just need to visit your youtube page. Thanks. An alternative way to solve the same. Set set = new HashSet(); for(char ch : str.toCharArray()) if(StringUtils.countMatches(str, ch) > 2 && !set.contains(ch)) { System.out.println(ch); set.add(ch); } System.out.print(set);
@deepakchandrashekar1023
@deepakchandrashekar1023 3 жыл бұрын
The question is "Print duplicate characters from String" but the solution also contains the count of duplicate characters in a given string 👍
@tapaskhandai
@tapaskhandai 2 жыл бұрын
In that case you can only print keys not values
@WMohanty
@WMohanty 3 жыл бұрын
what an explanation. God bless you Naveen...
@abhishekshandilya4052
@abhishekshandilya4052 3 жыл бұрын
I have paused the video to thankyou, loved the way you have explained.
@paladarsh39
@paladarsh39 3 жыл бұрын
Thanks solving this, was asked the same question with a extra condition which was that I have to print the map in the descending order of the repetitive elements.
@shirishan4525
@shirishan4525 4 ай бұрын
for how many year exp you were asked this question??
@VinayakTungal
@VinayakTungal 3 жыл бұрын
Good approach! 👍 Another case that might be worth considering, is the way white-spaces are treated in this construct. Spaces are neither empty, nor null. So if it's a string full of spaces, what would it be treated as.
@souvikchatterjee7400
@souvikchatterjee7400 3 жыл бұрын
This is the question I have come across in interview multiple times. Thing is in some cases I write the main logic but forget to handle the edge cases. Still they gave me the interview clearance 😐
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
edge cases will always give you bonus points.
@vikassinghal9413
@vikassinghal9413 3 жыл бұрын
This worked as well public static void printviaHashMap(String inputString) { inputString=inputString.toLowerCase(); Map dup = new HashMap(); for(String ch:inputString.split("")) { Integer count = dup.get(ch); dup.put(ch, count==null?1:count+1); }System.out.println(dup); }
@ayushgupta8239
@ayushgupta8239 3 жыл бұрын
Why not just use syso(map) or arrays.aslist or collection? Also I think keyset would be enough to print the keys one by one and then using key to print the value.
@maywellbeaghost6364
@maywellbeaghost6364 3 жыл бұрын
Good method of solve this particular problem. But, I feel how fast this will go as an obsolete process
@maneeshbuddha8253
@maneeshbuddha8253 Жыл бұрын
Hi Naveen,Please do the video on these 2 programs.Java program to print alternate odd numbers which are divisible by 3 and 7 in between 100 to 1000.Java program to print print fibonacci series in reverse order starting from 1000 to 100.
@phanikumarvishnubhotla1804
@phanikumarvishnubhotla1804 7 ай бұрын
For first program mate public static void main(String[] args) { int count=0,count1=0; for(int i=100;i
@MrAsgar123
@MrAsgar123 2 жыл бұрын
Thank you so much for your easy explaination.
@anushap2139
@anushap2139 2 жыл бұрын
I really like your voice 😊
@sonumishra6747
@sonumishra6747 3 жыл бұрын
I think 2 for loop and a string and int max count would do the job. No need of maintaining map set iterating again on it.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Two for loops will give you O(n^2). But ya would like to see your solution how would you get the max count?
@ShinAkuma
@ShinAkuma 3 жыл бұрын
@@naveenautomationlabs Just take a integer array of 26 size and update the (char-65)th index on every iteration. You can get the duplicates in O(n+26) complexity
@vengateshm2122
@vengateshm2122 3 жыл бұрын
Thank you. Time complexity? Space complexity? It would be helpful if you could give a hint on the above for different interview questions.
@fazex4185
@fazex4185 3 жыл бұрын
Time complexity I suppose n + k where k is the number of unique characters.
@amanuellebassi7294
@amanuellebassi7294 3 жыл бұрын
Great technique
@sweetthirty2
@sweetthirty2 3 жыл бұрын
Sir how to print "I love java" into "java love I" plzzz make a video on this frequently getting this problem
@tapaskhandai
@tapaskhandai 3 жыл бұрын
Hi Naveen, please try to start a series of c# with selenium
@tapaskhandai
@tapaskhandai 2 жыл бұрын
Hi Naveen, in this case how we can print the 1st repeatative character?
@prasanthraviv
@prasanthraviv 3 жыл бұрын
Thanks Naveen
@harinig2874
@harinig2874 3 жыл бұрын
Naveen , question is like how come hashmap storing duplicate key ? like a,1 ,a,2,a,3
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Watch this video kzbin.info/www/bejne/iYnJpHV6idSXprs
@sssaamm29988
@sssaamm29988 3 жыл бұрын
Nice video.should we not use if else conditon? I see that you have used multiple if's.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
It doesn't matter here. We are returning void return from each if condition.
@jeyhunaliyev1765
@jeyhunaliyev1765 3 жыл бұрын
Second here 👍😄✊
@shivashanker1315
@shivashanker1315 3 жыл бұрын
Hi Naveen, can you help me with the below one. Remove the duplicates from the string, Example: S=”cbbadaabaaebccd”, Condtions: on the 1st iteration, Highest repetitive letter should be removed like “cbbdbebccd”, 2nd iteration, Highest repetitive letter should be removed like “cbbdbebccd” and Final Output should be “e”.
@RohanKumar-bo6fi
@RohanKumar-bo6fi 2 жыл бұрын
Hello sir, one doubt I have So when we want to print those characters which are repeated 3 times only then we just need to pass in the if block as: If(entry.getValue==3) Sop(); Is it fine sir?
@suprabathj7843
@suprabathj7843 3 жыл бұрын
Nice explanation
@Jyotigupta-vs4mz
@Jyotigupta-vs4mz 2 жыл бұрын
Big thanks
@ShinAkuma
@ShinAkuma 3 жыл бұрын
Here's and alternate way to do it if you're not allowed to use HashMap. String s = "ABCDEADEF"; int chr[] = new int[26]; for(int i=0; i
@pandudamera7211
@pandudamera7211 3 жыл бұрын
Please make video alternative numbers and repeat numberss brother
@pandudamera7211
@pandudamera7211 3 жыл бұрын
Thanks you brother
@jptechnoservice9013
@jptechnoservice9013 3 жыл бұрын
Superb bro
@krishanuchakraborty3500
@krishanuchakraborty3500 3 жыл бұрын
Hi Naveen, can't we use HashSet here as well to solve it, instead of HashMap? Any particular reason you advised to use HashMap? Thanks!
@Erlisch1337
@Erlisch1337 3 жыл бұрын
How would you keep track of the count with a Set? But then again the question is to print duplicate characters, not count them. So I guess a Set should work here too.
@saikrishna-wi2kg
@saikrishna-wi2kg Жыл бұрын
hi,how to ignore spaces while finding duplicate count
@arunprasanth8881
@arunprasanth8881 3 жыл бұрын
But in zoho they ask differently...like for example...INPUT: aabbaccddbe OUTPUT: abacdbe How to bring like this?
@ghyanmitrajiblapnor444
@ghyanmitrajiblapnor444 3 жыл бұрын
Why you used set you can directly print the map using for each loop.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
How will you print using simple loop? Map doesn't maintain the order. And you need getvalue()>1.
@sonyjoseph1498
@sonyjoseph1498 Ай бұрын
​@@naveenautomationlabs for(Map. Entryentry:charMap. EntrySet()){ System.out. println(entry. getKey()+":"+entry.getValue());} can we use this method to print the resul without using set????
@atifpall2007
@atifpall2007 3 жыл бұрын
We did not check for capital N versus small n using the string Naveen
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
You can check, this will surely work.
@Amitpatil-g8g
@Amitpatil-g8g Жыл бұрын
i think this program is very big naveen sir. is it available another way short.
@explorer0709
@explorer0709 3 жыл бұрын
I want to display as duplicate and non duplicate values what to do in that case
@priyankshah4027
@priyankshah4027 3 жыл бұрын
U can use streams and partitioning
@ILuvBilli
@ILuvBilli 2 жыл бұрын
Hi, this is old approach, now a days interviewer wants the solution through stream only
@abhishekanand3036
@abhishekanand3036 3 жыл бұрын
Hi Naveen, I want same result. String st[] = {"Naveen","Java","Tom","A","",null}; Help me here.... Also share without using collection
@rdnkmr
@rdnkmr 3 жыл бұрын
iterate that array to call the method to count duplicates inside the loop. Each word gets processed separately for each iteration!
@abhishekanand3036
@abhishekanand3036 3 жыл бұрын
@@rdnkmr will this work for string array ?
@rdnkmr
@rdnkmr 3 жыл бұрын
@@abhishekanand3036 when it is already a array you can directly loop the array and pass each string to that method
@basirobaidi667
@basirobaidi667 3 жыл бұрын
First here 😊
@nishikantwairkar6866
@nishikantwairkar6866 3 жыл бұрын
❤️
@bootcamprag
@bootcamprag 3 жыл бұрын
How about you solve this using Python. I think you will use less code and complexity.
@nagamanickam5702
@nagamanickam5702 3 жыл бұрын
This is too complicated and verbose.. Simply use streams
String Interview Question: Count the occurrences of a character in a String
13:28
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 116 МЛН
Find Duplicate Elements in An Array || Important Java Interview Questions
22:36
Naveen AutomationLabs
Рет қаралды 52 М.
Find Duplicate Characters In A String
8:10
CppNuts
Рет қаралды 12 М.
How To Become A DevOps Engineer in 2023? | Skills To Learn
20:34
Travis Media
Рет қаралды 590 М.
Java Program #14 - Find duplicate characters in a String in Java
10:07
Programming For Beginners
Рет қаралды 6 М.