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-03-21.py
Created March 22, 2022 13:43
Smallest Time Interval
question = """
Given a list of times in a 24-hour period, return the smallest interval between two
times in the list. Hint: you can do this in O(n) time!
Example:
$ smallestTimeInterval(['01:00', '08:15', '11:30', '13:45', '14:10', '20:05'])
$ '25 minutes'
@les-peters
les-peters / 2022-03-07.py
Created March 8, 2022 14:01
Hashes without Hash, integer edition
import os.path
from os import path
import csv
question = """
Implement a hashmap from scratch without any existing libraries in your preferred language.
A hashmap should:
@les-peters
les-peters / 2022-02-28.py
Created March 3, 2022 21:27
Rectangle Measurement
question = """
Given a 2D array of 0s and 1s, return the size of the largest rectangle of 1s in the array.
Example:
let islands = [
0,0,0,1,0
1,1,0,0,1
1,1,0,0,0
@les-peters
les-peters / 2022-02-21.py
Created February 21, 2022 14:40
Longest Sequential Subarray
question = """
Given an array of integers, find the length of the longest sub-sequence such that elements
in the sub-sequence are consecutive integers, the consecutive numbers can be in any order.
Example:
$ longestSubSeq([1, 9, 87, 3, 10, 4, 20, 2, 45])
$ 4 // 1, 3, 4, 2
@les-peters
les-peters / 2022-02-14.py
Created February 14, 2022 21:18
Remote Control
question = """
Given a QWERTY keyboard grid and a remote control with arrows and a “select” button, write a
function that returns the buttons you have to press to type a certain word. The cursor will always
start in the upper left at the letter Q.
Example:
$ remoteControl('car')
$ 'down, down, right, right, select, left, left, up, select, up, right, right, right, select'
@les-peters
les-peters / 2022-02-07.py
Created February 12, 2022 23:16
Word Search
question = """
Implement a word search. Given a 2D array of letters and a word to find,
return the 2D array with the found word's letters replaced with an asterisk (*).
Example:
let grid = [['a','a','q','t'],
['x','c','w','e'],
['r','l','e','p']]
@les-peters
les-peters / 2022-01-31.py
Created February 3, 2022 01:58
Localtime
question = """
Given an array of people and their timezones in UTC, write a function to return the local
time for a given person. Extra credit: add options for a 12 or 24 hour clock!
Example:
let humans = [
{ name: 'Clara', timezone: 'UTC−4:00' },
{ name: 'Cami', timezone: 'UTC−7:00' }
{ name: 'Ximena', timezone: 'UTC−5:00' }
@les-peters
les-peters / 2022-01-25.py
Created January 26, 2022 21:57
Palindrome file search
question = """
You are given three files named first_page.txt, second_page.txt, and third_page.txt
with the occurrence of at least one palindrome in each of them. Write a script to find the following:
The exact number of palindromes in each file.
The line numbers of the palindromes in each file.
"""
import re
question = """
Using the rules of Wordle, given a guessWord and a solutionWord,
return a set of emojis returned from the guessWord.
Example:
let solutionWord = "fudge"
$ wordleGuess("reads", solutionWord)
@les-peters
les-peters / 2022-01-10.py
Created January 11, 2022 21:25
Permutations
question = """
Given a string s, you can transform every letter individually to be lowercase or
uppercase. Return a list of all possible permutations you could create from s.
Example:
$ capPermutations("ab2")
$ ["ab2","aB2","Ab2","AB2"]
$ capPermutations("35p")