Just [[currentUser.getNumFreeQuestionsLeft()]] No more free questions left!Upgrade Now
I figured out how to get rich: online poker.
I suspect the online poker game I'm playing shuffles cards by doing a single "riffle."
To prove this, let's write a function to tell us if a full deck of cards shuffledDeck is a single riffle of two other halves half1 and half2.
We'll represent a stack of cards as an array of integers in the range 1..52 (since there are 52 distinct cards in a deck).
Why do I care? A single riffle is not a completely random shuffle. If I'm right, I can make more informed bets and get rich and finally prove to my ex that I am not a "loser with an unhealthy cake obsession" (even though it's too late now because she let me go and she's never getting me back).
Watch out for index out of bounds errors! Will your function ever try to grab the 0th item from an empty array, or the nth item from an array with n elements (where the last index would be n-1)?
We can do this in time and additional space.
Did you come up with a recursive solution? Keep in mind that you may be incurring a hidden space cost (probably ) in the call stack! You can avoid this using an iterative approach.
time and additional space.
Becky if you're reading this I didn't really mean what I said in the problem statement. It's just that things have been hard lately and anyway if you'll just give me another chance I promise it won't be like last time. I'm a wreck without you. Like a collapsed soufflé. Please Becky.
If you read the whole breakdown section, you might have noticed that we started with a recursive function that looked simple but turned out to cost time and space because each recursive step created its own new "slice" of the input array. If you missed that part, go back and take a look.
Be careful of the hidden time and space costs of array slicing! Consider tracking array indices "by hand" instead (as we do in our final solution).