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

Join Telegram group : t.me/learnwithkrishnasandeep
Java Program to find longest substring without repetition| Amazon coding interview questions
(For all updates on Java interview questions and java tutorials join the telegram group)
Search in Telegram with text Java Tutorials if you are unable to join telegram with above link
1) How to read a matrix from console in java?
• How to read a matrix ...
2) How to remove duplicates from string in java?
www.youtube.com/watch?v=k20wL...
3) Write a java program to duplicate characters with number of occurences in java?
• Write a java program t...
4) Write a java program to implement bubble sort part 1?
www.youtube.com/watch?v=uvwCL...
5) Write a java program to check string is palindrome or not?
• Write a java program t...
6) Write a java program to print floyds triangle?
• Write a java program t...
7) Write a java program to print floyds triangle?
• Write a java program t...
8) How to count number of vowels in a string in java?
• How to count number of...
9) How to find largest and smallest values in an array in java?
• How to find largest an...
10) Write java program to find duplicate elements in array in java?
• Write java program to ...
11) write a java program to check the input number is prime or not in java?
• w.a.p to check the in...
12) Write a java program to print pyramid pattern of numbers?
• Write a java program t...
13) Write a java program to find missing number in array in java?
• Write a java program t...
14)Write a java program to print numbers in java up to 10 with out using loops?
• w.a.p to print numbers...
15) How to sort elements in array in asc and desc order in java?
• How to sort elements i...
16) Write a java program to find factorial of a number in java?
• Write a java program t...
17) write a java program to find second largest element in the array in the java?
• write a java program t...
18) Write a java program to check two Strings are anagrams or not by sorting and comparing strings?
• Write a java program t...
19) Write java program to print Characters count in each word in String ?
• Write java program to ...
20) Write a java program to find reverse of a string in java?
• Write a java program t...
21) Write a java program to add elements in an array in java?
• Write a java program t...
22) Write a java program to find largest of three numbers?
• Write a java program t...
23) Write a java program to print multiplication table?
• Write a java program t...
24) Write a java program to print star pattern?
• Write a java program t...
25) Write a java program to find factors of number from 1 to 100
• Write a java program t...
26) Write a java program to print fibonacci series using loops?
• Write a java program t...
27) Write a java program to print Ascii values of a Character ?
• Write a java program t...
off campus placement,
placement,
amazon,
google,
microsoft,
love babbar,
amazon hyderabad,
off campus,on campus,coding,competetive programming,leetcode,hackerrank,codeforces,topcoder,spoj,geeksforgeeks,software engineer,
Learn with Krishna Sandeep,
durga sir,
durga,
java,
java brains,

Пікірлер: 72

  • @Robcuisimplu
    @Robcuisimplu3 жыл бұрын

    Thank you so much for this videos! You help me get ready for my interview!

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

  • @lawanutech9977
    @lawanutech99774 жыл бұрын

    Thank you..Keep it up..More power to you👍

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

  • @prakashranjan6528
    @prakashranjan65283 жыл бұрын

    This will won't give correct o/p in case of str = "dvdf"; -> longest would be 'vdf'

  • @bharathkumard901
    @bharathkumard9012 жыл бұрын

    sir, for taking user input what i need to do?

  • @harshitsaluja3809
    @harshitsaluja38093 жыл бұрын

    This code does not seems to work for "dvdf" the output comes as dv it should come as vdf

  • @suprabathj7843
    @suprabathj78433 жыл бұрын

    Good one👍

  • @03_sah
    @03_sah2 жыл бұрын

    Sir to find longest substring - all substrings r of same length ,none of them is large- abcd ,bcda ,cdab

  • @gsivalingam3980
    @gsivalingam39804 жыл бұрын

    Plz display output

  • @gkandcurrentaffairs7151
    @gkandcurrentaffairs71512 жыл бұрын

    But we r not getting output

  • @freeebeee7261
    @freeebeee72613 жыл бұрын

    Sir couldn't reach the telegram group ......I assume the link might be expired

  • @narendramodi107
    @narendramodi1073 жыл бұрын

    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

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

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

    3 жыл бұрын

    Hi, one more loop has to be added, the snippet is below for(int j=0;j

  • @tharunmanitejakotha5686

    @tharunmanitejakotha5686

    3 жыл бұрын

    @@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 for (int j = i; j char c = str.charAt(j); if (set.contains(c)) { break; } set.add(c); longestTillnow += c; } if (longestOverall.length() longestOverall = longestTillnow; } longestTillnow = ""; set.clear(); } return longestOverall;

  • @kimyastudios

    @kimyastudios

    3 ай бұрын

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

  • @start1learn-n171
    @start1learn-n171Ай бұрын

    Tq

  • @shenth27
    @shenth273 жыл бұрын

    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

    3 жыл бұрын

    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

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

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

  • @srinivasand8900
    @srinivasand89003 жыл бұрын

    Longest substring with repeatation..... How to change the existing code sir

  • @dakshinrajavel1064
    @dakshinrajavel10643 жыл бұрын

    It won't work for all String. For example, it won't work for ABADEXED

  • @garikapatigopi00
    @garikapatigopi003 жыл бұрын

    not applicable for some strings like "dvdf","pwwkew".

  • @saikrishnasaikrishna9914
    @saikrishnasaikrishna99143 жыл бұрын

    Sir you have to kept link of source code

  • @user-mt3cq6zi1m
    @user-mt3cq6zi1m3 жыл бұрын

    Thank you 😊. But why didn't you execute the program?

  • @jeevansk3130

    @jeevansk3130

    Жыл бұрын

    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

  • @MeeraTech_Talks
    @MeeraTech_Talks Жыл бұрын

    Sir without use any method in string se bnao

  • @amans6504
    @amans65043 жыл бұрын

    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

    3 жыл бұрын

    Harder than this

  • @amans6504

    @amans6504

    3 жыл бұрын

    @@springhibernatetutes ok sir I'll try my best

  • @rohanchristopher2265
    @rohanchristopher22653 жыл бұрын

    Microsoft Interview Program : Input KKCCDFC out put should be KK2CC2D1F1C1 , request you create video for this program

  • @springhibernatetutes

    @springhibernatetutes

    3 жыл бұрын

    Already this program is in playlist

  • @uttamdey4575
    @uttamdey45753 жыл бұрын

    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

    3 жыл бұрын

    Yes we will check this.Thanks for your valuable comment

  • @PainofRiOt

    @PainofRiOt

    2 жыл бұрын

    @@omprakashak7176 a is repeated... common knowledge

  • @srivathsansworld4219
    @srivathsansworld42193 жыл бұрын

    this is not working

  • @chsainath6694
    @chsainath66944 жыл бұрын

    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

  • @user-wr9vx7ht2y

    @user-wr9vx7ht2y

    7 ай бұрын

    for(int i = 1; i

  • @saibabukarri6706
    @saibabukarri67063 жыл бұрын

    👍🙏❤️👌

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

    7 ай бұрын

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

  • @avijitsamanta8784
    @avijitsamanta87843 жыл бұрын

    Its not work properly

  • @deepikagupta7864
    @deepikagupta78643 жыл бұрын

    This will not work for most of the cases like abadef string..logic is not correct

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

  • @vinayshah573

    @vinayshah573

    3 жыл бұрын

    Did you get correct code then?

  • @suhaskhot9310

    @suhaskhot9310

    3 жыл бұрын

    @@vinayshah573 ya there are many comments with correct answers on this video

  • @chanchalsinghal5973
    @chanchalsinghal59733 жыл бұрын

    Do what u say.

  • @channelcuriousity6467
    @channelcuriousity6467 Жыл бұрын

    Mistake need to add longestoverall+=c

  • @letsstartagain2430
    @letsstartagain24304 жыл бұрын

    I'm not getting you properly 🙄

  • @springhibernatetutes

    @springhibernatetutes

    4 жыл бұрын

    Watch the video you will understand

  • @vaibhavkove1440
    @vaibhavkove14406 ай бұрын

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

  • @sumit1895
    @sumit18953 жыл бұрын

    its not accurate

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