Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Card Shuffling Program
00:00
5 left

Card Shuffling Program

EasyPython

Problem

Applied Epic workflows may need to randomize a set of cards used in training or simulation exercises. Implement a function that produces a uniformly shuffled copy of a deck using the Fisher-Yates algorithm.

For deterministic evaluation, the function receives random_values. During the shuffle, each value supplies the selected swap index for one iteration. The first value is used when i = n - 1, the second when i = n - 2, and so on. Every supplied value must already satisfy 0 <= random_values[k] <= i for its iteration.

The original deck must remain unchanged. Return a new list containing exactly the same cards, each appearing once.

Formal Specification

  • Input: deck, a list of distinct strings, and random_values, a list of integers with length max(0, len(deck) - 1).
  • Output: A new list containing a permutation of deck.
  • Do not call Python's built-in shuffle function.

Constraints

  • 0 <= len(deck) <= 10^5
  • All card labels are distinct strings
  • len(random_values) = max(0, len(deck) - 1)
  • For iteration i, the corresponding random value satisfies 0 <= random_value <= i

Function Signature

def shuffle_deck(deck, random_values):
Interviewer

Your question is Card Shuffling Program. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.