Practice 10 Python coding interview problems. Filter by difficulty and pattern, solve exercises in the browser, and track progress locally. No account or Python installation is required.
easy · hashmap
Array · Hash Table
Amazon · Google · Meta
You are given a list of integers `nums` and an integer `target`. Find two different positions in the list whose values add up to `target`, and return their indices as a list `[i, j]`. There is exactly one pair that works, and you may not use the same position twice.
easy · stack
String · Stack
Amazon · Google · Microsoft
You are given a string `s` that contains only the characters `(`, `)`, `{`, `}`, `[`, `]`. Decide whether the string is valid: every opening bracket must be closed by the same type of bracket, and brackets must close in the correct order — the most recently opened bracket must be the first one closed. An empty string counts as valid.
easy · bit magic
Array · Bit Manipulation
Amazon · Apple
You are given a list of integers `nums` in which every value appears exactly twice, except for one value that appears exactly once. Find and return that single value.
medium · sliding window
String · Sliding Window · Hash Table
Amazon · Google · Microsoft
You are given a string `s`. Find the length of the longest substring (a contiguous block of characters) that contains no repeating character. Return that length as an integer.
medium · intervals
Array · Sorting · Intervals
Amazon · Google · Meta
You are given a list of intervals, where each interval is a pair [start, end]. Two intervals overlap if one starts before or at the point where the other ends. Merge every group of overlapping intervals into a single interval and return the merged intervals in order of increasing start.
medium · tree/graph
Array · Graph · Depth-First Search · Breadth-First Search
Amazon · Google · Meta
You are given a rectangular grid of characters, where '1' means land and '0' means water. An island is a group of '1's connected horizontally or vertically (not diagonally). Count how many islands there are and return that number.
medium · heap
Array · Hash Table · Heap
Amazon · Google · Meta
You are given a list of integers `nums` and an integer `k`. Return the `k` elements that appear most often in the list. Return them in order of decreasing frequency; when several elements have the same frequency, return the smaller elements first.
medium · binary search on answer
Array · Binary Search
Google · Amazon
Koko loves bananas. There are piles of bananas, where piles[i] is the number of bananas in pile i, and she has `h` hours before the guards return. Each hour she chooses one pile and eats up to `k` bananas from it (if the pile has fewer than k, she eats the whole pile and the hour still counts). Return the smallest integer speed `k` (bananas per hour) that lets her finish all the piles within `h` hours.
medium · design
Design · Hash Table · Linked List
Amazon · Google · Meta · Microsoft
Build a cache with a fixed capacity that supports two operations: get(key) returns the stored value, or -1 if the key is not present; put(key, value) stores the pair, updating the value if the key already exists. When the cache is full and a new key is added, the least recently used key (the one not read or written for the longest) is evicted. Reading or writing a key marks it as recently used. The cache is created with LRUCache(capacity).
hard · two pointers
Array · Two Pointers · Stack
Amazon · Google · Meta
You are given a list `height` where height[i] is the height of a wall at position i. After it rains, water collects in the dips between walls. At any position, the water level is limited by the tallest wall to its left and the tallest wall to its right. Compute the total number of units of water trapped.