Want a Free Job Posting?

Buy a job posting today and the second one is on us. For a limited time only. Act Now.

Interview Question

Interview Waterloo, ON (Canada)

Write a function to sort N decks of 52 playing cards

  represented as an integer array with indexes from 0 to N*52 - 1. You are supplied a random generator that produces numbers from 0 to N - 1 for this task. What is the worst case runtime and memory bound?

Interview Answer

1 Answer


Iterate the array and on each iteration use the random number generator to select another cell in the array to swap your current value with. O(N) runtime, O(1) memory usage.

Interview Candidate on Oct 30, 2009

Add Answers or Comments

To comment on this, Sign In or Sign Up.