Open question library
Programming Interview Questions with Answers
An open resource for interview preparation: explanations, examples, common mistakes and practical tasks. Answer on your own first, then compare your approach and work through the follow-up questions.
- 10 questions explained
- An example, a common mistake and a follow-up for each
- No sign-up required
Tracks
Choose your track
Python Developer Interview Questions with Answers
20 questions · Collections, Objects, Comparison, Functions
Java Developer Interview Questions with Answers
20 questions · Objects, Parameters, Strings, Collections
Frontend Developer Interview Questions with Answers
20 questions · JavaScript, HTML, CSS, HTTP
QA Engineer Interview Questions with Answers
20 questions · Fundamentals, Types of checks, Test design, Defects
General questions
Sample questions and good answers
Algorithm complexityWhat does O(n) mean?
The estimate shows how an algorithm's need for a resource grows as the input size increases. O(n) sets an asymptotic upper bound of linear order and does not tell you the exact time in milliseconds. Clarify whether you are talking about time or memory, and whether you mean the worst, average or amortized case. Compare algorithms under the same contract: for example, searching for one query and building an index for many queries have different total costs.
- Example
- One pass over a list of length n usually takes O(n) operations; an extra list of results may take O(n) memory.
- Common mistake
- Ignoring the cost of a nested operation inside what looks like a single loop.
- Interviewer follow-up
- When will an algorithm with better asymptotics lose on small inputs?
HTTPWhat happens during an HTTP request?
The client sends a method, an address, headers and, if needed, a body. The server processes the request and returns a status, headers and a response body. Proxies, caches and load balancers can sit between them, so what you observe at one point does not always describe the whole path. When diagnosing, separate establishing the connection, delivering the request, processing it and displaying the result. A successful HTTP code by itself does not prove the intended business effect.
- Example
- A 202 response can mean that a background job was accepted and will finish later.
- Common mistake
- Treating any HTTP 200 as confirmation that the data has been saved for good.
- Interviewer follow-up
- How do you tell a connection timeout from a timeout while waiting for the response?
APIWhat does an API contract include?
The contract includes the allowed operations, input data, responses, errors, authorization and the significant properties of behavior. For an operation that changes data, retries and idempotency matter; for a list, order, filters and pagination. Compatibility is defined by the consumers, so changing the meaning of a field can be more dangerous than adding a new optional field. A good contract lets you implement a client independently and check the server on reproducible examples.
- Example
- Repeating an order creation with the same idempotency key must have a result that is described in advance.
- Common mistake
- Treating an example of a successful JSON response as the whole contract.
- Interviewer follow-up
- How do you change an API without breaking an old desktop client?
SQLWhy do you need LEFT JOIN?
LEFT JOIN keeps all rows of the left side and adds the matches from the right. If there is no match, the right-hand fields get NULL. This lets you show objects without related records, such as users without orders. After the join, additional filters can remove such rows, so whether a condition goes into ON or WHERE matters. A one-to-many join increases the number of rows and requires careful aggregation.
- Example
- To count each user's orders, use LEFT JOIN and COUNT(order.id).
- Common mistake
- Filtering the right table in WHERE and accidentally excluding users without orders.
- Interviewer follow-up
- How do you find only the rows that have no match on the right?
DatabasesWhat does a transaction group together?
A transaction groups database operations into one consistent change: either the result is committed or it is rolled back. The isolation level affects which concurrent changes are visible. A transaction in one database does not automatically extend to an external HTTP service, sending an email or another database. Such boundaries need additional protocols and handling of an uncertain result. It is important to define the business invariant that must hold.
- Example
- A debit from one account and a credit to another are performed in one database transaction.
- Common mistake
- Assuming that a database rollback will cancel an external payment that has already been sent.
- Interviewer follow-up
- How do you tie a record change and sending an event together so that they never get out of sync?
DatabasesWhy can an index speed up reads and slow down writes?
An index is an extra structure that lets suitable queries find the rows they need without scanning the whole table. On inserts, updates and deletes, the base table and the index must stay consistent. The benefit depends on the condition, the sorting, the data distribution and the execution plan. Having an index does not guarantee that the optimizer will choose it. Too many indexes increase the storage size and the cost of changing data.
- Example
- An index on user_id can help a frequent lookup of a user's orders, but its benefit is checked with the query plan.
- Common mistake
- Creating an index on every field without measuring the load.
- Interviewer follow-up
- How does the order of columns affect a composite index?
ConcurrencyHow is concurrency different from parallelism?
Concurrency means working with several tasks whose execution periods overlap. Parallelism means actually executing them at the same time. A single thread with an event loop can serve I/O concurrently by switching between tasks while they wait. Simultaneous computation needs the right resources and support from the runtime. In both cases, questions of state ownership, load limiting and shutting tasks down correctly remain.
- Example
- While one request waits for the network, the event loop handles another; these are not necessarily two CPU computations running at the same time.
- Common mistake
- Treating async as a synonym for a separate thread.
- Interviewer follow-up
- Which tasks benefit from overlapping their waiting?
TestingWhat does a passing test prove?
A test confirms specific observable behavior on chosen inputs in a particular environment. It does not prove that there are no defects at all. The strength of a test suite depends on whether it covers the important rules, boundaries, failures and likely implementation mistakes. Checks at different levels complement each other: a function, an integration and a user scenario have different boundaries. The result must be tied to the version and the conditions of the run.
- Example
- A unit test of the price calculation does not confirm that the amount is passed correctly to the payment provider.
- Common mistake
- Replacing a specific result with the phrase “everything has been checked”.
- Interviewer follow-up
- How do you find out which integration risk the unit tests do not cover?
ReliabilityWhen can a request be safely retried?
A retry is safe if the contract rules out duplicating an unwanted effect or lets you recognize an operation that has already been performed. A network timeout can mean either a failure before processing or a lost response after successful execution. So payments and the creation of important objects need a stable operation key, a state check and protection against concurrent retries. Limiting the number of attempts, adding a delay and setting an overall deadline help you avoid making an overload worse.
- Example
- After a payment timeout, first check the status of the operation by its ID.
- Common mistake
- Retrying any POST immediately after a network error.
- Interviewer follow-up
- How should the client tell the user about an uncertain result?
ArchitectureWhat questions should you ask before adding a cache?
Determine what the key is, who owns the data, how stale it can get and what triggers a refresh. Then think through a cache miss, the cache being unavailable, concurrent refreshes and deletion of the source object. A cache can reduce latency, but it can also leak personal data or create views that contradict each other. A long TTL does not replace an invalidation strategy if the user needs to see a change right away.
- Example
- A public article can be cached separately from a personal profile; unpublishing the article must update the list as well.
- Common mistake
- Using one URL as the key for responses to different users.
- Interviewer follow-up
- How do you avoid recomputing one expensive value several times at once?