FastPrepShortest Atom Action Path
Problems/Shortest Atom Action Path

Shortest Atom Action Path

OpenAI logoOpenAI● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OpenAI online assessment for a full-time role. The report describes avoiding forbidden grid cells and rebuilding a shortest atom path, but does not show the action definitions. Here an explicit action table, the transition conventions and a tie rule define the task.

Our version is about 70% the same as the reported question.

An atom starts at cell start in a rectangular grid and must reach cell target. A cell containing . is allowed; a cell containing # is forbidden. Coordinates are zero-based [row, column] pairs, with rows increasing downward and columns increasing to the right.

The input actions defines the available moves. Action i changes cell (r, c) to (r + actions[i][0], c + actions[i][1]). Every action costs one step and may be used repeatedly.

  • An action is legal only when its destination is inside the grid and allowed.
  • Each action is an atomic transition. Only its destination is checked: it may jump over forbidden cells or move diagonally without visiting intermediate cells.
  • Actions are directed. A reverse move is available only if its offset appears in actions.
  • Different action indices may have identical offsets. They remain distinct choices.

Return the sequence of action indices that reaches target using the fewest steps. If several shortest sequences exist, return the lexicographically smallest one: at the first differing position, the smaller action index wins.

Return an empty array if start already equals target. Return [-1] if the target cannot be reached. Both the start and target are guaranteed to be allowed cells.

Function

shortestAtomPath(grid: String[], start: int[], target: int[], actions: int[][]) → int[]

Examples

Example 1

grid = ["...","..."]start = [0,0]target = [1,2]actions = [[0,1],[1,0],[0,-1],[-1,0]]return = [0,0,1]
grid
0120...1...

The atom visits (0,0), (0,1), (0,2), (1,2). Three actions are necessary. Of the shortest sequences, [0,0,1] is lexicographically smallest.

Example 2

grid = [".#...","#####","...#."]start = [0,0]target = [2,4]actions = [[0,2],[2,0],[0,-2],[-2,0]]return = [0,0,1]
grid
012340.#...1#####2...#.

The atom visits (0,0), (0,2), (0,4), (2,4). Each action checks only its destination, so it may jump over a forbidden cell. All three destinations are allowed; the smaller action index breaks the tie with other three-step routes.

Example 3

grid = ["..",".."]start = [1,1]target = [0,0]actions = [[1,0],[0,1]]return = [-1]
grid
010..1..

Both actions leave the grid from (1,1). The target is allowed, but no sequence of the directed actions reaches it.

Constraints

  • 1 <= grid.length <= 100 and 1 <= grid[r].length <= 100.
  • All rows have the same length and contain only . or #.
  • start.length = target.length = 2; both coordinates are inside the grid and identify allowed cells.
  • 1 <= actions.length <= 8; each action contains exactly two integers.
  • Each action component is between -100 and 100, inclusive. No action is [0, 0]; duplicate offsets are allowed.

More OpenAI Online Assessment questions

  • Count Routes Through Four Shop TypesOA · Seen Oct 2026
  • Digit-Sum Sequence Join PointOA · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
  • Password Clues and the Next CommandOA · Seen Oct 2026
  • Longest Increasing Price SubsequenceOA · Seen Oct 2026
  • Macaron Order PriceOA · Seen Oct 2026
  • Simplify a Quadratic ExpressionOA · Seen Oct 2026
  • Minimum-Cost Color SequenceOA · PHONE SCREEN · Seen Oct 2026
  • Largest Microorganism After ConsumptionOA · Seen Oct 2026
  • Invert or Blur an ImageOA · Seen Sep 2026

Similar questions at other companies

  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
  • Count Islands with DFS and BFSVisa · OAVisa interview questions
  • Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Count One Groups by SizeAgoda · OAAgoda interview questions
  • Ascend Vertical Wall (For off-campus 2025 batch hiring :)Uber · OAUber interview questions
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • Nearest Different Maze Exit for a SnakeIntuit · OAIntuit interview questions
  • Minimum Grid MovesAtlassian · OAAtlassian interview questions

Interview reports that mention this question

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int[] shortestAtomPath(String[] grid, int[] start, int[] target, int[][] actions) {
        // Write your code here
    }
}
Checking account…