This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You have a character who jumps forward n number of units at a time, and an array representing the road in front of them (where 0 is a flat piece of road, and 1 is an obstacle). Return true or false if your character can jump to the end without hitting an obstacle in front of them. | |
Trying it out in rust this time! | |
Example: | |
character_jump(3, [0,1,0,0,0,1,0]) -> true | |
character_jump(3, [0,1,0,1,0,1,0]) -> false | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Given an array of integers representing asteroids in a row, for each asteroid, the absolute value represents its size, and the sign represents its direction (positive = right, negative = left). | |
Return the state of the asteroids after all collisions (assuming they are moving at the same speed). | |
If two asteroids meet, the smaller one will explode. | |
When they are the same size, they both explode. Asteroids moving in the same direction will never meet. | |
Example: | |
$ asteroids([5, 8, -5]) -> [5, 8] // The 8 and -5 collide, 8 wins. The 5 and 8 never collide. | |
$ asteroids([10, -10]) -> [] // The 10 and -10 collide and they both explode. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Given an array of increasing integers, find the length of the longest fibonacci-like subsequence of the array. If one does not exist, return 0. A sequence is “fibonacci-like” if X_i + X_{i+1} = X_{i+2}. | |
''' | |
def fibonacci_like(a): | |
''' | |
solution: O(n^3-ish) | |
me: 🤡 | |
''' | |
max_fib_len = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This week’s question: | |
Given an array of numbers that represent stock prices (where each number is the price for a certain day), find 2 days when you should buy and sell your stock for the highest profit. | |
Example: | |
$ stockBuySell([110, 180, 260, 40, 310, 535, 695]) | |
$ “buy on day 4, sell on day 7” | |
''' | |
def stockBuySell(prices): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This week’s question: | |
# Given an array of random integers, move all the zeros in the array to the end of the array. Try to keep this in O(n) time (or better)! | |
# Example: | |
# $ moveZeros([1, 2, 0, 1, 0, 0, 3, 6]) | |
# $ [1, 2, 1, 3, 6, 0, 0, 0] | |
def _get_end_pointer(l, end_pointer=-1): | |
while l[end_pointer] == 0 and -end_pointer < len(l): | |
end_pointer -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KEYBOARD_ROWS = { | |
'qwerty': (tuple('qwertyuiop'), tuple('asdfghjkl'), tuple('zxcvbnm')), | |
'dvorak': (tuple('pyfgcrl'), tuple('aoeuidhtns'), tuple('qjkxbmwvz')), | |
'colemak': (tuple('qwfpgjluy'), tuple('arstdhneio'), tuple('zxcvbkm')), | |
} | |
LETTERS_TO_ROWS = {} | |
for keyboard in KEYBOARD_ROWS: | |
LETTERS_TO_ROWS[keyboard] = {} | |
for row in KEYBOARD_ROWS[keyboard]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Given a list of ordered integers with some of the numbers missing (and with possible duplicates), find the missing numbers. | |
Example: | |
> missingInts([1, 3, 3, 3, 5, 6]) | |
> 2, 4 | |
> missingInts([1, 2, 3, 4, 4, 7, 7]) | |
> 5, 6 | |
''' |