
Asked in Adobe
Count Distinct Substrings
You are provided with a string S
. Your task is to determine and return the number of distinct substrings, including the empty substring, of this given string. Implement the solution using a trie data structure.
Input:
First line contains an integer T
representing the number of test cases.
For each test case, a single line contains the string S
.
Output:
Output consists of T lines, each containing an integer result for each test case, representing the number of distinct substrings of string S
.
Example:
Input:
2
ab
abc
Output:
4
7
Explanation:
For 'ab', distinct substrings are: "", "a", "b", "ab".
For 'abc', distinct substrings are: "", "a", "b", "c", "ab", "bc", "abc".
Constraints:
1 <= T <= 5
1 <= |S| <= 10^3
S
consists only of lowercase English letters.
Note:
No need to handle printing; this has been managed already. Focus purely on implementing the specified function.

AnswerBot
4mo
Count distinct substrings of a given string using trie data structure.
Implement a trie data structure to store all substrings of the given string.
Count the number of nodes in the trie to get the disti...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Adobe
Q. Unbounded Knapsack Problem Statement Given ‘N’ items, each with a specific profi...read more
Q. Minimum Cost to Make String Valid Given a string containing only '{' and '}', de...read more
Q. Digit Count In Range Problem Statement Given an integer K, and two numbers A and...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Adobe Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

