Skip to content

Instantly share code, notes, and snippets.

View les-peters's full-sized avatar

Les Peters les-peters

View GitHub Profile
@les-peters
les-peters / 2021-12-27.py
Created December 27, 2021 15:27
Fireworks
question = """
You're in charge of the fireworks display, and you have a list of fireworks
to shoot off. You want to make sure you don't fire the same colors twice in a row.
Given an array of fireworks, return a valid firing order. You decide how you want an
impossible solution to work!
Example:
$ orderFireworks(['green','green','green','red','red','blue'])
$ ['green','red','green','red','green','blue']
@les-peters
les-peters / 2021-12-20.py
Last active December 21, 2021 23:54
White Elephant
question = """
Design a data structure and functions for a white elephant game.
You'll want to have a set of players and gifts they bring, and
the gifts they end up with in the end!
"""
import random
from pprint import pprint
@les-peters
les-peters / 2021-12-13.py
Created December 15, 2021 21:13
Christmas Tree
question = """
Given a file named merry-christmas.txt that has a single integer x in it,
write a script to generate a Christmas tree with asterisks (*) and output
it as happy-holidays.txt. The tree should have a height of x, and if
merry-christmas.txt is empty, the height should be 25 asterisks tall.
Example (you can be flexible with your output, but this might be helpful
for you as a starting point):
// merry-christmas.txt
@les-peters
les-peters / 2021-12-06.py
Last active December 7, 2021 22:50
Wrapping Gifts
question = """
You have to order wrapping paper for presents. Given the length, width,
and height of the boxes you need to wrap, return the number of square feet
(or whatever units you want) of wrapping paper you need to order.
Extra credit: allow for other shapes of presents and their dimensions!
Example:
$ wrap(2, 3, 4)
$ 52 square feet
@les-peters
les-peters / 2021-11-29.py
Created November 29, 2021 21:29
Telephone Texting
question = """
Given a string containing digits from 2-9, return all possible letter combinations
that the number could represent based on phone numbers/letters. For example,
2 could be a, b, or c, 3 could be d, e, or f, and so on.
Example:
$ phoneLetter('9')
$ ['w', 'x', 'y', 'z']
@les-peters
les-peters / 2021-11-22.py
Last active November 22, 2021 21:11
Anagram Grouping
question = """
Given an array of strings, group the anagrams together in separate arrays.
An anagram is a word or phrase formed by rearranging the letters of another
word or phrase, using all the original letters exactly once.
Example:
$ groupAnagrams(["eat","tea","ten","poop","net","ate"])
$ [["poop"],["net","ten"],["eat","tea","ate"]]
"""
@les-peters
les-peters / 2021-11-09.py
Created November 9, 2021 21:14
Local Peaks
question = """
Given an array of integers, return the index of each local peak in the array.
A “peak” element is an element that is greater than its neighbors.
$ localPeaks([1,2,3,1])
$ [2]
$ localPeaks([1,3,2,3,5,6,4])
$ [1, 5]
"""
@les-peters
les-peters / 2021-10-26.py
Created October 26, 2021 19:16
Wild Palindrome Hunt
question = """
Given a string s where some of the letters can be “wilds” (denoted by an underscore _),
find the longest palindrome possible from the letters of s in order, where the wilds
can be any character.
Example:
$ longestPalindrome('abcb_cbcbafg')
$ 'abcbccbcba'
@les-peters
les-peters / 2021-10-24.py
Created October 24, 2021 17:56
add without plus
def binOr(x, y):
if x == '0' and y == '0':
return 0
elif x == '1' and y == '1':
return 2
else:
return 1
a = 10
b = 20
bin_a = str(str(bin(a))[2::])[::-1]
question = """
Given an array of objects A, and an array of indexes B, reorder the objects in array A with the given indexes in array B.
Example:
let a = [C, D, E, F, G, H];
let b = [3, 0, 4, 1, 2, 5];
$ reorder(a, b) // a is now [D, F, G, C, E, H]
"""