Skip to content

Instantly share code, notes, and snippets.

View arkadyark's full-sized avatar

Arkady Arkhangorodsky arkadyark

  • Zoom
  • New York City
View GitHub Profile
@arkadyark
arkadyark / 2020_11_04.rs
Created November 4, 2020 05:39
cassidoo_problem_2020_11_04
/*
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
*/
'''
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.
'''
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
@arkadyark
arkadyark / cassidoo_problem_08302020.py
Created September 2, 2020 06:57
Stock date problem from Cassidoo newsletter
'''
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 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
@arkadyark
arkadyark / oneRow.py
Created May 4, 2020 18:03
My solution for Cassidy Williams' weekly interview problem for the week of May 4, 2020
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]:
@arkadyark
arkadyark / missing_ints.py
Created October 28, 2019 05:48
Missing Integers interview question
'''
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
'''