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...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 68

  • @sridharlanka2721
    @sridharlanka2721 3 ปีที่แล้ว +4

    Truly an "Approach" for Problem solving , and i just learned it!

  • @bhuvanabaskaran8063
    @bhuvanabaskaran8063 3 ปีที่แล้ว +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

  • @WMohanty
    @WMohanty 3 ปีที่แล้ว

    what an explanation. God bless you Naveen...

  • @VinayakTungal
    @VinayakTungal 3 ปีที่แล้ว +1

    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.

  • @vishnuchandar7073
    @vishnuchandar7073 3 ปีที่แล้ว +2

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

  • @abhishekshandilya4052
    @abhishekshandilya4052 3 ปีที่แล้ว

    I have paused the video to thankyou, loved the way you have explained.

  • @Tidda420
    @Tidda420 3 ปีที่แล้ว +4

    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.

  • @MrAsgar123
    @MrAsgar123 2 ปีที่แล้ว

    Thank you so much for your easy explaination.

  • @maywellbeaghost6364
    @maywellbeaghost6364 3 ปีที่แล้ว

    Good method of solve this particular problem. But, I feel how fast this will go as an obsolete process

  • @AshutoshMishra-qc7nl
    @AshutoshMishra-qc7nl 3 ปีที่แล้ว +8

    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 4 หลายเดือนก่อน

      can you put that solution here @ashutoshMishra

  • @amanuellebassi7294
    @amanuellebassi7294 3 ปีที่แล้ว +1

    Great technique

  • @jptechnoservice9013
    @jptechnoservice9013 3 ปีที่แล้ว

    Superb bro

  • @suprabathj7843
    @suprabathj7843 3 ปีที่แล้ว

    Nice explanation

  • @prasanthraviv
    @prasanthraviv 3 ปีที่แล้ว +1

    Thanks Naveen

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

  • @paladarsh39
    @paladarsh39 3 ปีที่แล้ว +1

    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 14 วันที่ผ่านมา

      for how many year exp you were asked this question??

  • @tapaskhandai
    @tapaskhandai ปีที่แล้ว

    Hi Naveen, in this case how we can print the 1st repeatative character?

  • @ayushgupta8239
    @ayushgupta8239 3 ปีที่แล้ว +2

    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.

  • @tapaskhandai
    @tapaskhandai 2 ปีที่แล้ว

    Hi Naveen, please try to start a series of c# with selenium

  • @anushap2139
    @anushap2139 2 ปีที่แล้ว +1

    I really like your voice 😊

  • @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”.

  • @deepakchandrashekar1023
    @deepakchandrashekar1023 3 ปีที่แล้ว +7

    The question is "Print duplicate characters from String" but the solution also contains the count of duplicate characters in a given string 👍

    • @tapaskhandai
      @tapaskhandai ปีที่แล้ว

      In that case you can only print keys not values

  • @pandudamera7211
    @pandudamera7211 3 ปีที่แล้ว

    Thanks you brother

  • @ShinAkuma
    @ShinAkuma 3 ปีที่แล้ว +2

    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

  • @Jyotigupta-vs4mz
    @Jyotigupta-vs4mz 2 ปีที่แล้ว

    Big thanks

  • @pandudamera7211
    @pandudamera7211 3 ปีที่แล้ว

    Please make video alternative numbers and repeat numberss brother

  • @sweetthirty2
    @sweetthirty2 2 ปีที่แล้ว +1

    Sir how to print "I love java" into "java love I" plzzz make a video on this frequently getting this problem

  • @saikrishna-wi2kg
    @saikrishna-wi2kg ปีที่แล้ว

    hi,how to ignore spaces while finding duplicate count

  • @vikassinghal9413
    @vikassinghal9413 2 ปีที่แล้ว +1

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

    }

  • @souvikchatterjee7400
    @souvikchatterjee7400 3 ปีที่แล้ว +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 😐

  • @jeyhunaliyev1765
    @jeyhunaliyev1765 3 ปีที่แล้ว +4

    Second here 👍😄✊

  • @sssaamm29988
    @sssaamm29988 3 ปีที่แล้ว +1

    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.

  • @maneeshbuddha8253
    @maneeshbuddha8253 8 หลายเดือนก่อน

    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 3 หลายเดือนก่อน

      For first program mate
      public static void main(String[] args) {
      int count=0,count1=0;
      for(int i=100;i

  • @nishikantwairkar6866
    @nishikantwairkar6866 3 ปีที่แล้ว

    ❤️

  • @arunprasanth8881
    @arunprasanth8881 3 ปีที่แล้ว

    But in zoho they ask differently...like for example...INPUT: aabbaccddbe
    OUTPUT: abacdbe
    How to bring like this?

  • @vengateshm2122
    @vengateshm2122 3 ปีที่แล้ว +4

    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.

  • @sonumishra6747
    @sonumishra6747 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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 ปีที่แล้ว +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

  • @explorer0709
    @explorer0709 3 ปีที่แล้ว

    I want to display as duplicate and non duplicate values what to do in that case

    • @priyankshah4027
      @priyankshah4027 3 ปีที่แล้ว +1

      U can use streams and partitioning

  • @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 th-cam.com/video/SXfsBDTodpY/w-d-xo.html

  • @krishanuchakraborty3500
    @krishanuchakraborty3500 3 ปีที่แล้ว +2

    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.

  • @atifpall2007
    @atifpall2007 3 ปีที่แล้ว

    We did not check for capital N versus small n using the string Naveen

  • @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.

  • @bootcamprag
    @bootcamprag 3 ปีที่แล้ว

    How about you solve this using Python. I think you will use less code and complexity.

  • @ILuvBilli
    @ILuvBilli 2 ปีที่แล้ว

    Hi, this is old approach, now a days interviewer wants the solution through stream only

  • @basirobaidi667
    @basirobaidi667 3 ปีที่แล้ว +1

    First here 😊

  • @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

  • @nagamanickam5702
    @nagamanickam5702 3 ปีที่แล้ว

    This is too complicated and verbose.. Simply use streams

  • @Najamashaikh937
    @Najamashaikh937 11 หลายเดือนก่อน +1

    i think this program is very big naveen sir. is it available another way short.