Every Distinct Substring in Order
Updated
Problem statement
You are given a string s. A substring is a run of one or more consecutive characters of s. Return every different substring of s exactly once: two substrings taken from different positions that spell the same text count as one.
Return them in dictionary order. Compare two strings letter by letter; when one string is the start of the other, the shorter one comes first (so ab comes before abc, which comes before b).
Function
distinctSubstrings(s: String) → List<String>Examples
Example 1
s = "dad"return = ["a","ad","d","da","dad"]The pieces of dad are d, a, d, da, ad and dad. d appears twice but is listed once, so 5 different pieces remain, in dictionary order.
Example 2
s = "zzz"return = ["z","zz","zzz"]Every piece is made of z only, so the different pieces are just the three lengths 1, 2 and 3.
Example 3
s = "pear"return = ["a","ar","e","ea","ear","p","pe","pea","pear","r"]All four letters differ, so all 4 + 3 + 2 + 1 = 10 pieces are different. In dictionary order a shorter piece comes before a longer piece that starts with it, so e comes before ea.
Constraints
1 <= s.length <= 30scontains only lowercase English letters
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Remove Prefix StringsRoblox · PHONE SCREENRoblox interview questions
- Shell Path AutocompleteFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Top K Query SuggestionsMicrosoft · PHONE SCREENMicrosoft interview questions
- Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
- Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Search Suggestions with a Prefix TreeCitadel · ONSITE INTERVIEWCitadel interview questions
- Highlight and Rank Overlapping CitationsHarvey · ONSITE INTERVIEWHarvey interview questions
- Suggested ProductsSquarepoint Capital · OASquarepoint Capital interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)