VOOZH about

URL: https://www.geeksforgeeks.org/dsa/count-of-all-unique-substrings-with-non-repeating-characters/

⇱ Count of all unique substrings with non-repeating characters - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count of all unique substrings with non-repeating characters

Last Updated : 12 Jul, 2025

Given a string str consisting of lowercase characters, the task is to find the total number of unique substrings with non-repeating characters.

Examples: 

Input: str = "abba" 
Output:
Explanation: 
There are 4 unique substrings. They are: "a", "ab", "b", "ba".

Input: str = "acbacbacaa" 
Output: 10 

Approach: The idea is to iterate over all the substrings. For every substring, check whether each particular character has previously occurred or not. If so, then increase the count of required substrings. In the end return this count as count of all unique substrings with non-repeating characters.

Below is the implementation of the above approach: 


Output: 
4

 

Time Complexity: O(N2) where N is the length of the string.
Auxiliary Space: O(N2), to store all substrings in hashmap.

Comment
Article Tags:
Article Tags: