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-10-11.py
Created October 11, 2021 17:49
Odious test
question = """An “odious number” is a non-negative number that has an odd number of 1s
in its binary expansion. Write a function that returns true if a given number is odious.
Example:
$ isOdious(14)
$ true
$ isOdious(5)
$ false
@les-peters
les-peters / 2021-10-04.py
Created October 6, 2021 20:27
distinct combos
question = """
Given an integer array, find all distinct combinations of a given length x (with repetition allowed).
Example:
$ distinctCombos([1,1,2], 2)
$ [1, 1], [1, 2], [2, 2]
$ distinctCombos([1,2,3,4], 2)
$ [1, 1], [1, 2], [1, 3], [1, 4], [2, 2], [2, 3], [2, 4], [3, 3], [3, 4], [4, 4]
@les-peters
les-peters / 2021-09-20.py
Created September 20, 2021 19:41
Parse HTML
question = """
Given a string of HTML, detect and print all the HTML tags, attributes and values of attributes.
Example:
$ parseHTML(`<p><img src="https://i.imgur.com/LSG9xg3.jpeg" /></p>`)
$ [{ tag: 'p' }, { tag: 'img', attributes: [{'src': 'https://i.imgur.com/LSG9xg3.jpeg'}] }]
"""
@les-peters
les-peters / 2021-09-13.py
Created September 13, 2021 19:20
Parentheses Pairs
question = """
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Example:
$ formParens(1)
$ ["()"]
$ formParens(3)
$ ["((()))","(()())","(())()","()(())","()()()"]
@les-peters
les-peters / 2021-09-06.py
Created September 9, 2021 12:15
String Multiply 2.0
question = """
Given two non-negative integers n1 and n2 represented as strings,
return the product of n1 and n2, also represented as a string.
Twist: You can’t use any built-in language integer libraries nor
convert the inputs to integers directly.
Example:
$ stringProduct("123", "456")
$ "56088"
@les-peters
les-peters / 2021-08-30.py
Created August 30, 2021 15:45
Shortest Common Prefix
question = """
Write a function to find the longest common prefix string in an array of strings.
Example:
$ longestPrefix(["cranberry","crawfish","crap"])
$ "cra"
$ longestPrefix(["parrot", "poodle", "fish"])
@les-peters
les-peters / 2021-08-23.py
Created August 25, 2021 19:30
Popular Repos
question = """
You need to get the top 5 GitHub OSS code repositories that make use of the
navigator.sendBeacon Web API. How would you go about it?
"""
import requests
import re
url = 'https://github.com/miguelmota/Navigator.sendBeacon/network/dependents'
@les-peters
les-peters / 2021-08-16.py
Created August 17, 2021 11:50
Palindrome Hunt
question= """
Given a string s, return the longest palindromic substring in s.
Example:
$ pSubstring('babad')
$ 'bab' // or 'aba'
"""
@les-peters
les-peters / 2021-08-09.py
Last active August 11, 2021 21:08
Minesweeper
question = """Given a grid size, and a set of mines (in pairs of rows and columns),
generate the Minesweeper grid for that set of mines. You can use asterisks for mines,
and an x for 0!
Example:
let gridSize = 5
let mines = [[1, 3], [3, 5], [2, 4]]
$ generateMinesweeper(gridSize, mines)
@les-peters
les-peters / 2021-07-26.py
Created July 28, 2021 22:21
Factorial Zeros
question = """
Given a positive integer n, write a function that finds
the number of zeros at the end of n! in base 10.
Example:
$ zerosEndingFactorial(1)
$ 0