Solve delimiter and CSV tasks
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates skills in string parsing and bracket balancing, CSV/file parsing and joining, computation of derived values, and sorting, emphasizing data representation, correctness, and algorithmic efficiency.
Part 1: Validate Bracket Sequences
Constraints
- 0 <= len(s) <= 100000
- Each character in `s` is one of: `(`, `)`, `[`, `]`, `{`, `}`
Examples
Input: '()[]{}'
Expected Output: True
Explanation: Each opening bracket has a matching closing bracket in the correct order.
Input: '([{}])'
Expected Output: True
Explanation: This is a properly nested sequence.
Input: '(]'
Expected Output: False
Explanation: The closing `]` does not match the opening `(`.
Input: '([)]'
Expected Output: False
Explanation: The counts match, but the nesting order is wrong.
Input: ''
Expected Output: True
Explanation: An empty string is considered balanced.
Hints
- Use a stack to remember opening brackets as you scan from left to right.
- When you see a closing bracket, it must match the most recent unmatched opening bracket.
Part 2: Join Two CSV Files and Sort by Speed
Constraints
- 0 <= number of data rows in each file <= 10000
- Each file includes its header row
- Names are unique within each file
- Numeric fields are valid non-negative decimal numbers
- Field values do not contain embedded commas
Examples
Input: ['NAME,LEG_LENGTH,DIET\nRex,2.0,carnivore\nAva,1.5,herbivore\nMoe,3.0,omnivore', 'NAME,STRIKE,STANCE\nAva,4.0,biped\nRex,3.0,biped\nNotInFirst,10.0,biped']
Expected Output: [['Ava', 6.0], ['Rex', 6.0]]
Explanation: Only `Ava` and `Rex` appear in both files. Both have speed 6.0, so the tie is broken alphabetically.
Input: ['NAME,LEG_LENGTH,DIET\nA,1.0,herbivore', 'NAME,STRIKE,STANCE\nB,2.0,biped']
Expected Output: []
Explanation: There are no shared names between the two files.
Input: ['NAME,LEG_LENGTH,DIET', 'NAME,STRIKE,STANCE']
Expected Output: []
Explanation: Both files contain only headers, so there is nothing to join.
Input: ['NAME,LEG_LENGTH,DIET\nStego,4.0,herbivore', 'NAME,STRIKE,STANCE\nStego,2.5,quadruped']
Expected Output: [['Stego', 10.0]]
Explanation: A single shared dinosaur gives one output row.
Input: ['NAME,LEG_LENGTH,DIET\n\n Neo , 2.5 , herbivore \nTri,1.0,carnivore', 'NAME,STRIKE,STANCE\nTri,4.0,biped\n\n Neo , 2.0 , biped ']
Expected Output: [['Neo', 5.0], ['Tri', 4.0]]
Explanation: Extra spaces and blank lines should be ignored while parsing.
Hints
- Parse one file into a dictionary keyed by dinosaur name so you can join in O(1) average lookup time.
- After building the joined result, sort with a key like `(-speed, name)`.