Solve common string/tree/grid interview tasks
Company: Bloomberg
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This problem set evaluates practical coding competencies including string parsing and sign handling, positional and frequency-based matching for feedback scoring, grid pathfinding via backtracking traversal, and binary-tree vertical ordering using column indices and level-order traversal, testing data structure knowledge (arrays, hash maps, trees) and algorithmic techniques (search, traversal, and counting). It is commonly asked in the Coding & Algorithms domain to measure correctness on edge cases, handling of duplicates and positional constraints, and implementation efficiency; the tasks are primarily practical implementation problems that also require conceptual understanding of algorithmic trade-offs and traversal strategies.
Part 1: Parse an Integer from a String
Constraints
- 0 <= len(s) <= 100000
- s may begin with '+' or '-'
- If a sign is present, it must be followed by at least one digit
- No whitespace or decimal points need to be handled
- Use normal Python integer behavior; no 32-bit clamping is required
Examples
Input: '123'
Expected Output: 123
Explanation: A normal positive integer should be parsed directly.
Input: '-45'
Expected Output: -45
Explanation: The leading '-' makes the result negative.
Input: '+0'
Expected Output: 0
Explanation: A leading '+' is allowed.
Input: ''
Expected Output: 0
Explanation: Empty input is invalid, so return 0.
Input: '12a3'
Expected Output: 0
Explanation: Any non-digit after the optional sign makes the format invalid.
Hints
- Handle the optional sign first, then scan the rest of the characters from left to right.
- Build the number manually using value = value * 10 + digit instead of calling int().
Part 2: Compute Wordle-Style Feedback
Constraints
- 0 <= len(guess) == len(target) <= 100000 in valid inputs
- Strings may contain repeated characters
- A target character can only be matched once: first by greens, then by yellows
Examples
Input: ('apple', 'apple')
Expected Output: 'GGGGG'
Explanation: Every character matches in the same position.
Input: ('allee', 'apple')
Expected Output: 'GYBBG'
Explanation: The first 'a' and last 'e' are green; only one of the two 'l' letters can be yellow.
Input: ('bbbb', 'aaaa')
Expected Output: 'BBBB'
Explanation: No guessed letters appear in the target.
Input: ('aabb', 'bbaa')
Expected Output: 'YYYY'
Explanation: All letters exist, but every one is in the wrong position.
Hints
- A good strategy is to do two passes: mark all greens first, then process yellows using counts of the remaining target letters.
- Do not mark a letter yellow just because it exists somewhere in the target; make sure that occurrence has not already been used.
Part 3: Word Path in a Grid
Constraints
- 0 <= number of rows, columns <= 6
- 0 <= len(word) <= 15
- board is rectangular
- You may move only in 4 directions: up, down, left, right
- A cell may be used at most once in any single candidate path
Examples
Input: ([['A','B','C','E'],['S','F','C','S'],['A','D','E','E']], 'ABCCED')
Expected Output: True
Explanation: A valid path exists through adjacent cells without reusing any cell.
Input: ([['A','B','C','E'],['S','F','C','S'],['A','D','E','E']], 'SEE')
Expected Output: True
Explanation: The word can be formed using a different path in the same board.
Input: ([['A','B','C','E'],['S','F','C','S'],['A','D','E','E']], 'ABCB')
Expected Output: False
Explanation: The board contains the letters, but forming the word would require reusing a cell.
Input: ([], 'A')
Expected Output: False
Explanation: A non-empty word cannot be formed from an empty board.
Input: ([['A']], '')
Expected Output: True
Explanation: The empty word is considered trivially present.
Hints
- Try starting a depth-first search from each cell that matches the first character.
- Mark a cell as visited while exploring a path, then unmark it when backtracking.
Part 4: Vertical Order Traversal of a Binary Tree
Constraints
- 0 <= len(values) <= 10000
- values contains integers or None
- The list represents the tree in standard level-order form
- If values is empty or starts with None, the tree is empty
Examples
Input: [3, 9, 20, None, None, 15, 7]
Expected Output: [[9], [3, 15], [20], [7]]
Explanation: Nodes are grouped by column from left to right.
Input: [3, 9, 8, 4, 0, 1, 7]
Expected Output: [[4], [9], [3, 0, 1], [8], [7]]
Explanation: The nodes 0 and 1 share the same row and column, and BFS keeps them in left-to-right order.
Input: []
Expected Output: []
Explanation: An empty tree has no columns.
Input: [1, None, 2, 3]
Expected Output: [[1, 3], [2]]
Explanation: The node 3 is the left child of 2, so it returns to column 0.
Hints
- Use a breadth-first traversal and track each node's column index.
- BFS naturally preserves the required top-down and left-to-right order for nodes that share a row and column.