Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cards Shuffle Program

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

Your question is Cards Shuffle Program. 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

A.O. Smith field-service software uses card-like lists to present diagnostic actions in a randomized order. Implement a function that returns a uniformly shuffled copy of the provided cards using the Fisher-Yates algorithm.

The shuffle must be deterministic for the same seed, must not modify the input list, and must preserve every card exactly once. Cards may be any JSON-compatible values, including strings or numbers.

Formal Specification

Implement shuffle_cards(cards, seed), where cards is a list and seed is an integer. Return a new list containing the same elements in shuffled order. Initialize a local pseudorandom generator with seed; do not use or modify global random state.

Constraints

  • 0 <= len(cards) <= 10^5
  • seed is an integer
  • Card values are distinct in the intended use case
  • The input list must not be modified
  • The output must preserve the input multiset

Function Signature

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