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 / 2022-05-23.py
Created May 25, 2022 21:02
Start to End
question = """
Given an n x m matrix where all of the units are 0s except for an 1
for “start”, a 2 for “end”, and 3s for walls, find the shortest paths
that you can take to get from 1 to 2, while working around 3s.
Example:
let grid = [
[1,0,0],
@les-peters
les-peters / 2022-05-16.py
Created May 18, 2022 12:54
Maximized Arrays
question = """
Given two integer arrays of size n, return a new array of size n such that
n consists of only unique elements and the sum of all its elements is maximum.
Example:
let arr1 = [7, 4, 10, 0, 1]
let arr2 = [9, 7, 2, 3, 6]
@les-peters
les-peters / 2022-05-09.py
Created May 9, 2022 20:19
Who Owes Money
question = """
You went on a vacation with friends. Each of you paid for certain meals
on the trip for the group. Write a function that determines who owes
money to whom so that everyone pays equally.
Example:
let receipts = [
{ name: 'Ximena', paid: 45 },
@les-peters
les-peters / 2022-05-02.py
Created May 4, 2022 10:53
SimpleAutocomplete
question = """
Implement a simple version of autocomplete, where given an input string s and a
dictionary of words dict, return the word(s) in dict that partially match s
(or an empty string if nothing matches).
Example:
let dict = ['apple', 'banana', 'cranberry', 'strawberry']
@les-peters
les-peters / 2022-04-25,.py
Created April 25, 2022 20:23
Merged Intervals
question = """
Given an array of intervals, merge the overlapping intervals, and return an array of the resulting intervals.
Example:
$ mergeIntervals([[1,4],[2,6],[8,10],[15,20]])
$ [[1,6],[8,10],[15,20]]
$ mergeIntervals([[1,2],[2,7]])
@les-peters
les-peters / change-a-letter.py
Created April 25, 2022 16:29
Change One Letter in a Spell Name
from english_words import english_words_set
alphabet = []
for ch in range(0, 26):
alphabet.append(chr(97 + ch))
def change_a_letter(words):
letters = []
for letter in words.strip().lower():
letters.append(letter)
@les-peters
les-peters / 2022-04-17.py
Created April 23, 2022 16:53
Largest Subarray Sum
question = """
Given an unsorted array of integers and a number n, find the subarray of length n that has the largest sum.
Example:
$ largestSubarraySum([3,1,4,1,5,9,2,6], 3)
$ [9, 2, 6]
@les-peters
les-peters / 2022-04-11.py
Created April 11, 2022 11:30
Interior Angle Size
question = """
Given an integer n representing the number of sides of a regular polygon,
return the measure of each interior angle. Bonus points: implement some of
the other functions listed in the linked Wikipedia page!
Example:
$ interiorAngleSize(3)
$ 60 // Each angle in a triangle that is a regular polygon is 60 degrees
@les-peters
les-peters / 2022-04-04.py
Created April 5, 2022 21:09
Equal With Deletions
question = """
Given two strings n and m, return true if they are equal when both are entered into
text editors. But: a # means a backspace character (deleting backwards), and a % means
a delete character (deleting forwards).
Example:
> equalWithDeletions("a##x", "#a#x")
> true // both strings become "x"
@les-peters
les-peters / 2022-03-28.py
Created March 31, 2022 10:52
Contained Items
question = """
Given a string that represents items as asterisks (*) and compartment walls as pipes (|),
a start index, and an end index, return the number of items in a closed compartment.
Example:
let str = '|**|*|*'
> containedItems(str, 0, 5)