FastPrepWords by Curly Brace Depth
Problems/Words by Curly Brace Depth

Words by Curly Brace Depth

Capital One logoCapital One● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One coding question in a 2021 Capital One report from a software engineer candidate in McLean was to read a string made of groups nested inside curly braces. The report shows one short sample, kept here as Example 1. It does not say which of its three interview steps asked it.

It does not say what the reading should produce. Here you return the words grouped by how many braces enclose them, outermost first. Each level's words are in reading order, and a level with no words gives an empty list. The braces are always balanced, words are lowercase, and the string is at most 2000 characters long. These are our choices.

Our version is about 50% the same as the reported question.

The string s holds words made of lowercase letters, curly braces { and }, and spaces. The braces are balanced and every word sits inside at least one pair. A word's depth is the number of brace pairs around it.

Return a list whose entry d (counting from 0) lists every word at depth d + 1, in the order the words appear in s. The list has one entry for each depth from 1 up to the deepest pair in s; a depth with no words gets an empty list.

Spaces only separate words. A brace can sit right next to a word.

Function

wordsByDepth(s: String) → List<List<String>>

Examples

Example 1

s = "{ hello { how are you } }"return = [["hello"],["how","are","you"]]

hello is inside one pair of braces, so it is at depth 1. how, are and you are inside two pairs, so they are at depth 2.

Example 2

s = "{ card {debit} { credit { gold } } fee }"return = [["card","fee"],["debit","credit"],["gold"]]

Depth 1 holds card and fee; fee comes after the inner groups close. Depth 2 holds debit and credit, from two different inner groups. Depth 3 holds only gold. A brace does not need a space next to it.

Example 3

s = "{{ deep }}"return = [[],["deep"]]

The outer pair holds no word of its own, so depth 1 is an empty list. deep sits at depth 2.

Constraints

  • 2 <= s.length <= 2000
  • s contains only lowercase English letters, {, } and spaces.
  • The braces in s are balanced, s has at least one pair, and every letter is inside at least one pair.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Molecular Weight of a Grouped FormulaAgoda · ONSITE INTERVIEWAgoda interview questions
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Rich Text Parser Part 3 (Depth Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Parse Nested HTML into a TreeApple · ONSITE INTERVIEWApple interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Lisp Expression ParserAmazon · ONSITE INTERVIEW
  • Lisp Expression ParserAttentive · ONSITE INTERVIEWAttentive interview questions
  • Flatten Nested Map Paths with a StackSalesforce · ONSITE INTERVIEWSalesforce interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public List<List<String>> wordsByDepth(String s) {
        // Write your code here.
    }
}
Checking account…