• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Longest Substring

  • January 6, 2020
  • CODE OF GEEKS
  • 9


Find longest substring of unique characters which is case insensitive. 

For “ABDEFGABEF”, the longest substring are “BDEFGA” and “DEFGAB”, with length 6.

For “BBBB”, the longest substring is “B”, with length 1.

For “CDEF”, the longest substring is “CDEF” with length 4.

Input : 

First Input : String

Output : Length of longest substring

Sample Testcases :

I/P 1:

CDEF

O/P 1:

4



Solution provided by our user :

l=input()
len1=len(l)
a=[]
maxi=[]
for i in range(len1):
    for j in range(i,len1):
        if l[j] in a:
            break;
        else:
            a.append(l[j])
    if len(maxi)<=len(a):
        maxi=a
        a=[]
    else:
        a=[]
print(len(maxi))
Tags: infosys last year handson problemsinfytqinfytq examinfytq examinationinfytq handson problems last yearinfytq handson problems of last yearinfytq handson questionsinfytq last year coding problemsinfytq last year problemsinfytq last year questionsLast year questions Infytqpractice infyprepare infytq question
  • Previous Special Reversal
  • Next Factor Game

9 comments on “Longest Substring”

  1. GIRISH says:
    March 3, 2020 at 9:03 am

    #this is my code it worked
    l=input(“enter the string: “)
    len1=len(l)
    a=[]
    maxi=[]
    for i in range(len1):
    for j in range(i,len1):
    if l[j] in a:
    break;
    else:
    a.append(l[j])
    if len(maxi)<=len(a):
    maxi=a
    a=[]
    else:
    a=[]
    print(maxi)

    Reply
    1. girish says:
      March 3, 2020 at 2:28 pm

      sorry about the tab spaces.

      Reply
  2. RISHABH GUPTA says:
    June 2, 2020 at 5:22 pm

    step1. Change the string in upper case.(for avoiding the case sensitive result,avoid it if input is always in upper cases or lower cases)
    step2. Convert the string into Set and print its length.
    here is two line code.

    string=input()
    print(len(set(string.upper())))

    Reply
    1. Sagar says:
      April 13, 2021 at 1:03 pm

      This is wrong …try ABBCD..

      Reply
    2. vaishali khilari says:
      April 14, 2021 at 4:37 am

      i think your solutiom won’t work for all testcases
      consider the one:ABCDEFFDCMNOPQ

      rectify me if am wrong

      Reply
  3. Charan Manne says:
    June 13, 2020 at 9:49 am

    import java.util.*;
    import java.io.*;

    public class LongestSubstring {
    public static void main(String[] args)throws Exception {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    String s=br.readLine();
    System.out.println(Norepeat(s));

    }

    public static String Norepeat(String input) {
    Map visited = new HashMap();
    String output = “”;
    for (int start = 0, end = 0; end < input.length(); end++) {
    char currChar = input.charAt(end);
    if (visited.containsKey(currChar)) {
    start = Math.max(visited.get(currChar)+1, start);
    }
    if (output.length() < end – start + 1) {
    output = input.substring(start, end + 1);
    }
    visited.put(currChar, end);
    }
    return output;
    }

    }

    Reply
  4. Vijay_Paturi says:
    March 16, 2021 at 8:21 am

    s=input()
    l=[]
    if len(s)==len(set(s)):
    print(len(s))
    elif len(set(s))==1:
    print(1)
    else:
    for i in range(len(s)):
    for j in range(i+1,len(s)):
    if s[i]==s[j]:
    l.append(len(s[i+1:j+1]))
    print(max(l))

    Reply
  5. Ankit Sisodiya says:
    April 15, 2021 at 4:42 pm

    s=input()
    t=””
    m=0
    for i in range(len(s)):
    for j in range(i,len(s)):
    if s[j] in t:
    if m<len(t):
    m=len(t)
    t=""
    t+=s[j]
    print(m)

    Reply
  6. Ashutosh Tripathi Ashutosh Tripathi says:
    April 16, 2021 at 4:06 pm

    /*package whatever //do not write package name here */

    import java.io.*;
    import java.util.*;

    class GFG {
    public static void main (String[] args) {

    String input=”BBBBB”;

    ArrayList al= new ArrayList();
    int maxL=0;

    for (int i=0;i<input.length();i++ ){
    for(int j=i;jmaxL){
    maxL=al.size();
    al.clear();
    }
    else
    al.clear();
    }

    System.out.println(maxL);

    }

    }

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

What is Cloud Computing | Cloud Computing Applications | Cloud Development Models| SaaS vs PaaS vs IaaS
  • October 23, 2021
What is Amazon Web Services | AWS Regions & AZs | Different AWS Services
  • October 19, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →