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
# Write a function that when given a positive integer n and a digit d (which is not 0), | |
# outputs a way to represent n using only addition, subtraction, multiplication, | |
# exponentiation, division, concatenation, parenthesis and the digit d. | |
# Example: | |
# n = 6, d = 1 => 1 + 1 + 1 + 1 + 1 + 1 | |
# n = 10, d = 1 => 1 | 1 - 1 | |
# n = 12, d = 1 => 1 | (1 + 1) | |
# n = 64, d = 2 => 2 ^ (2 + 2 + 2) | |
# n = 1, d = 9 => 9 / 9 |
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 unsorted integers, return the mean, median, and mode. | |
import math | |
from functools import reduce | |
def mean_median_mode(N): | |
print('given', N) | |
SN = sorted(N) | |
mean = 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
def moveZeros(a): | |
a = [1, 2, 0, 1, 0, 0, 3, 6] | |
b = [] | |
c = [] | |
for i in a: | |
if i: | |
b.append(i) | |
else: | |
c.append(i) |
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
import math | |
def gimmePizza(consumers, slices_per_pizza): | |
slices_to_consume = 0 | |
for consumer in consumers: | |
slices_to_consume += consumer['num'] | |
pizzas = math.ceil((slices_to_consume / slices_per_pizza)) | |
return pizzas | |
def pickyEaters(consumers, slices_per_pizza): |
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
question = """ | |
Given an array that was once sorted in ascending order is rotated at some | |
pivot unknown to you beforehand (so [0,2,4,7,9] might become [7,9,0,2,4], for | |
example). Find the minimum value in that array in O(n) or less. | |
""" | |
def find_pivot_point(a): | |
start = 0 | |
end = len(a) - 1 | |
mid = int((start + end) / 2) |
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
import re | |
question = """ | |
Given a basic Lisp-like string expression, parse it (where the available | |
functions are add, subtract, multiply, and divide, and they all take in 2 values). | |
""" | |
def babyLisp(str): | |
ops = { | |
'add': '+', |
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
import re | |
arr = [0,1,2,3,4,5,6,7,8] | |
arr.sort(key=lambda x: len(re.sub(r'0','', "{0:b}".format(x)))) | |
print(arr) |
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
from functools import reduce | |
def characterJump(jump_length, road): | |
return True if reduce((lambda x, y: x + y), list(map(lambda x: road[x], list(filter(lambda x: x % jump_length == 0, range(0, len(road))))))) == 0 else False | |
print(characterJump(3, [0,1,0,0,0,1,0])) | |
print(characterJump(4, [0,1,1,0,1,0,0,0,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
import re | |
question = """ | |
Given a positive integer n, write a function that returns true if | |
it is a perfect square and false otherwise. Don’t use any built-in | |
math functions like sqrt. Hint: Use binary search! | |
Examples: | |
$ perfectSquare(25) |
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
import re | |
from itertools import cycle, islice | |
question = """ | |
Given two non-negative integers n1 and n2 represented as strings, | |
return the product of n1 and n2, also represented as a string. | |
Neither input will start with 0, and don’t just convert it to an | |
integer and do the math that way. |