All puzzles › Computer Science
Computer Science Practice Problems
32 puzzles (9 easy, 15 medium, 8 hard), 10 free, in Python, JavaScript and C++.
Ciphers, sorting, binary and other CS building blocks.
The puzzles, easiest first
- Store the Surprise, Not the Time (Easy, free): A monitoring system records a reading every ten seconds, so its timestamps are large numbers that are almost perfectly predictable.
- Binary to Decimal (Easy): Given an array of bits, return the number it represents.
- Caesar Cipher (Easy): Given a lowercase string and a number k, shift every letter forward k places in the alphabet, wrapping from z back to a.
- Count Set Bits (Easy): Given a number, return how many 1 bits it has in binary.
- Count Vowels (Easy): Given a string, return how many vowels it has (a, e, i, o, u).
- Decimal to Binary (Easy): Given a number that's 0 or more, return its binary digits as an array.
- Hex to Decimal (Easy): Given a hex string using 0-9 and a-f, return its decimal value.
- Linear Search (Easy): Given an array and a target, return the index of the first match, or -1 if it isn't there.
- Reverse a String (Easy): Given a string, return it backwards.
- Copy From What You Already Wrote (Medium, free): LZ77, the idea inside nearly every compressor, replaces repeated data with a pointer backward: go back this far and copy this many.
- Counting Without a Slot per Item (Medium, free): To count how often each item appears in a huge stream, a hash map needs an entry per item.
- Cut Where the Data Says (Medium, free): A backup tool splits files into chunks and stores each distinct chunk once.
- Shuffle It So It Compresses (Medium, free): The Burrows-Wheeler transform rearranges a string so that equal letters end up side by side, which makes it far easier to compress, and the rearrangement can be undone exactly.
- Similar Sets, Tiny Fingerprints (Medium, free): Comparing two huge sets item by item is slow.
- Whoever Is Left Standing (Medium, free): You want the items that make up more than one k-th of an endless stream, and there is no room to count everything.
- Bubble Sort (Medium): Given an array of numbers, sort it with bubble sort.
- FizzBuzz (Medium): Given n, return the numbers 1 to n as strings, but use "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of both.
- Hamming Distance (Medium): Given two bit arrays of the same length, return how many positions differ.
- Insertion Sort (Medium): Given an array, sort it with insertion sort, the way you'd sort cards in your hand.
- Isomorphic Strings (Medium): Given two strings, return true if you can turn one into the other by swapping each letter for another letter, the same way every time.
- Kth Largest Element (Medium): Given an array and k, return the kth largest value, where k = 1 means the biggest.
- Reverse Bits (Byte) (Medium): Given a number from 0 to 255, reverse the order of its 8 bits and return the result.
- Run-Length Encoding (Medium): Given a string, compress it by writing each run of repeated letters as the letter followed by how many times it repeats.
- Selection Sort (Medium): Given an array, sort it with selection sort.
- A Running Total You Can Edit (Hard, free): A table of running totals answers any range sum at once, but changing one number means rebuilding it.
- Count by the Longest Run of Zeros (Hard, free): HyperLogLog counts distinct items using a few bytes, by noticing how rare a hash that starts with many zeros is.
- Kick Out the Occupant (Hard, free): Cuckoo hashing gives every key two homes, one in each of two tables, so a lookup checks two slots and is done.
- Longest Common Prefix (Hard): Given a list of strings, return the longest prefix they all share, or "" if they share none.
- Longest Increasing Subsequence (Hard): Given an array, return the length of the longest strictly increasing subsequence.
- Merge Sort (Hard): Given an array, sort it with merge sort.
- Search Rotated Array (Hard): Given a sorted array that's been rotated at some unknown point, like [4, 5, 6, 7, 0, 1, 2], return the index of the target, or -1.
- Word Break (Hard): Given a string and a list of dictionary words, return true if the string can be split completely into dictionary words.
Practice another pattern
Or browse by subject
Browse all 676 puzzles