Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

One-Dimensional Tile Moves

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is One-Dimensional Tile Moves. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Suppose you have a one-dimensional board of two colors of tiles. Given a start and end configuration represented as a list of strings, return a list of valid moves to get from start to end, or None if none exist, including the start and end states in the list of moves.

Represent the empty position with "_". A valid move swaps the empty position with an immediately adjacent tile. Implement def solve_board(start, end):, where both arguments are lists of one-character strings and the result is a list of board states or None.

Constraints

  • 1 <= len(start) = len(end) <= 12
  • Each configuration contains exactly one "_"
  • Each element is one of "R", "B", or "_"
  • Configurations may contain different tile multisets
  • Return None when no valid sequence exists

Function Signature

def solve_board(start, end):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output