Note that there are some explanatory texts on larger screens.

plurals
  1. POshuffle card deck issues in language agnostic
    text
    copied!<p>Not so long ago I was in an interview, that required solving two very interesting problems. I'm curious how would you approach the solutions.</p> <p>Problem 1 :</p> <p><strong>Product of everything except current</strong> </p> <p>Write a function that takes as input two integer arrays of length len, input and index, and generates a third array, result, such that: result[i] = product of everything in input except input[index[i]]</p> <p>For instance, if the function is called with len=4, input={2,3,4,5}, and index={1,3,2,0}, then result will be set to {40,24,30,60}.</p> <p>IMPORTANT: Your algorithm must run in linear time.</p> <p>Problem 2 : ( the topic was in one of Jeff posts )</p> <p><strong>Shuffle card deck evenly</strong></p> <ol> <li><p>Design (either in C++ or in C#) a class Deck to represent an ordered deck of cards, where a deck contains 52 cards, divided in 13 ranks (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K) of the four suits: spades (?), hearts (?), diamonds (?) and clubs (?).</p></li> <li><p>Based on this class, devise and implement an efficient algorithm to shuffle a deck of cards. The cards must be evenly shuffled, that is, every card in the original deck must have the same probability to end up in any possible position in the shuffled deck. The algorithm should be implemented in a method shuffle() of the class Deck: void shuffle()</p></li> <li><p>What is the complexity of your algorithm (as a function of the number n of cards in the deck)?</p></li> <li><p>Explain how you would test that the cards are evenly shuffled by your method (black box testing).</p></li> </ol> <p>P.S. I had two hours to code the solutions</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload