Java Program To Find Longest Substring Without Repeated Character | Ashok IT

preview_player
Показать описание
#java #javascript #javaprogrammer #javaprogrammig #javadevelopment #ashokit

** For Online Training ► Call: +91-6301921083

Subscribe to our channel and hit the bell 🔔🔔🔔 icon to get video updates.

💡 Visit Our Website

💡 About Ashok IT :

Ashok IT is the No.1 quality training institute in India for the candidates who want to build their future in Information Technology. We are into online training, class room training, corporate training and one to one training with more passion and dedication. Ashok IT aims in providing best quality realtime oriented trainings on C, C++, Java, Spring , Spring REST, Spring Cloud, Microservices, Python, DJango, .Net, Angular, React JS, Salesforce, , Testing, Android, Docker, Kubernates, Manual Testing, Selenium and Digital Marketing.

-----------------------------------------------------------------------------------

💡 Our Online Training Features

🎈 Training with Real-time Working Professionals
🎈 Industry Matching use cases
🎈 Live Coding
🎈 Real-time Environment
🎈 Class Notes
🎈 Doubts Clarifications in Each Session

-----------------------------------------------------------------------------------

💡 Contact details:

☎ WhatsApp Number: +91-6301921083
Рекомендации по теме
Комментарии
Автор

Excellent explanation.Esay approach.Thank you.

lakshmidevilakshmidevi
Автор

Your code would get fail if input string is like s ="abcbdaac" because you'r replacing the i value with map.get(ch) but in this case i should be replaced as map.get(ch) -1 as it has to include character "c" when second b is get encountered.

ayushsingh
Автор

public static int findL(String s) {
int l = s.length();
int a_pointer = 0;
int b_pointer = 0;
int max = 0;
HashSet<Character> hashSet = new HashSet<>();
while (b_pointer < l) {
if {

b_pointer++;
max = Math.max(hashSet.size(), max);
} else {
//
a_pointer++; // to iterate to next pointer since the current pointer is removed in the previous step
}
}
return max;
}

manishjoshi
Автор

Thank you sir this was amazing series on string!

vaibhavnirmal
Автор

Hi, sir while explaining use debugging mode so that it will easy to understand more clearly. Anyways, nice tutorial.

kogulselvanathan
Автор

i am not able to understand what else part doing

tricksforsolving
Автор

Map will clear whole values inside Map??

my_love_sanatan
Автор

the code will fail for ip:abac it gives 2 as op but the correct ans is 3 beacuse bac is longest sub string with no repeated character ...in your code we are not taking previous

RISHIKA_REDDY
Автор

Hi Sir,

This code is not working:

public static void main(String [] args) {


}
public static void s) {
String longestsubstring = null;
int longestsubstringlength = 0;
Map<Character, Integer> map = new LinkedHashMap<Character, Integer>();
char [] arr = s.toCharArray();
for (int i = 0; i < arr.length; i++) {
char ch = arr[i];
if (!map.containsKey(ch)) {
map.put(ch, i);
}
else {
i= map.get(ch);
map.clear();
}
if {
longestsubstringlength = map.size();
longestsubstring = map.keySet().toString();
}
}}

AbhishekSingh-hs
Автор

import java.util.LinkedHashMap;
import java.util.Map;

class Solution {
public static void s) {
String longestSubstring = null;
int lengthOfLongestSubstring = 0;
Map<Character, Integer> map = new LinkedHashMap<Character, Integer>();
char[] arr = s.toCharArray();
int start = 0;

for (int i = 0; i < arr.length; i++) {
char ch = arr[i];
if (map.containsKey(ch)) {
start = Math.max(start, map.get(ch) + 1);
}
map.put(ch, i);

if (i - start + 1 > lengthOfLongestSubstring) {
lengthOfLongestSubstring = i - start + 1;
longestSubstring = s.substring(start, i + 1);
}
}


}

public static void main(String[] args) {

}
}

proper working code for all string inputs

dhanushakian
Автор

else block is not clear, why are you getting index value and setting it to i

rjoker
Автор

Sir I written same program it is giving wrong answer if I pass string "aabb" it rutering 1 insted of

maheshmagarde
Автор

This code wont work for string ABCDEFGABEF

akhouritushar