Program to Find Duplicate character in a String Coding Interview Question and Answer | Code Decode

  Рет қаралды 53,257

Code Decode

Code Decode

Күн бұрын

Пікірлер: 65
@vinothkumarpalanivel4355
@vinothkumarpalanivel4355 2 жыл бұрын
Very usefull...I had interview today and the interviewer ask the same question 😂😂😂
@CodeDecode
@CodeDecode 2 жыл бұрын
Hehe yess, interviewers have some set of common questions to ask from 🙂🙂
@rishiraj2548
@rishiraj2548 2 жыл бұрын
Wow
@rushikeshgodase8498
@rushikeshgodase8498 Жыл бұрын
At that interview time you were fresher or experienced???
@vinothkumarpalanivel4355
@vinothkumarpalanivel4355 Жыл бұрын
@@rushikeshgodase8498 i'm having 3+ year experience when I attended the interview
@umangshah9305
@umangshah9305 2 жыл бұрын
Can use single for loop that goes till length-1 with indexof() and lastindexof(). Check if both are different, then add to the set. This will work since we do not need count of occurrences. Set duplicates = new LinkedHashSet(); String input = "code decode"; for (int i = 0; i < input.length() - 1; i++) { if (input.indexOf(input.charAt(i)) != input.lastIndexOf(input.charAt(i))) { duplicates.add(input.charAt(i)); } }
@karthigeyanm3376
@karthigeyanm3376 2 жыл бұрын
I am really a big fan of CodeDecode and I want to say this video explanation is "THE BEST" we can find in the internet for FREE. You guys are really awesome and especially ma'am, the way you explain the logics are stupendous. This channel has helped me to grap multiple offers from various MNC's for more than 10 LPA package and I wanted to thank the entire team for your efforts on all your videos and playlist. Thanks again...!!!
@CodeDecode
@CodeDecode 2 жыл бұрын
sure karthikeyan we have noted the request and we will try to create it in near future
@pratiyushanand6454
@pratiyushanand6454 2 жыл бұрын
Can also be solved using set - add chars to the set, if add() in set returns false, it means it is a duplicate value. Just store it.
@jaivikkotadiya730
@jaivikkotadiya730 8 ай бұрын
Just add all char in set and then compare size of set with length of string. This will be more compact solution
@sourabhchougule5642
@sourabhchougule5642 7 ай бұрын
I really appreciate your videos and lectures these helped me to prepare well. For the deplicate elements in string i have other solution; i.e public static Set duplicatesByUsingLastIndexOfMethod(String str) { Set duplicateCharacters = new LinkedHashSet(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (str.lastIndexOf(c) > i) { duplicateCharacters.add(c); } } return duplicateCharacters; } is it correct @CodeDecode ?
@nishankjain8739
@nishankjain8739 2 жыл бұрын
I really like how you explain the concepts. Can you please make a video series (2-3 vids) for spring data jpa. A lot of interviewers have focused on this and sadly it was hard to fool them without complete knowledge on it. Thanks
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Nishank we will cover them too 👍🙂
@_satveer
@_satveer Жыл бұрын
*At **2:35** use getOrDefault method of map & keep on incrementing them with+1 by initial setting value 0 instead of if…else* Btw nice video👌
@CodeDecode
@CodeDecode Жыл бұрын
👍👍
@mysteriouscartoontales
@mysteriouscartoontales 2 жыл бұрын
Good Explanation. Please try to make videos on springs containers, JPA, Hibernate and other topics in spring. in most of the interview they asked about springs question with java.
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Akash. We do have many on our channel already 👍🙂
@ashwinmarathe9844
@ashwinmarathe9844 Жыл бұрын
Very well explained
@CodeDecode
@CodeDecode Жыл бұрын
Thanks
@gyvsr
@gyvsr 2 жыл бұрын
Why we need to iterate again in 3rd approach? We can add duplicate elements into duplicates set directly after line no 26 right?
@kalekar100
@kalekar100 2 жыл бұрын
Thanks. That is simple and in detail.
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Sourabh 🙂👍
@ponnamramesh4569
@ponnamramesh4569 2 жыл бұрын
I think we don't require second for loop in last 2 case's... In first for only we can add duplicate elements.
@kancharlasrimannarayana7068
@kancharlasrimannarayana7068 2 жыл бұрын
int [ ] arrayforchar = new int [256] ; why we use 256bytes size here?
@CodeDecode
@CodeDecode 2 жыл бұрын
www.ascii-code.com/ Look at this table. In java asciiis 256 bytes n not of 128 as in c etc. We map each string character to ascii value n store in integer array. Since it's easy to convert from character to ascii integer n vice versa, we use this technique to solve our problem.
@sureshmanne7245
@sureshmanne7245 2 жыл бұрын
Excellent explanation, thank you
@CodeDecode
@CodeDecode 2 жыл бұрын
you're welcome suresh
@sonaligayake9240
@sonaligayake9240 Жыл бұрын
Really good explanation 😃
@CodeDecode
@CodeDecode Жыл бұрын
Thanks
@arutsudar
@arutsudar 2 жыл бұрын
Isn’t the time complexity of map operations (put and get) is O(1) ? And, the 3rd approach’s overall time complexity is O(n) ??
@CodeDecode
@CodeDecode 2 жыл бұрын
Now map internally implements tree for handling collisions. So what is the time complexity of tree? It's o(logn). Hence o(nlogn)
@chiranjibidangal6184
@chiranjibidangal6184 Ай бұрын
It’s great video
@CodeDecode
@CodeDecode Ай бұрын
Thanks
@sravandatha9511
@sravandatha9511 Жыл бұрын
Solution using Java 8 Streams: Set characterDuplicates = Arrays.asList(string.split("")).stream() .collect(Collectors.groupingBy(Function.identity(),Collectors.counting())) .entrySet().stream().filter( e -> e.getValue()>1).map(e -> e.getKey()).collect(Collectors.toSet());
@krishnareddy-ro2rp
@krishnareddy-ro2rp 2 жыл бұрын
Please do videos on Java Data Structers
@CodeDecode
@CodeDecode 2 жыл бұрын
sure krishna we will create it soon
@rajashekar-bu8xd
@rajashekar-bu8xd 2 жыл бұрын
Please make a series on multithreading
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Raja 👍🙂
@akshaykohale3121
@akshaykohale3121 2 жыл бұрын
Pls make one video on.. how to call stored procedure in hibernate or spring boot
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure 👍👍
@varunsiddarth1265
@varunsiddarth1265 2 жыл бұрын
It's really very helpful
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks varun
@varunsiddarth1265
@varunsiddarth1265 2 жыл бұрын
@@CodeDecode keep rocking "code decode" team..🤗🤗
@rishiraj2548
@rishiraj2548 2 жыл бұрын
Great thanks
@CodeDecode
@CodeDecode 2 жыл бұрын
You are welcome
@rishiraj2548
@rishiraj2548 Ай бұрын
@@CodeDecode , sessions with you are worth revising. Thanks again.
@Ravikumar-gj6qw
@Ravikumar-gj6qw 2 жыл бұрын
Hi how your coding like this , can u just refer me the links to pratice such a analyst and speed in coding plz
@swapnilmishra697
@swapnilmishra697 2 жыл бұрын
Really nice video...
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Swapnil🙂👍
@tanveersyed1049
@tanveersyed1049 2 жыл бұрын
Mostly asked questions in interviews
@CodeDecode
@CodeDecode 2 жыл бұрын
Yes it is frequently asked. 🙂
@elangovan.s7820
@elangovan.s7820 2 жыл бұрын
String s ="codedecode"; //count of duplicate characters List list1=Arrays.asList(s.split("")); Map m =list1.stream().collect(Collectors.groupingBy(Function.identity(),Collectors.counting())); System.out.println(m.entrySet()); //print only duplicate List list = Arrays.asList(s.split("")); Set set = new HashSet(); list.stream().filter(x->!set.add(x)).collect(Collectors.toSet()).forEach(System.out::println);
@akhilchowdary814
@akhilchowdary814 2 жыл бұрын
Instead of that you can add directly into hash set because they don't allow duplicate elements
@AbhishekPandey-mi1wi
@AbhishekPandey-mi1wi 2 жыл бұрын
How will you get the counts then? Also linkedhashset is a implemented class of set interface
@felix2916
@felix2916 2 жыл бұрын
In the 3rd approach maybe if you use a LinkedHashMap instead of a HashMap then you can add the chars in the order they appeared in the string. In the other hand, I didn't get why O(log(n)). Great video thanks a lot!
@rocker31590
@rocker31590 2 жыл бұрын
Please create videos for Spring Transaction and Hibernate Transaction.
@CodeDecode
@CodeDecode 2 жыл бұрын
sure we will create video on it soon
@rocker31590
@rocker31590 2 жыл бұрын
@@CodeDecode thanks 😊
@ILuvBilli
@ILuvBilli 2 жыл бұрын
But now a days interviewer asked us to solve this through stream
@CodeDecode
@CodeDecode 2 жыл бұрын
kzbin.info/aero/PLyHJZXNdCXsfcMboYwGoL6wKAFPxljz5W
@ganeshdaund4493
@ganeshdaund4493 2 ай бұрын
Still didn't get why you have taken array size of 256 though we have only 26 characters in second approach
@samahmahdi5511
@samahmahdi5511 7 ай бұрын
private static Set getDuplicateCharacters1(String s) { Set set = new LinkedHashSet(); // or HashSet if u dont mind of insertion order Map map = new HashMap(); for(char ch : s.toCharArray()){ if(map.containsKey(ch)) map.put(ch, map.get(ch)+1) ; else map.put(ch, 1) ; } for(Map.Entry entry : map.entrySet() ) if(entry.getValue()>1) set.add(entry.getKey()); return set; }
@sangeethaponnusamy579
@sangeethaponnusamy579 Жыл бұрын
Great explanation😊
@CodeDecode
@CodeDecode Жыл бұрын
Thanks Sangeetha 🙂
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 99 МЛН
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 2,4 МЛН
Java String Tricky Interview Coding Questions
22:48
Java Guides
Рет қаралды 7 М.