Add coding exercises for Facebook interviews
Add attempts at solving coding problems to Briefcase.
This commit is contained in:
parent
d2d772e43e
commit
aa66d9b83d
66 changed files with 2994 additions and 0 deletions
17
scratch/facebook/shuffle.py
Normal file
17
scratch/facebook/shuffle.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from random import randint
|
||||
|
||||
def get_random(i, j):
|
||||
return randint(i, j)
|
||||
|
||||
def shuffle(xs):
|
||||
for i in range(len(xs)):
|
||||
j = get_random(i, len(xs) - 1)
|
||||
xs[i], xs[j] = xs[j], xs[i]
|
||||
|
||||
xs = list(range(1, 53))
|
||||
print(xs)
|
||||
assert len(set(xs)) == 52
|
||||
shuffle(xs)
|
||||
assert len(set(xs)) == 52
|
||||
print(xs)
|
||||
print("Success!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue