← Questions

Research OA: best value ratio, shuttle trips and grid commands

0
MetaCodingLast asked Mar 2026

A coding interview question asked in Meta's technical phone screen, last asked Mar 2026. It tests arrays, simulation and two pointers.

A timed online assessment with independent tasks; write a function for each.

Part 1: best value index

Unless you agree on a different interface with the interviewer, assume:

  • best_value_index(ratings: list[int], prices: list[int]) -> int — the index with the largest ratings[i] / prices[i], the smallest index on ties, -1 for empty arrays. Compare fractions exactly with integer cross-multiplication (a * d versus c * b), never floating point.
best_value_index([10, 8, 9], [2, 4, 3])  ->  0    # values 5, 2, 3
best_value_index([1, 2, 3], [2, 4, 6])   ->  0    # all exactly 1/2; smallest index

Constraints: up to 2 * 10^5 items; ratings in [-10^9, 10^9]; prices in [1, 10^9].

Part 2: shuttle round trips

  • finish_time(missions: int, a_to_b: list[int], b_to_a: list[int]) -> int — you must make missions round trips, each one trip A to B then one trip B to A. Both lists hold departure times, sorted, and each departure can be used once. You start at A at time 0 and always take the earliest unused departure at or after the current time; taking it sets the current time to its departure time. Return the time after the last trip, or -1 if you run out of departures.
finish_time(2, [1, 5, 10], [2, 6, 10])  ->  6    # 1, 2, 5, 6
finish_time(2, [0, 1], [0, 1])          ->  1    # 0, 0, 1, 1
finish_time(2, [1, 5], [2, 3])          ->  -1   # no B-to-A departure after 5

Constraints: up to 2 * 10^5 missions and departures; times in [0, 10^9].

Part 3: grid commands

  • apply_commands(matrix: list[list[int]], commands: list[tuple]) -> list[list[int]] — apply in order: ("swapRows", r1, r2), ("swapCols", c1, c2), ("reverseRow", r), ("reverseCol", c), ("rotate90",) clockwise (which swaps the dimensions). Indices are 0-based and valid when each command runs.
apply_commands([[1, 2, 3], [4, 5, 6]], [("swapRows", 0, 1), ("reverseRow", 0)])
    ->  [[6, 5, 4], [1, 2, 3]]
apply_commands([[1, 2, 3], [4, 5, 6]], [("rotate90",)])
    ->  [[4, 1], [5, 2], [6, 3]]

Constraints: up to 100 x 100 cells and 1,000 commands.

Clarifying questions

  • Part 1: can ratings be negative, and do products overflow 64 bits?
  • Part 2: is a departure at exactly the current time allowed? Can one departure be reused?
  • Part 3: does rotate90 change which indices later commands refer to?

What a strong answer covers

  • Part 1: a single pass updating the best only on a strictly larger cross-product, which keeps the smallest index on ties.
  • Part 2: two pointers that only move forward (or a lower-bound binary search starting after the last used index), O(missions + n), with the out-of-departures check on every leg.
  • Part 3: in-place swaps and reversals, and a rebuild for rotation (new row c is old column c read bottom to top); for many commands, tracking a lazy transform instead of moving data.
  • Edge cases in each: empty input, zero missions, a 1 x n matrix.

Follow-ups

  • Part 1: return the top k indices by value.
  • Part 2: you may wait at either end; what is the minimum number of round trips possible by a deadline?
  • Part 3: answer queries for single cells after 10^5 commands without materialising the matrix.

Where it's asked

  • Meta · Technical phone screen · Last asked Mar 202645 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted

What it tests

arrays · simulation · two pointers

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding