Find the longest substring without repeating characters.

Given a string, find the longest substrings without repeating characters. Iterate through the given string, find the longest maximum substrings.

Kotlin program to find the longest substring without repeating characters

import java.util.HashSet

fun subString(input: String): String {

    val set = HashSet()

    var longestOverAll = ""
    var longestTillNow = ""

    for (i in 0 until input.length) {
        val c = input[i]

        if (set.contains(c)) {
            longestTillNow = ""
        longestTillNow += c
        if (longestTillNow.length > longestOverAll.length) {
            longestOverAll = longestTillNow

    return longestOverAll

fun main(args: Array) {
    val input = "substringfindout"



Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Subscribe to See Videos

Subscribe to my Youtube channel for new videos : Subscribe Now