Important Interview Question: How to Print count of duplicate characters from String? ||
ฝัง
- เผยแพร่เมื่อ 4 เม.ย. 2021
- In this video, I have explained one Important Interview Question: How to Print duplicate characters from String?
~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
th-cam.com/users/Naveen%20Au...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
t.me/joinchat/Q8HTanc9Xi4os0tS
Naveen AutomationLabs Paid Courses:
Java & Selenium:
naveenautomationlabs.com/manua...
Java & API +POSTMAN + RestAssured + HttpClient:
naveenautomationlabs.com/selen... - วิทยาศาสตร์และเทคโนโลยี
Truly an "Approach" for Problem solving , and i just learned it!
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
what an explanation. God bless you Naveen...
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.
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);
I have paused the video to thankyou, loved the way you have explained.
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.
Thank you so much for your easy explaination.
Good method of solve this particular problem. But, I feel how fast this will go as an obsolete process
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
can you put that solution here @ashutoshMishra
Great technique
Superb bro
Nice explanation
Thanks Naveen
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?
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.
for how many year exp you were asked this question??
Hi Naveen, in this case how we can print the 1st repeatative character?
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.
Hi Naveen, please try to start a series of c# with selenium
I really like your voice 😊
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”.
The question is "Print duplicate characters from String" but the solution also contains the count of duplicate characters in a given string 👍
In that case you can only print keys not values
Thanks you brother
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
Big thanks
Please make video alternative numbers and repeat numberss brother
Sir how to print "I love java" into "java love I" plzzz make a video on this frequently getting this problem
hi,how to ignore spaces while finding duplicate count
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);
}
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 😐
edge cases will always give you bonus points.
Second here 👍😄✊
Nice video.should we not use if else conditon? I see that you have used multiple if's.
It doesn't matter here. We are returning void return from each if condition.
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.
For first program mate
public static void main(String[] args) {
int count=0,count1=0;
for(int i=100;i
❤️
But in zoho they ask differently...like for example...INPUT: aabbaccddbe
OUTPUT: abacdbe
How to bring like this?
Thank you.
Time complexity?
Space complexity?
It would be helpful if you could give a hint on the above for different interview questions.
Time complexity I suppose n + k where k is the number of unique characters.
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.
Two for loops will give you O(n^2). But ya would like to see your solution how would you get the max count?
@@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
I want to display as duplicate and non duplicate values what to do in that case
U can use streams and partitioning
Naveen , question is like how come hashmap storing duplicate key ? like a,1 ,a,2,a,3
Watch this video th-cam.com/video/SXfsBDTodpY/w-d-xo.html
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!
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.
We did not check for capital N versus small n using the string Naveen
You can check, this will surely work.
Why you used set you can directly print the map using for each loop.
How will you print using simple loop? Map doesn't maintain the order. And you need getvalue()>1.
How about you solve this using Python. I think you will use less code and complexity.
Hi, this is old approach, now a days interviewer wants the solution through stream only
First here 😊
Hi Naveen, I want same result.
String st[] = {"Naveen","Java","Tom","A","",null};
Help me here.... Also share without using collection
iterate that array to call the method to count duplicates inside the loop. Each word gets processed separately for each iteration!
@@rdnkmr will this work for string array ?
@@abhishekanand3036 when it is already a array you can directly loop the array and pass each string to that method
This is too complicated and verbose.. Simply use streams
i think this program is very big naveen sir. is it available another way short.