Problem · String

Find the Longest Isolated Substring Length

Learn this problem
MediumAmazonNEW GRADOA
See Amazon hiring insights

Problem statement

The task is to determine the length of the longest isolated proper substring within a given string. An isolated proper substring must satisfy the following conditions:

  • The substring is not the entire given string inputString.
  • No character within the substring appears anywhere outside the substring.

Given a string inputString of length n, determine the length of its longest isolated proper substring. If no such substring exists, return 0.

Function

findLongestIsolatedSubstringLength(s: String) → int

Implement the function findLongestIsolatedSubstringLength in the editor.

The function takes the following parameter:

  1. String inputString: the string to analyze

Returns

int: the length of the longest isolated proper substring

Examples

Example 1

s = "abcba"return = 0
Example 1 illustration
A new test case added on 03-01-2025 for your testing convenience :) The source said the expected output should be 3 - "abcba output should be : 3 (the substring will be bcb). but expected output is 0."

Example 2

s = "amazonservices"return = 11
Example 2 illustration
(Image updated on 2025-02-02) The longest self-sufficient proper substring is "zonservices" which has a length of 11.

Constraints

  • s consists of lowercase letters.
  • 1 ≤ n ≤ 10^5

More Amazon problems

drafts saved locally
public int findLongestIsolatedSubstringLength(String s) {
  // write your code here
}
s"abcba"
expected0
checking account