Coding challenges in Python and JavaScript
Each challenge is a function you write and a set of tests it passes or fails. They are sorted by Big-O, from the most direct ones to what you get asked in an interview. Pick one, read the problem and solve it in your browser: there is nothing to install.
O(1) · Trivial
59 challenges · Free- Area of a rectangleoperations
- Celsius to Fahrenheitoperations · decimals
- Closest to the targetconditionals · comparisons · operations
- Coat or t-shirt?conditionals · strings · comparisons
- Did the fever go down?lists · indexes · booleans
- Did they pass the class?booleans · conditionals
- Digits the other way rounddigits · operations
- Do the two times overlap?conditionals · booleans · comparisons
- Does it fall in range?conditionals · booleans · comparisons
- Does the photo fit the envelope?lists · conditionals · booleans
- How far apartoperations · comparisons
- How far from free shippingoperations · conditionals
- How far off is it?conditionals · comparisons · operations
- How many blocks you walklists · indexes · operations
- How many days in the month?lists · conditionals
- Initialsstrings
- Is it a leap year?conditionals · booleans
- Is it even?operations · booleans
- Is it isosceles?lists · conditionals · booleans
- Is it the same text?strings · booleans
- Is the big bottle worth it?operations · booleans
- Last name firststrings
- Minutes to hoursoperations · strings
- Ribbon around the frameoperations
- Same letter at both ends?strings · booleans
- Swap the endsstrings · indexes
- The area of the plateoperations · decimals
- The average without the worstlists · indexes · decimals
- The bill with the tipoperations · decimals
- The boxes you needoperations · division
- The candy left in the bagoperations · division
- The cards I getoperations · division · conditionals
- The date written outlists · indexes · strings
- The eggs that shipoperations · division
- The final gradeoperations · decimals
- The first and last stoplists · indexes · strings
- The hypotenuseoperations · decimals
- The larger of twoconditionals
- The last characterstrings
- The last digitoperations · digits
- The last fourstrings · indexes
- The letter gradeconditionals · strings · comparisons
- The letters left overstrings · operations
- The middle letterstrings · indexes
- The name, written rightstrings
- The nearest tenoperations · division
- The percentage you got rightoperations · division · decimals
- The seats still freeoperations · division
- The shortened textstrings · conditionals
- The sign of a numberconditionals · comparisons
- The song in secondsstrings · operations
- The tax already in the priceoperations · decimals
- The tiles that fitoperations · division
- The twelve-hour clockconditionals · strings
- The usernamestrings
- Three for the price of twooperations · division
- What the host paysoperations · division
- What time will it be?operations · division
- What you need on the last examoperations
O(log n) · Easy
24 challenges · Free- A power of 2?loops · operations · booleans
- Binary searchlists · search · loops
- Count the digitsloops · operations
- Digits to number the pagesdigits · operations · loops
- Split the thousandsstrings · digits · loops
- The ad with no pairlists · search · indexes
- The beacons that are missinglists · search · indexes
- The catches of the same weightlists · search · indexes
- The first broken buildlists · search · booleans
- The gates of the canaldictionaries · search · lists
- The growing colonydivision · loops
- The key of the daydigits · comparisons · loops
- The lighthouse in binarydivision · strings
- The lockers in usedivision · digits · loops
- The lucky ticketdigits · booleans · loops
- The mailbags that pile upoperations · search · loops
- The nearest stoplists · search · comparisons
- The one-digit oracledigits · loops
- The section a page belongs tolists · search · indexes
- The square plotsdivision · search · operations
- The supply shipsdivision · search · loops
- The top of the ridgelists · search · comparisons
- The turn in the tapelists · search · comparisons
- Tournament roundsdivision · loops
O(n) · Medium
77 challenges · Full plan- A steady beatlists · loops · booleans
- Add up the evensloops · lists
- Are they balanced?strings · lists · loops · booleans
- Atoms in the formulastrings · loops
- Compress the textstrings · loops
- Connecting flightsstrings · lists · booleans
- Count the vowelsstrings · loops
- Count the wordsstrings · loops
- Crossed alibislists · indexes · comparisons
- Even numbers in even placeslists · loops · indexes
- File namesstrings · conditionals · loops
- From binary to a numberstrings · loops
- Full barslists · loops · booleans
- Game to elevenstrings · loops · conditionals
- High tideslists · indexes · comparisons
- Hit combostrings · loops
- How many linesstrings · loops · conditionals
- How many servingslists · division · loops
- Initials of a phrasestrings · lists
- Interleaved orderslists · indexes · loops
- Is it a palindrome?strings · loops · booleans
- Is it a pangram?strings · loops · booleans
- Is the ISBN valid?strings · loops · booleans
- Jumping across platformslists · booleans · loops
- Lead changesstrings · loops · conditionals
- Level by experiencelists · loops · conditionals
- Pendulum crossingslists · loops · comparisons
- Reverse the textstrings · loops
- Roman numeralsstrings · indexes · comparisons
- Rum for the voyagelists · loops
- Spices between portslists · loops · comparisons
- Square root by handloops · operations · search
- Stock at closing timedictionaries · lists · loops
- Sum of multiplesloops · lists · division
- The balanced potionlists · loops · indexes
- The book club rounddictionaries · loops
- The burnt cookieslists · loops
- The busiest pair of cornersdictionaries · lists · comparisons
- The butcher's tallystrings · regular expressions · operations
- The cart totallists · loops
- The diver's logstrings · loops
- The divisor that fits them alllists · loops · operations
- The doubled wordstrings · loops
- The echo spellstrings · digits · loops
- The fake doubloonlists · indexes · loops
- The fastest kilometerlists · loops · indexes
- The favorite facelists · loops · indexes
- The fewest transfersdictionaries · sets · loops
- The health barlists · loops · conditionals
- The hidden runestrings · booleans · loops
- The itinerary in the ticketsdictionaries · sets · lists
- The keyboard with backspacestrings · loops · indexes
- The largest in the listlists · loops
- The launch windowlists · loops · indexes
- The list averagelists · loops · decimals
- The longest wordstrings · lists · loops
- The mirror cipherstrings · loops
- The missing bandlists · operations
- The most typical satellitelists · indexes · comparisons
- The recipe's timestrings · division · loops
- The rover heading homestrings · loops
- The sailboat's headinglists · loops · conditionals
- The scrambled messagestrings · sorting · lists
- The shape of the melodylists · strings · comparisons
- The shelf that settlesgrids · strings · indexes
- The strong passwordstrings · booleans · loops
- The strongest signallists · loops · indexes
- The stuck sensorlists · loops
- The tiered tributelists · loops · decimals
- The torn-out table of contentsstrings · regular expressions · lists
- The twin keysstrings · loops · indexes
- The unclosed doorsstrings · loops
- The vault combinationlists · loops · booleans
- The winning numberdictionaries · lists · loops
- The wizards' duellists · loops · comparisons
- Two half mapsstrings · conditionals · loops
- Wave setslists · loops · conditionals
O(n log n) · Hard
45 challenges · Full plan- Are they consecutive?lists · sorting · booleans
- As many shows as you canlists · strings · sorting
- Beach umbrellaslists · sorting · comparisons
- Is it an isogram?strings · sorting · booleans
- Numbers that arrived as textlists · sorting · strings
- Portions for the dinerslists · sorting · loops
- Probes before the deadlinelists · sorting · booleans
- Routes with no repeatslists · sorting · loops
- Sold only oncelists · sorting · loops
- Sort by lengthlists · sorting · strings
- Sort the lettersstrings · sorting · lists
- The alternating choirlists · sorting · indexes
- The anagrams of a wordstrings · lists · sorting
- The busiest bandsorting · lists · indexes
- The cars that stay putlists · sorting · division
- The cheapest billsorting · lists · indexes
- The flipping spellssorting · lists · conditionals
- The galleon's holdstrings · sorting · loops
- The game shopsorting · loops · comparisons
- The height of the sawlists · search · comparisons
- The hives kept apartlists · sorting · search
- The jersey numberslists · sorting · loops
- The kindergarten potsdictionaries · sorting · indexes
- The largest numberlists · sorting · digits
- The lifeboatslists · sorting · comparisons
- The longest straightlists · sorting · loops
- The medianlists · sorting · decimals
- The most voted and the least votedlists · sorting · loops
- The price you cannot paysorting · loops
- The primes up to nlists · loops · operations
- The researcher's scorelists · sorting · comparisons
- The sacks before the rainlists · search · division
- The same coins?lists · sorting · booleans
- The shortest gapstrings · sorting · division
- The smallest differencelists · sorting · loops
- The station platformslists · sorting · loops
- The temple beamslists · sorting · comparisons
- The three crystalslists · sorting · operations
- The top three scoreslists · sorting · loops
- The torches on the walllists · sorting · decimals
- The trough that never runs drylists · search · loops
- The watched hoursstrings · lists · sorting
- The witnesses' clockslists · sorting · comparisons
- What every supplier carriessets · lists · sorting
- Who waits the leastlists · sorting · loops
O(n²) · Very hard
58 challenges · Full plan- A day that works for bothlists · loops · booleans
- Candy at summer camplists · loops · comparisons
- Chain of gemsstrings · loops · indexes
- Days until warmerlists · loops · indexes
- Don Chuy's pancakesloops · lists · indexes
- In a row, in orderlists · loops · booleans
- Pairs out of orderlists · loops
- Pairs that add uplists · loops
- Pairs that are k apartlists · loops
- Power for liftofflists · loops
- Rain between the rockslists · loops · comparisons
- Roles that never meetsets · lists · sorting
- Samples in the capsulescomparisons · loops · lists
- Starts and ends the samestrings · loops
- The antennas that see each othercomparisons · loops · lists
- The best run of the seasonlists · loops
- The birthday cluesloops · lists · indexes
- The buses that went bylists · comparisons · conditionals
- The cartographer's tableconditionals · loops · lists
- The change at the registerlists · loops · indexes
- The closest strainsstrings · lists · loops
- The coach's shoutsloops · lists · strings
- The coded telegrambooleans · loops · strings
- The colliding particleslists · loops · comparisons
- The color codelists · loops · conditionals
- The fence on the streetcomparisons · loops · lists
- The first one that never repeatsstrings · loops
- The game of tic-tac-toegrids · conditionals · loops
- The golem clashlists · loops · comparisons
- The khan's horsescomparisons · loops · lists
- The lamplighter's roundcomparisons · loops · lists
- The last one in the circlelists · loops · division
- The loneliest seatstrings · indexes · comparisons
- The longest climblists · loops
- The magician's shufflelists · indexes · loops
- The oasis caravandivision · loops · lists
- The palindrome inscriptionstrings · loops · indexes
- The penguin lineconditionals · loops · lists
- The puddles in the yardgrids · recursion · loops
- The pyramid of glassesdecimals · loops · lists
- The ring lockstrings · loops · indexes
- The routes past the roadworksrecursion · grids · dictionaries
- The sail between two mastslists · loops · comparisons
- The signal that comes backlists · indexes · loops
- The snail's shellstrings · loops · indexes
- The sphinx's digitsdigits · strings · indexes
- The Talavera borderstrings · loops · indexes
- The terracotta rowlists · loops · indexes
- The theme comes backlists · loops · indexes
- The three sackslists · sorting · loops
- The tiles on the rackloops · lists · strings
- The tournament joustscomparisons · loops · lists
- The tune with no repeated notesstrings · loops
- The twelve-knot ropeloops · operations · lists
- The twin codicesloops · strings · indexes
- The warriors of Cadmuslists · loops · comparisons
- The wasp nests in the nurserygrids · strings · loops
- Yang Hui's triangleoperations · loops · lists
O(2ⁿ) · Legendary
25 challenges · Full plan- A fully covered night shiftrecursion · lists · strings
- Ariadne's threadrecursion · lists · loops
- Clash-free rhythmsrecursion · strings · lists
- Grandma's game piecerecursion · lists · indexes
- Grandpa's spoonsrecursion · lists · indexes
- Lilavati's sumsrecursion · strings · indexes
- Mansa Musa's bags of goldrecursion · lists · indexes
- Modules on rocketsrecursion · lists · booleans · division
- Monday's operating roomsrecursion · lists · comparisons
- Spelling with elementsrecursion · strings · indexes
- Splitting the honeyrecursion · lists · comparisons
- The block partyrecursion · lists · loops
- The board cutsrecursion · lists · dictionaries
- The capsule's cargo holdrecursion · lists · comparisons
- The Hansa votesrecursion · lists · comparisons
- The hidden motifrecursion · strings · indexes
- The houses of Xibalbarecursion · lists · loops
- The lab switchesrecursion · lists
- The morning batchesrecursion · lists · dictionaries
- The necklace both threads sharerecursion · strings · indexes
- The Pompeii graffitorecursion · strings · indexes
- The rowers of Puntrecursion · lists · comparisons
- The satellite's counterweightsrecursion · lists · operations
- The subway routesrecursion · lists · loops
- The two-pan balancerecursion · lists · operations