Java Program to find longest substring without repetition| Amazon coding interview questions

  Рет қаралды 66,857

Learn With KrishnaSandeep

Learn With KrishnaSandeep

Күн бұрын

Пікірлер: 74
@narendramodi107
@narendramodi107 3 жыл бұрын
try this one guys without any additional loops.. HashSet cha=new HashSet(); String Longest=""; String current=""; int j=0; for(int i=0;iLongest.length()) { Longest=current; } }
@suhaskhot9310
@suhaskhot9310 3 жыл бұрын
Oh wow you just changed some lines and got correct code.
@nekkantisandeepkumar8897
@nekkantisandeepkumar8897 3 жыл бұрын
Thank you so much
@channelcuriousity6467
@channelcuriousity6467 Жыл бұрын
Really i am stucked in solving geeks for geeks. After I solve your 100 basics problem. I have feelings to crack any questions.
@shankardayal6928
@shankardayal6928 3 жыл бұрын
Thanks for sharing your idea. But in interview I had seen that we had one rule "Don't use any inbuilt methods". Here we use predefined data structure set and its method.
@premkumareaswaran6875
@premkumareaswaran6875 4 жыл бұрын
As per the problem statement, for the string "abcdablsdh", isn't it expected to return "cdabls" as the result? However, it returns "ablsdh" because during the first iteration of the for-loop, once we reach the second "a" (index 4), we break there and continue with the result of the string. Is this what we are trying to achieve here? Your explanation would be helpful.
@sauravsemwal7427
@sauravsemwal7427 4 жыл бұрын
Yes there should be some correction in the code. If we find any repeated character we will delete character upto that character .
@uttamdey4575
@uttamdey4575 4 жыл бұрын
Hi, one more loop has to be added, the snippet is below for(int j=0;j
@tharunmanitejakotha5686
@tharunmanitejakotha5686 4 жыл бұрын
@@uttamdey4575 This words perfectly. The code in the video breaks at a point. Thanks to you Uttam
@aishwaryajaini9985
@aishwaryajaini9985 3 жыл бұрын
You can try it like this in a more simpler way String str = "abcdablsdh"; HashSet set = new HashSet(); String longestOverall = ""; String longestTillnow = ""; for (int i = 0; i < str.length(); i++) { for (int j = i; j < str.length(); j++) { char c = str.charAt(j); if (set.contains(c)) { break; } set.add(c); longestTillnow += c; } if (longestOverall.length() < longestTillnow.length()) { longestOverall = longestTillnow; } longestTillnow = ""; set.clear(); } return longestOverall;
@kimyastudios
@kimyastudios 7 ай бұрын
@@tharunmanitejakotha5686 it can be done with single for loop also. String s="abacdefb"; HashMap hm=new LinkedHashMap(); int maxLength=0; String maxString=""; for(int i=0; imaxLength) { maxLength=hm.keySet().size(); maxString=hm.keySet().toString(); } } System.out.println(maxString); }
@Robcuisimplu
@Robcuisimplu 4 жыл бұрын
Thank you so much for this videos! You help me get ready for my interview!
@gkandcurrentaffairs7151
@gkandcurrentaffairs7151 2 жыл бұрын
But we r not getting output
@lawanutech9977
@lawanutech9977 4 жыл бұрын
Thank you..Keep it up..More power to you👍
@gsivalingam3980
@gsivalingam3980 4 жыл бұрын
Plz display output
@Bharathkumar-j3a
@Bharathkumar-j3a 2 жыл бұрын
sir, for taking user input what i need to do?
@03_sah
@03_sah 2 жыл бұрын
Sir to find longest substring - all substrings r of same length ,none of them is large- abcd ,bcda ,cdab
@shenth27
@shenth27 4 жыл бұрын
I haven't tested your code but I think it won't find the correct longest substring in every inputs. e.g. abcdaeb -> bcdae
@abhisheksrivastava9307
@abhisheksrivastava9307 4 жыл бұрын
now worry bro just add one more for loop import java.util.*; class FirstLongestSubstring{ public static void main(String ar[]){ String str="abcdaeb"; String res=Longest(str); System.out.println("Longest Sub-String is :"+res); } private static String Longest(String str) { HashSet set=new HashSet(); String longestOverall=""; String longestTillnow=""; for(int i=0;i
@shivampathania2607
@shivampathania2607 3 жыл бұрын
This video program not giving any output idk y ? Can anyone help me in this
@prakashranjan6528
@prakashranjan6528 3 жыл бұрын
@@abhisheksrivastava9307 this won't be work still for we cases like. i/p "asjrgapa" o/p should be 6 length as str : sjrgap
@vijaymaurya3695
@vijaymaurya3695 3 жыл бұрын
@@abhisheksrivastava9307 even this won't work check for "abcabcbb"
@ShankyGaming0306
@ShankyGaming0306 3 жыл бұрын
@@vijaymaurya3695 public class LongestString { public static void main(String[] args) { String str = "abcdaeb"; String finalans = longest(str); System.out.println(finalans); } private static String longest(String str) { HashSet set = new HashSet(); int maxLength = 0; String longestTillnow = ""; String longestoverall = ""; //take each character form the given string for(int i =0; i longestoverall.length()) { longestoverall=longestTillnow; } } //System.out.println("Max Length of longest Substring is " + set.size()); return longestoverall; } } correct ans
@samrathrdt
@samrathrdt Жыл бұрын
Logic was correct , just did a small improvision. package com.samrat; import java.util.HashSet; // to find substring without repetition public class LongestSubString { public static void main(String[] args) { //String str="abcdabefghi"; String str="dvdf "; String longestSubString = longestSubString(str); System.out.println("String:"+longestSubString); } private static String longestSubString(String str) { HashSet set = new HashSet(); String finalSubString=""; String tempSubString=""; int j=0; for(int i=0;ifinalSubString.length()) { finalSubString=tempSubString; } } return finalSubString; } }
@prakashranjan6528
@prakashranjan6528 3 жыл бұрын
This will won't give correct o/p in case of str = "dvdf"; -> longest would be 'vdf'
@rahulmundada5268
@rahulmundada5268 2 ай бұрын
Exactly 👍🏻
@harshitsaluja3809
@harshitsaluja3809 3 жыл бұрын
This code does not seems to work for "dvdf" the output comes as dv it should come as vdf
@suprabathj7843
@suprabathj7843 4 жыл бұрын
Good one👍
@start1learn-n171
@start1learn-n171 5 ай бұрын
Tq
@freeebeee7261
@freeebeee7261 3 жыл бұрын
Sir couldn't reach the telegram group ......I assume the link might be expired
@anjan5545
@anjan5545 Жыл бұрын
For input -> "dvdf" it returns the longest substring as "dv" but it should have been "vdf"
@Pawan76457
@Pawan76457 Жыл бұрын
Yes that's the true answer bcoz that's the longest without repetition
@ayushsahu3983
@ayushsahu3983 11 ай бұрын
@anjan5545 String str = "dvdf"; String longestSubString = ""; int longestLength = 0; Map map = new LinkedHashMap(); for(int i=0; i longestLength) { longestLength = map.size(); longestSubString = map.keySet().toString(); } } System.out.println(longestSubString); System.out.println(longestLength);
@dakshinrajavel1064
@dakshinrajavel1064 3 жыл бұрын
It won't work for all String. For example, it won't work for ABADEXED
@channelcuriousity6467
@channelcuriousity6467 Жыл бұрын
Mistake need to add longestoverall+=c
@Таалай-ж9ч
@Таалай-ж9ч 3 жыл бұрын
Thank you 😊. But why didn't you execute the program?
@jeevansk3130
@jeevansk3130 2 жыл бұрын
Because it's wrong , it return only first largest substring it will never start to search from i+1 th character , we should do that
@uttamdey4575
@uttamdey4575 4 жыл бұрын
Hi you are doing a great work really thank you for all these effors from your side. Wanted to ask I was trying with different combination of Strings for eg:- "abacdab" -> the output for this should be cdab but if gives acd. The idea of removing the set and emptying the string inside the loop needs to be modified a bit.
@springhibernatetutes
@springhibernatetutes 4 жыл бұрын
Yes we will check this.Thanks for your valuable comment
@PainofRiOt
@PainofRiOt 3 жыл бұрын
@@omprakashak7176 a is repeated... common knowledge
@srivathsansworld4219
@srivathsansworld4219 3 жыл бұрын
this is not working
@srinivasand8900
@srinivasand8900 3 жыл бұрын
Longest substring with repeatation..... How to change the existing code sir
@chsainath6694
@chsainath6694 4 жыл бұрын
Hi Sandeep, Print the following structure; input =4 1 1 2 1 2 3 1 2 3 4 can you explain this program?
@arijitmohapatra8737
@arijitmohapatra8737 3 жыл бұрын
For (int i=1;i
@Luckyupadhyay-c7h
@Luckyupadhyay-c7h 11 ай бұрын
for(int i = 1; i
@deepikagupta7864
@deepikagupta7864 3 жыл бұрын
This will not work for most of the cases like abadef string..logic is not correct
@garikapatigopi00
@garikapatigopi00 3 жыл бұрын
not applicable for some strings like "dvdf","pwwkew".
@maheshnaga1862
@maheshnaga1862 3 жыл бұрын
Sir u r explaintion is very super I know theory of all java concept but coading section I can fail pls how start coding improvement
@shankardayal6928
@shankardayal6928 3 жыл бұрын
Same here also before 6 months. I tried to understand logic and implement that without inbuilt methods. Mostly avoid collection as they have many inbuilt methods. This had improved my concept.
@suhaskhot9310
@suhaskhot9310 3 жыл бұрын
There is a loophole in this program. Let me take input as ABCAD so for this input I should get longest substring as BCAD but by this program you won't. You will get CAD as output which is not correct.
@vinayshah573
@vinayshah573 3 жыл бұрын
Did you get correct code then?
@suhaskhot9310
@suhaskhot9310 3 жыл бұрын
@@vinayshah573 ya there are many comments with correct answers on this video
@amans6504
@amans6504 4 жыл бұрын
Ok i understood this completely.. So can you please tell me whether the actual competitive programming is just like this or way harder than this? Asking Just for some motivation.
@springhibernatetutes
@springhibernatetutes 4 жыл бұрын
Harder than this
@amans6504
@amans6504 4 жыл бұрын
@@springhibernatetutes ok sir I'll try my best
@MeeraTech_Talks
@MeeraTech_Talks 2 жыл бұрын
Sir without use any method in string se bnao
@saikrishnasaikrishna9914
@saikrishnasaikrishna9914 3 жыл бұрын
Sir you have to kept link of source code
@avijitsamanta8784
@avijitsamanta8784 3 жыл бұрын
Its not work properly
@rohanchristopher2265
@rohanchristopher2265 4 жыл бұрын
Microsoft Interview Program : Input KKCCDFC out put should be KK2CC2D1F1C1 , request you create video for this program
@springhibernatetutes
@springhibernatetutes 4 жыл бұрын
Already this program is in playlist
@chanchalsinghal5973
@chanchalsinghal5973 3 жыл бұрын
Do what u say.
@sumit1895
@sumit1895 3 жыл бұрын
its not accurate
@vaibhavkove1440
@vaibhavkove1440 9 ай бұрын
Please check this and please tell me the my mistake as soon as possible package interview13; import java.util.HashSet; //Ques: Java Program to find longest SubString without Repetition public class LongestString { public static void main(String[] args) { String str = "abcdab"; longest(str); } private static String longest(String str) { HashSet set = new HashSet(); String longestOverall = ""; String longestTillNow = ""; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (set.contains(c)) { longestTillNow = ""; set.clear(); } set.add(c); longestTillNow += c; if (longestTillNow.length() > longestOverall.length()) { longestOverall = longestTillNow; } } return longestOverall; } }
@saibabukarri6706
@saibabukarri6706 4 жыл бұрын
👍🙏❤️👌
@letsstartagain2430
@letsstartagain2430 4 жыл бұрын
I'm not getting you properly 🙄
@springhibernatetutes
@springhibernatetutes 4 жыл бұрын
Watch the video you will understand
@ananyasamanta9857
@ananyasamanta9857 14 күн бұрын
import java.util.*; public class A{ static void function(String str){ String longestTillnow=""; String longestoverall=""; ArrayList l1=new ArrayList(); for(int i=0;i
Java Program to check given String is Panagram or not?
8:24
Learn With KrishnaSandeep
Рет қаралды 59 М.
Longest Substring Without Repeating Characters | Amazon
24:00
take U forward
Рет қаралды 292 М.
My MEAN sister annoys me! 😡 Use this gadget #hack
00:24
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 33 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 153 МЛН
Java Program for String compression | Amazon Coding Interview Questions
14:28
Learn With KrishnaSandeep
Рет қаралды 25 М.
Find longest substring with K unique characters - Sliding Window Algorithm
19:51
Code With Ease - By Varsha
Рет қаралды 8 М.
Leetcode 3. Longest Substring Without Repeating Characters
15:49
Code with Alisha
Рет қаралды 72 М.
My MEAN sister annoys me! 😡 Use this gadget #hack
00:24