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; } }
@suhaskhot93103 жыл бұрын
Oh wow you just changed some lines and got correct code.
@nekkantisandeepkumar88973 жыл бұрын
Thank you so much
@channelcuriousity6467 Жыл бұрын
Really i am stucked in solving geeks for geeks. After I solve your 100 basics problem. I have feelings to crack any questions.
@shankardayal69283 жыл бұрын
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.
@premkumareaswaran68754 жыл бұрын
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.
@sauravsemwal74274 жыл бұрын
Yes there should be some correction in the code. If we find any repeated character we will delete character upto that character .
@uttamdey45754 жыл бұрын
Hi, one more loop has to be added, the snippet is below for(int j=0;j
@tharunmanitejakotha56864 жыл бұрын
@@uttamdey4575 This words perfectly. The code in the video breaks at a point. Thanks to you Uttam
@aishwaryajaini99853 жыл бұрын
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;
@kimyastudios7 ай бұрын
@@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); }
@Robcuisimplu4 жыл бұрын
Thank you so much for this videos! You help me get ready for my interview!
@gkandcurrentaffairs71512 жыл бұрын
But we r not getting output
@lawanutech99774 жыл бұрын
Thank you..Keep it up..More power to you👍
@gsivalingam39804 жыл бұрын
Plz display output
@Bharathkumar-j3a2 жыл бұрын
sir, for taking user input what i need to do?
@03_sah2 жыл бұрын
Sir to find longest substring - all substrings r of same length ,none of them is large- abcd ,bcda ,cdab
@shenth274 жыл бұрын
I haven't tested your code but I think it won't find the correct longest substring in every inputs. e.g. abcdaeb -> bcdae
@abhisheksrivastava93074 жыл бұрын
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
@shivampathania26073 жыл бұрын
This video program not giving any output idk y ? Can anyone help me in this
@prakashranjan65283 жыл бұрын
@@abhisheksrivastava9307 this won't be work still for we cases like. i/p "asjrgapa" o/p should be 6 length as str : sjrgap
@vijaymaurya36953 жыл бұрын
@@abhisheksrivastava9307 even this won't work check for "abcabcbb"
@ShankyGaming03063 жыл бұрын
@@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 Жыл бұрын
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; } }
@prakashranjan65283 жыл бұрын
This will won't give correct o/p in case of str = "dvdf"; -> longest would be 'vdf'
@rahulmundada52682 ай бұрын
Exactly 👍🏻
@harshitsaluja38093 жыл бұрын
This code does not seems to work for "dvdf" the output comes as dv it should come as vdf
@suprabathj78434 жыл бұрын
Good one👍
@start1learn-n1715 ай бұрын
Tq
@freeebeee72613 жыл бұрын
Sir couldn't reach the telegram group ......I assume the link might be expired
@anjan5545 Жыл бұрын
For input -> "dvdf" it returns the longest substring as "dv" but it should have been "vdf"
@Pawan76457 Жыл бұрын
Yes that's the true answer bcoz that's the longest without repetition
It won't work for all String. For example, it won't work for ABADEXED
@channelcuriousity6467 Жыл бұрын
Mistake need to add longestoverall+=c
@Таалай-ж9ч3 жыл бұрын
Thank you 😊. But why didn't you execute the program?
@jeevansk31302 жыл бұрын
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
@uttamdey45754 жыл бұрын
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.
@springhibernatetutes4 жыл бұрын
Yes we will check this.Thanks for your valuable comment
@PainofRiOt3 жыл бұрын
@@omprakashak7176 a is repeated... common knowledge
@srivathsansworld42193 жыл бұрын
this is not working
@srinivasand89003 жыл бұрын
Longest substring with repeatation..... How to change the existing code sir
@chsainath66944 жыл бұрын
Hi Sandeep, Print the following structure; input =4 1 1 2 1 2 3 1 2 3 4 can you explain this program?
@arijitmohapatra87373 жыл бұрын
For (int i=1;i
@Luckyupadhyay-c7h11 ай бұрын
for(int i = 1; i
@deepikagupta78643 жыл бұрын
This will not work for most of the cases like abadef string..logic is not correct
@garikapatigopi003 жыл бұрын
not applicable for some strings like "dvdf","pwwkew".
@maheshnaga18623 жыл бұрын
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
@shankardayal69283 жыл бұрын
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.
@suhaskhot93103 жыл бұрын
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.
@vinayshah5733 жыл бұрын
Did you get correct code then?
@suhaskhot93103 жыл бұрын
@@vinayshah573 ya there are many comments with correct answers on this video
@amans65044 жыл бұрын
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.
@springhibernatetutes4 жыл бұрын
Harder than this
@amans65044 жыл бұрын
@@springhibernatetutes ok sir I'll try my best
@MeeraTech_Talks2 жыл бұрын
Sir without use any method in string se bnao
@saikrishnasaikrishna99143 жыл бұрын
Sir you have to kept link of source code
@avijitsamanta87843 жыл бұрын
Its not work properly
@rohanchristopher22654 жыл бұрын
Microsoft Interview Program : Input KKCCDFC out put should be KK2CC2D1F1C1 , request you create video for this program
@springhibernatetutes4 жыл бұрын
Already this program is in playlist
@chanchalsinghal59733 жыл бұрын
Do what u say.
@sumit18953 жыл бұрын
its not accurate
@vaibhavkove14409 ай бұрын
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; } }
@saibabukarri67064 жыл бұрын
👍🙏❤️👌
@letsstartagain24304 жыл бұрын
I'm not getting you properly 🙄
@springhibernatetutes4 жыл бұрын
Watch the video you will understand
@ananyasamanta985714 күн бұрын
import java.util.*; public class A{ static void function(String str){ String longestTillnow=""; String longestoverall=""; ArrayList l1=new ArrayList(); for(int i=0;i