Solve Four Online Assessment Problems
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This multi-part question evaluates algorithmic problem-solving across array manipulation, exact fraction comparison, scheduling and simulation with ordered event lists, matrix transformation operations, and string concatenation/counting, exercising skills in data structures, searching, and combinatorial counting.
Part 1: Find the Best Value Index
Constraints
- 0 <= len(ratings) == len(prices) <= 200000
- -10^9 <= ratings[i] <= 10^9
- 1 <= prices[i] <= 10^9
- If two indices have equal value, return the smaller index
Examples
Input: ([10, 8, 9], [2, 4, 3])
Expected Output: 0
Explanation: The values are 5, 2, and 3, so index 0 is best.
Input: ([1, 2, 3], [2, 4, 6])
Expected Output: 0
Explanation: All ratios are exactly 1/2, so return the smallest index.
Input: ([-1, 2, -3], [1, 2, 1])
Expected Output: 1
Explanation: The values are -1, 1, and -3, so index 1 has the largest value.
Input: ([], [])
Expected Output: -1
Explanation: Empty input has no valid index, so return -1.
Hints
- To compare a/b and c/d exactly, compare a*d and c*b instead of dividing.
- If you only update the answer when you find a strictly larger ratio, ties automatically keep the smallest index.
Part 2: Schedule Round Trips
Constraints
- 0 <= missions <= 200000
- 0 <= len(aToB), len(bToA) <= 200000
- 0 <= trip time <= 10^9
- aToB and bToA are sorted in nondecreasing order
- Each array element represents one trip that can be used at most once
Examples
Input: (2, [1, 5, 10], [2, 6, 10])
Expected Output: 6
Explanation: Take 1 (A->B), then 2 (B->A), then 5 (A->B), then 6 (B->A).
Input: (2, [0, 1], [0, 1])
Expected Output: 1
Explanation: Trips at time 0 can be used for the first round trip, and trips at time 1 for the second.
Input: (2, [1], [2, 3])
Expected Output: -1
Explanation: After using 1 and 2 for the first round trip, there is no remaining A->B trip for the second.
Input: (0, [], [])
Expected Output: 0
Explanation: No round trips are required, so you finish immediately at time 0.
Hints
- Because the arrays are sorted and time only moves forward, two pointers are enough.
- After you use a trip at index i, the next search in that same array should continue from i + 1.
Part 3: Execute Matrix Transformation Commands
Constraints
- 0 <= number of rows, columns <= 100
- 0 <= number of commands <= 1000
- All rows in the input matrix have the same length
- All command indices are valid for the matrix state when that command is processed
Examples
Input: ([[1, 2, 3], [4, 5, 6]], [('swapRows', 0, 1), ('reverseRow', 0)])
Expected Output: [[6, 5, 4], [1, 2, 3]]
Explanation: After swapping rows, the first row becomes [4, 5, 6], then reversing it gives [6, 5, 4].
Input: ([[1, 2, 3], [4, 5, 6]], [('rotate90',)])
Expected Output: [[4, 1], [5, 2], [6, 3]]
Explanation: A 2x3 matrix becomes a 3x2 matrix after one clockwise rotation.
Input: ([[1, 2], [3, 4], [5, 6]], [('swapCols', 0, 1), ('reverseCol', 1)])
Expected Output: [[2, 5], [4, 3], [6, 1]]
Explanation: Swapping columns gives [[2, 1], [4, 3], [6, 5]], then reversing column 1 changes it to [5, 3, 1].
Input: ([[7]], [('rotate90',), ('reverseCol', 0), ('reverseRow', 0)])
Expected Output: [[7]]
Explanation: A single-element matrix stays the same under all these operations.
Hints
- Most commands affect only one row or one column, but rotate90 rebuilds the whole matrix.
- For a clockwise rotation, the new row c comes from old column c read from bottom to top.
Part 4: Count Concatenation Pairs Matching an Access Code
Constraints
- 0 <= len(fragments) <= 200000
- 0 <= len(accessCode) <= 200000
- The total length of all strings in fragments is at most 200000
- Strings may be empty
- The same index may be used for both positions in a pair
Examples
Input: (['ab', 'c', 'a', 'bc'], 'abc')
Expected Output: 2
Explanation: The valid ordered pairs are ('ab', 'c') and ('a', 'bc').
Input: (['a', 'a', ''], 'a')
Expected Output: 4
Explanation: Pairs are ('', 'a') using either 'a', and ('a', '') using either 'a', for a total of 4.
Input: (['', 'x', ''], '')
Expected Output: 4
Explanation: There are two empty strings, so every ordered pair of empty-string indices is valid: 2 * 2 = 4.
Input: (['aa'], 'aaaa')
Expected Output: 1
Explanation: The only valid pair is index (0, 0), which is allowed.
Input: (['a', 'b'], 'abx')
Expected Output: 0
Explanation: No ordered pair concatenates to 'abx'.
Hints
- If you fix the left fragment, the right fragment is completely determined.
- Use a frequency map so duplicate strings contribute multiple pairs automatically.