Coding & Algorithms Interview Questions
Practice the exact questions companies are asking right now.
Implement an in-memory database with TTL and backup
In-Memory Database (Levels 1–4: TTL and Backup/Restore) Implement an in-memory database that stores records identified by a string key. Each record co...
Implement an in-memory file system
Implement an in-memory file system supporting basic directory and file operations. You must support the following methods (names are illustrative; any...
Implement an in-memory SQL-like table
Problem Implement a simple in-memory database for one table. All values are strings. Each row is identified by a rowKey (string). Each row contains co...
Implement credit ledger with out-of-order timestamps
Problem You are implementing a GPU credit ledger that supports adding credits, charging credits, and querying balances. Requests can arrive in any tim...
Find path in implicit Fibonacci tree
You are given a special family of binary trees called Fibonacci trees. The k‑th order Fibonacci tree T(k) is defined recursively: - T(1) is a single n...
Validate a JSON-like string
Problem You are given a string s that is intended to be a JSON text. Implement a function isValidJsonStructure(s) -> bool that checks structural valid...
Implement toy-language types and generic substitution
Problem: Toy Language Type System (Printing + Generic Resolution) You are implementing a small type system for a custom “Toy Language”. Types can be: ...
Implement streaming RLE and bit-packed codec
You are implementing a simple compression scheme for sequences of 32‑bit signed integers. The codec should support two encoding strategies: 1. Run‑Len...
Find median of merged RLE arrays
Problem You are given two run-length encoded (RLE) arrays A and B. Each is sorted by value in non-decreasing order. - Each element is a pair (value, f...
Determine earliest collision among moving cars
You are given n cars moving over time. Each car has known initial state at time \(t=0\): - 1D case (straight road): - initial position \(x_i\) (mete...
Compute courier pay and implement load balancing
Problem 1: Compute courier (delivery driver) pay You are given a sequence of delivery-related events for a courier during a day. Your task is to compu...
Design KV store with sliding-window average QPS
Problem Design an in-memory key–value store that supports mutation operations and can report the average QPS (queries per second) over a recent time w...
Simulate turn-based monster team battle
Design an object-oriented model and implement the core battle logic for a turn-based fight between two teams of monsters. The system should simulate t...
Calculate transaction fees from CSV records
You are given a CSV-like multi-line string representing transactions with columns: id,reference,amount,currency,date,merchant_id,buyer_country,transac...
Implement a persistent sharded key-value store
Problem Implement a simple key–value store that persists data on disk. You must store the data in fixed-size shards, where each shard is saved in one ...
Optimize flight and cargo bookings for profit
OptiCargo: make the booking algorithm profitable You are given two streams/lists: - Flights you may attempt to book. Each flight has: - flight_id ...
Compute time to infect all cells
You are given an n × m grid representing people in a city. - Each cell is either infected (1) or healthy (0). - Two cells are neighbors if they share ...
Maximize non-adjacent sum on an N-ary tree
You are given an N-ary tree (each node may have 0..k children). Each node contains an integer value (can be 0 or positive). You want to select a set o...
Answer ancestor-walk queries on a rooted tree
Problem (Tree / Parent Array Queries) You are given a rooted tree with n nodes labeled 1..n, represented by a parent array par[1..n]: - par[i] is the ...
Implement map serialization and deserialization
You are given an in-memory map (dictionary) from strings to strings. Implement two functions: - string serialize(map<string, string> m) - map<string, ...