Single-Nested Valid Bracket Substrings
Updated
Problem statement
Given a valid bracket sequence s built from round, square, and curly brackets, return every substring that forms one single nested segment.
Each opening bracket and its matching closing bracket define exactly one such segment. A segment may contain any number of complete child segments, but a concatenation of sibling segments is not itself one segment unless another matching pair encloses it.
Return the segments in increasing order of their opening positions. If equal substring values occur at different positions, retain every occurrence.
Function
singleNestedSegments(s: String) → String[]Examples
Example 1
s = "()[()]{[][]}"return = ["()","[()]","()","{[][]}","[]","[]"]The opening positions occur in the order 0, 2, 3, 6, 7, 9. The two equal [] segments come from different matched pairs, so both remain in the output.
Example 2
s = "{}{[]}"return = ["{}","{[]}","[]"]The whole string is a concatenation of two top-level segments, so it is not returned as one segment. Its three matched pairs contribute {}, {[]}, and [].
Example 3
s = "{[()]}"return = ["{[()]}","[()]","()"]The three opening brackets appear from outermost to innermost, so their matched substrings are returned in that order.
Constraints
1 <= s.length <= 2000.scontains only(,),[,],{, and}.sis a valid bracket sequence and may contain multiple top-level segments.
More Wells Fargo interview questions
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
- Compare Calendar DatesPHONE SCREEN · Seen May 2025
- Count Array Element FrequenciesPHONE SCREEN · Seen May 2025
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
Similar questions at other companies
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Rich Text Parser Part 3 (Depth Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Decode an Encoded StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Parse Indented YAML MappingsUber · PHONE SCREENUber interview questions
- Decode Repeated GroupsWaymo · PHONE SCREENWaymo interview questions
- Deserialize XML Into a TreeAdobe · PHONE SCREENAdobe interview questions
- Convert Email Text to Structured MarkupZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions