Solve Four Online Assessment Coding Tasks
Company: Virtu
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This set of four problems evaluates a candidate's proficiency in core algorithmic competencies including string parsing and bracket validation, bitwise reasoning and flip-count optimization, interval coverage and greedy/coverage strategies for binary strings, and array partitioning with segment-sum equivalence.
Part 1: Validate Bracket Strings
Constraints
- 0 <= len(brackets) <= 10000
- 0 <= len(brackets[i]) <= 100000
- The total length of all strings is at most 200000
- Each string contains only the characters (), [], {}
Examples
Input: (['()', '([]){}', '([)]', ''],)
Expected Output: [True, True, False, True]
Explanation: The first two strings are valid, `([)]` is not properly nested, and the empty string is valid.
Input: (['(', ')', '{{[]}}'],)
Expected Output: [False, False, True]
Explanation: A single opening or closing bracket is invalid. `{{[]}}` is correctly nested.
Input: ([],)
Expected Output: []
Explanation: Edge case: an empty input list returns an empty result list.
Input: (['{[()()]}', '{[(])}', '][', '(()'],)
Expected Output: [True, False, False, False]
Explanation: Only the first string is valid.
Hints
- Use a stack to track opening brackets as you scan each string from left to right.
- When you see a closing bracket, it must match the most recent unmatched opening bracket.
Part 2: Minimize Bit Flips to Make Numbers Equal
Constraints
- 1 <= len(nums) <= 200000
- 0 <= nums[i] <= 10^9
Examples
Input: ([1, 2],)
Expected Output: 2
Explanation: Using width 2, the numbers are `01` and `10`. One flip is needed in each bit position, for a total of 2.
Input: ([7, 7, 7],)
Expected Output: 0
Explanation: All numbers are already equal.
Input: ([0],)
Expected Output: 0
Explanation: Edge case: a single element needs no changes.
Input: ([0, 1, 3],)
Expected Output: 2
Explanation: Using width 2: bit 0 needs 1 flip, bit 1 needs 1 flip.
Input: ([8, 0, 8, 0],)
Expected Output: 2
Explanation: Only the highest bit differs, and two flips are needed there.
Hints
- Each bit position can be optimized independently from the others.
- For a fixed bit position, choose the final bit value that matches the majority of numbers at that position.
Part 3: Eliminate Long Runs of Zeros
Constraints
- 0 <= len(s) <= 200000
- 1 <= m <= 200000
- 1 <= k <= 200000
- s contains only `0` and `1`
Examples
Input: ("00100", 2, 3)
Expected Output: 1
Explanation: Turning the middle length-3 substring into `111` gives `01110`, which has no `00`.
Input: ("000000", 3, 2)
Expected Output: 1
Explanation: One operation on the middle two positions yields `001100`, and the longest zero run is then 2.
Input: ("10101", 2, 2)
Expected Output: 0
Explanation: The string already has no run of two or more zeros.
Input: ("000", 2, 4)
Expected Output: -1
Explanation: Edge case: no length-4 operation fits inside the string, so the invalid run cannot be changed.
Input: ("01010", 1, 2)
Expected Output: 3
Explanation: When `m = 1`, every zero must be covered by at least one operation. Three operations are needed.
Hints
- The condition is equivalent to saying every length-`m` substring must contain at least one `1` in the final string.
- Focus on windows that are all zeros in the original string. Greedily fix the leftmost uncovered bad window by placing the operation as far right as possible.
Part 4: Make Two Arrays Equal by Merging Segment Sums
Constraints
- 1 <= len(a), len(b) <= 200000
- 1 <= a[i], b[i] <= 10^9
Examples
Input: ([1, 2, 1], [1, 1, 2])
Expected Output: 2
Explanation: One optimal common sequence is `[1, 3]`.
Input: ([1, 1], [2])
Expected Output: 1
Explanation: Both arrays can be reduced to `[2]`.
Input: ([1, 2], [1, 1])
Expected Output: -1
Explanation: The total sums differ, so no common final sequence exists.
Input: ([5], [5])
Expected Output: 1
Explanation: Edge case: both arrays already match as a single segment.
Input: ([2, 1, 1, 2], [1, 3, 2])
Expected Output: 2
Explanation: One optimal common sequence is `[4, 2]`.
Hints
- If the total sums of the arrays are different, they can never become equal.
- Because all values are positive, common segment boundaries occur exactly at common cumulative sums.