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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Shuffling Names and Sorting Code
00:00
5 left

Shuffling Names and Sorting Code

HardPython

Problem

Sonata Software needs a reproducible way to rearrange names for test data and display them in alphabetical order. Given a list of names and a non-negative seed, implement a deterministic shuffle using the Fisher-Yates algorithm, then return both the shuffled list and a case-insensitive sorted copy.

Use this linear congruential generator for reproducibility:

state = (1103515245 * state + 12345) % 2^31

During Fisher-Yates, process indices from n - 1 down to 1. After updating the generator state, choose j = state % (i + 1) and swap positions i and j. The input list must not be modified. Sorting must be stable, so names that differ only by case retain their original relative order in the sorted result.

Formal Specification

Implement shuffle_and_sort_names(names, seed). The input is a list of strings and a non-negative integer. Return a dictionary with shuffled, containing the deterministic permutation, and sorted, containing the original names sorted by name.casefold().

Constraints

  • 0 <= len(names) <= 10^5
  • 0 <= seed < 2^31
  • Each name contains 1 to 100 Unicode characters
  • Duplicate names and case variations are allowed

Function Signature

def shuffle_and_sort_names(names, seed):
Interviewer

Your question is Shuffling Names and Sorting Code. 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.