diff options
author | William Carroll <wpcarro@gmail.com> | 2020-11-12T14·37+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-11-12T14·37+0000 |
commit | aa66d9b83d5793bdbb7fe28368e0642f7c3dceac (patch) | |
tree | a0e6ad240fe1cdfd2fcdba7266931beea9fbe0d6 /scratch/facebook/cafe-order-checker.py | |
parent | d2d772e43e0d4fb1bfaaa58d7de0c9e2cc274a25 (diff) |
Add coding exercises for Facebook interviews
Add attempts at solving coding problems to Briefcase.
Diffstat (limited to 'scratch/facebook/cafe-order-checker.py')
-rw-r--r-- | scratch/facebook/cafe-order-checker.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scratch/facebook/cafe-order-checker.py b/scratch/facebook/cafe-order-checker.py new file mode 100644 index 000000000000..9d88a68069fd --- /dev/null +++ b/scratch/facebook/cafe-order-checker.py @@ -0,0 +1,19 @@ +def orders_are_sorted(take_out, dine_in, audit): + if len(take_out) + len(dine_in) != len(audit): + return False + + i, j = 0, 0 + for x in audit: + if i < len(take_out) and take_out[i] == x: + i += 1 + elif j < len(dine_in) and dine_in[j] == x: + j += 1 + else: + return False + return True + + +assert orders_are_sorted([1,3,5], [2,4,6], [1,2,4,3,6,5]) +assert not orders_are_sorted([1,3,5], [2,4,6], [1,2,4,5,6,3]) +assert orders_are_sorted([], [2,4,6], [2,4,6]) +print("Success!") |