Skip to main content

Oracle

Oracle OA-10 2024

Problem Description

You are given a string str, and your task is to determine how many unique substrings it contains that do not have any repeated characters. Two substrings are considered distinct if they start or end at different indices.

Function Description:

Complete the function countUniqueSubstrings as described below.

Parameters:

  • string str: The input string consisting of lowercase English letters.

Returns:

  • The number of unique substrings in str that do not contain repeated characters.

Constraints:

  • 1 <= length of str <= 10^5
  • str contains only lowercase English letters (['a' - 'z']).

Example:
For the string "abac":

The substrings that have no repeating characters are:

  • "a", "b", "a", ab", "c", "ab", "ac", and "bac".

Note that "aba" and "abac" do not qualify because the character 'a' is repeated in them. Also, two substrings, "a" and "a", both qualify because their start indices are different: s[0] and s[2].

Thus, there are 8 substrings that have no repeating characters.

Sample Input:

bcada

Output:

9

Explanation:
For the string "bcada", the substrings with no repeating characters are:

  • "b", "c", "a", "d", "bc", "ca", "ad", "bca", and "cad".

Thus, there are 9 substrings that meet the criteria.

Given a string, determine how many different substrings exist in it that have no repeating characters. Two substrings are considered different if they have a different start or end index.