FastPrepSliding Puzzle
Problems/Sliding Puzzle

Sliding Puzzle

NVIDIA logoNVIDIA● HardFULLTIMEPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported numbered puzzle matches at about 90%. The phonetic number is resolved to the standard 2 x 3 board, legal moves, target and unreachable result.

The 2 x 3 board contains tiles 1 through 5 and one empty cell 0. In one move, swap the empty cell with a tile directly above, below, left or right of it.

Return the minimum moves needed to reach [[1,2,3],[4,5,0]]. Return -1 if the target is unreachable.

Function

slidingPuzzle(board: int[][]) → int

Examples

Example 1

board = [[1,2,3],[4,0,5]]return = 1
board
01201231405

Swap the empty cell with tile 5.

Example 2

board = [[1,2,3],[5,4,0]]return = -1
board
01201231540

Swapping the two numbered tiles changes the component; no sequence reaches the target.

Example 3

board = [[4,1,2],[5,0,3]]return = 5
board
01204121503

The shortest path uses five legal swaps.

Constraints

  • board has exactly two rows and three columns.
  • Its six cells contain each integer from 0 through 5 exactly once.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Shortest Distance from All BuildingsWaymo · PHONE SCREENWaymo interview questions
  • Maximum-Clearance Path From a PointGoogle · PHONE SCREENGoogle interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Count Connected IslandsUber · PHONE SCREENUber interview questions
  • Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int slidingPuzzle(int[][] board) {
        // Write your code here.
    }
}
Checking account…