HireHireInterview Quizzes › Software Engineer

Software Engineer Interview Questions

Think you're ready? These are the questions that actually decide Software Engineer interviews. Warm up on Easy — then face the Hard round, where 95% of candidates crumble. 30 questions across 3 levels, instant score, completely free.

30Questions
3Difficulty levels
95%Fail the hard round
FreeInstant score
Easy
Warm-up · 10 Qs
Medium
Practical · 10 Qs
Hard
Brutal · 10 Qs
⚡ Take the Software Engineer quiz — get your score →

The Software Engineer interview questions

Below are the real questions, grouped by difficulty. Expand any one to reveal the correct answer and why — or take the timed quiz for a score you can share. Can you clear the Hard round?

Easy round 10 questions

What is the average-case time complexity of searching for an element in a balanced binary search tree with n nodes?
  • A. O(1)
  • B. O(log n) ✓
  • C. O(n)
  • D. O(n log n)
Correct answer: B. A balanced BST has height proportional to log n, so search visits at most O(log n) nodes.
In a relational database, what does an INNER JOIN between two tables return?
  • A. All rows from both tables regardless of match
  • B. Only rows that have matching values in both tables ✓
  • C. All rows from the left table plus matched rows from the right
  • D. Only rows that exist in the left table but not the right
Correct answer: B. INNER JOIN returns only the rows where the join condition matches in both tables.
Which HTTP status code indicates that the requested resource was not found on the server?
  • A. 200
  • B. 301
  • C. 404 ✓
  • D. 500
Correct answer: C. HTTP 404 is the standard status code signaling that the server could not find the requested resource.
In Git, which command creates a new branch and switches to it in a single step?
  • A. git branch new-feature
  • B. git checkout -b new-feature ✓
  • C. git merge new-feature
  • D. git clone new-feature
Correct answer: B. git checkout -b creates the new branch and immediately switches the working tree to it.
What is the primary purpose of an index on a database column?
  • A. To enforce that all values in the column are unique
  • B. To speed up data retrieval on queries filtering that column ✓
  • C. To reduce the total storage size of the table
  • D. To automatically back up the column's data
Correct answer: B. An index provides a fast lookup structure that speeds up read queries that filter or sort on the indexed column.
Which data structure operates on a Last-In-First-Out (LIFO) principle?
  • A. Queue
  • B. Stack ✓
  • C. Linked list
  • D. Hash table
Correct answer: B. A stack removes the most recently added element first, which is the LIFO principle.
In object-oriented programming, what does encapsulation primarily refer to?
  • A. Bundling data and the methods that operate on it while restricting direct access ✓
  • B. A class inheriting behavior from a parent class
  • C. One interface being implemented by many different classes
  • D. Breaking a program into independent network services
Correct answer: A. Encapsulation bundles state and behavior together and hides internal data behind controlled access.
A REST API endpoint should update an existing user's entire record. Which HTTP method is most appropriate?
  • A. GET
  • B. POST
  • C. PUT ✓
  • D. DELETE
Correct answer: C. PUT is used to replace or fully update an existing resource at a known URI.
What does the Big-O notation O(n^2) typically indicate about an algorithm?
  • A. Runtime stays constant as input grows
  • B. Runtime grows linearly with input size
  • C. Runtime grows proportionally to the square of the input size ✓
  • D. Runtime grows logarithmically with input size
Correct answer: C. O(n^2) means the number of operations scales with the square of the input size, common in nested loops over the same data.
In a multithreaded program, what is a race condition?
  • A. Two threads finishing at exactly the same time
  • B. Incorrect behavior caused by unsynchronized access to shared data ✓
  • C. A thread that runs faster than all others
  • D. A deadlock where all threads are permanently blocked
Correct answer: B. A race condition occurs when the program's outcome depends on the unsynchronized timing of threads accessing shared state.

Medium round 10 questions

You accidentally committed a file with API credentials and pushed the branch to the shared remote. What is the correct remediation?
  • A. Add the file to .gitignore and push again, which removes it from earlier commits
  • B. Run `git rm --cached secrets.env`, commit, and push; the secret is now safe
  • C. Rewrite the history to purge the file, force-push, and rotate the leaked credentials ✓
  • D. Delete the file locally and push, since Git only keeps the latest version of each file
Correct answer: C. Because the secret already exists in pushed history you must purge it from history, force-push, and rotate the exposed credentials since they should be treated as compromised.
A REST endpoint creates a new resource successfully. Which HTTP status code is the most appropriate to return?
  • A. 200 OK
  • B. 201 Created ✓
  • C. 202 Accepted
  • D. 204 No Content
Correct answer: B. 201 Created specifically indicates that a request succeeded and a new resource was created as a result.
In a relational database, a query filtering `WHERE email = ?` on a large users table is slow. What is the most effective first fix?
  • A. Add an index on the email column ✓
  • B. Rewrite the query to use SELECT * instead of specific columns
  • C. Increase the connection pool size
  • D. Wrap the query in a transaction
Correct answer: A. An index on the filtered column lets the database avoid a full table scan, which is the primary cause of slow equality lookups on large tables.
You wrote a unit test that occasionally fails without any code change. What is the most likely root cause of this 'flaky' test?
  • A. The test asserts on too few conditions
  • B. The test depends on timing, ordering, or shared external state ✓
  • C. The test file is too long
  • D. The test uses mocks instead of real objects
Correct answer: B. Flaky tests typically fail intermittently because they rely on non-deterministic factors like timing, execution order, or shared mutable state.
In JavaScript, what does `console.log(0.1 + 0.2 === 0.3)` print, and why?
  • A. true, because the numbers are exact
  • B. false, because floating-point arithmetic introduces rounding error ✓
  • C. true, because JavaScript rounds automatically
  • D. It throws a TypeError
Correct answer: B. IEEE-754 floating-point cannot represent 0.1 and 0.2 exactly, so their sum is slightly off from 0.3 and the strict comparison is false.
Your service calls a flaky third-party API that sometimes times out. Which pattern best prevents these failures from cascading and overloading the downstream service?
  • A. Retrying indefinitely until it succeeds
  • B. A circuit breaker that stops calls after repeated failures ✓
  • C. Increasing the request timeout to several minutes
  • D. Caching all responses forever
Correct answer: B. A circuit breaker trips after repeated failures to stop sending requests for a period, preventing cascading failures and giving the downstream service time to recover.
What is the primary purpose of using a prepared statement (parameterized query) instead of string-concatenating user input into SQL?
  • A. It makes queries run faster in all cases
  • B. It prevents SQL injection by separating code from data ✓
  • C. It automatically creates database indexes
  • D. It compresses the query text sent to the server
Correct answer: B. Parameterized queries send SQL structure and user data separately so input can never be interpreted as executable SQL, preventing injection.
In Git, what is the practical difference between `git merge` and `git rebase` when integrating your feature branch with `main`?
  • A. Rebase deletes the feature branch; merge keeps it
  • B. Merge creates a merge commit preserving history; rebase rewrites your commits onto the tip of main for a linear history ✓
  • C. Merge only works on remote branches; rebase only works locally
  • D. There is no difference; they are aliases
Correct answer: B. Merge combines histories with a merge commit and preserves the original branch structure, while rebase replays your commits on top of main to produce a linear history.
An HTTP request from your browser JavaScript to a different domain's API is blocked by the browser. Which mechanism controls whether this cross-origin request is allowed?
  • A. CORS (Cross-Origin Resource Sharing) headers set by the server ✓
  • B. The Content-Type request header
  • C. The client's DNS configuration
  • D. HTTP status code 418
Correct answer: A. The browser's same-origin policy blocks cross-origin requests unless the target server returns appropriate CORS headers permitting the requesting origin.
You need to look up values by key millions of times in a tight loop. Which data structure gives the best average-case lookup time?
  • A. A sorted array with linear search
  • B. A linked list
  • C. A hash map (dictionary) ✓
  • D. A stack
Correct answer: C. A hash map provides average O(1) key lookups, which is faster than the O(n) linear scan of a list or array for repeated random-access lookups.

Hard round 10 questions

A read-heavy service caches product data in Redis with a 60s TTL. A single hot product gets 50k req/s. At the TTL boundary, latency spikes and the primary DB briefly saturates every minute. Which mitigation BOTH prevents the DB dogpile AND avoids serving stale data for the full extra TTL?
  • A. Increase the TTL to 600s so expiries happen less often
  • B. Use a per-key mutex/lock so only one request recomputes on miss while others wait or serve the last value ✓
  • C. Switch the cache eviction policy from LRU to LFU
  • D. Add a random 0-60s jitter to each key's TTL at write time
Correct answer: B. A recompute lock (single-flight) collapses the stampede so only one request hits the DB while others wait, without extending staleness like a longer TTL would.
A Kafka consumer reads a record, processes it (charges a card), then commits its offset. It crashes AFTER the side effect but BEFORE the offset commit. On restart, what happens and what is the correct fix?
  • A. The record is skipped because Kafka auto-advances offsets on crash; enable auto-commit
  • B. The record is reprocessed (double charge); make processing idempotent using a dedup key so replays are safe ✓
  • C. Kafka's exactly-once transaction on the consumer poll guarantees no reprocessing; no fix needed
  • D. The consumer group rebalance drops the partition permanently; increase session.timeout.ms
Correct answer: B. With at-least-once semantics an uncommitted offset causes redelivery, so the side effect must be made idempotent (e.g., a unique transaction key) to tolerate replays.
Client A acquires a distributed lock in Redis (TTL 10s), then stalls for 15s on a stop-the-world GC pause. The lock expires and Client B acquires it and writes to shared storage. A wakes up believing it still holds the lock and also writes. Which mechanism prevents the resulting corruption?
  • A. A longer lock TTL of 60s so GC pauses fit inside it
  • B. Fencing tokens: each lock grant carries a monotonically increasing number that the storage layer rejects if lower than the last accepted ✓
  • C. Redlock across five Redis nodes to increase lock durability
  • D. Setting the Redis lock with NX and a random value checked at release time
Correct answer: B. Only a fencing token enforced at the resource makes the stale writer's request rejected, since any time-based TTL can still be violated by an arbitrarily long pause.
A payments table is sharded by shard = user_id % N. Analytics runs SELECT SUM(amount) WHERE merchant_id = ? for a merchant whose transactions are spread across all shards. What is the fundamental problem and the standard remedy?
  • A. The query is fine; each shard has an index on merchant_id so it is a single-shard lookup
  • B. It is a cross-shard scatter-gather; maintain a secondary index or read model keyed by merchant_id (e.g., via CQRS/materialized view) ✓
  • C. Rehash the whole cluster using consistent hashing to co-locate the merchant
  • D. Wrap the aggregate in a 2PC transaction so all shards return a consistent sum
Correct answer: B. The partition key is user_id, so a merchant query fans out to every shard; the fix is a separate index/read model partitioned by merchant_id, not a distributed transaction.
In Raft, a leader receives a client write and replicates the entry to a minority of followers before crashing. A new leader is elected from a node that never saw that entry. What is guaranteed about the un-replicated entry?
  • A. It is guaranteed committed because the old leader acknowledged writing it locally
  • B. It may be silently overwritten because it was never committed (never on a majority) and was not acked to the client ✓
  • C. It is automatically recovered from the old leader's disk during the next election
  • D. Raft blocks all new writes until the old leader rejoins and re-sends it
Correct answer: B. An entry is only committed once stored on a quorum; an entry present on only a minority can be overwritten by a new leader, which is why it was never acknowledged to the client.
Consider this Java snippet run by two threads sharing a long counter field `count` (no volatile, no lock): `count++;`. Beyond the obvious lost-update race, why is `count` specifically dangerous on a 32-bit JVM even for a single read?
  • A. Longs are always atomic in the JVM so there is no additional risk
  • B. Non-volatile 64-bit long/double reads and writes may be split into two 32-bit operations, so a reader can observe a torn value ✓
  • C. The JIT compiler promotes count to a register making it thread-local automatically
  • D. Garbage collection can relocate the long and corrupt its bytes
Correct answer: B. The JLS permits non-volatile long/double stores to be performed as two 32-bit writes, so a concurrent reader can see a word-tearing (half-updated) value.
You add a node to a load-balancing tier that uses plain `hash(key) % N` for routing to caches. After N goes from 8 to 9, what fraction of keys remap, and what does consistent hashing with virtual nodes fix?
  • A. About 1/9 remap; consistent hashing mainly reduces memory usage
  • B. Nearly all keys remap because the modulus changed; consistent hashing limits remapping to ~1/N of keys and virtual nodes smooth load distribution ✓
  • C. Exactly the keys on the new node remap; consistent hashing eliminates all remapping
  • D. No keys remap because hashing is deterministic; virtual nodes only help with replication
Correct answer: B. Changing the modulus reshuffles almost every key, whereas consistent hashing only moves keys near the added node (~1/N) and virtual nodes even out skew.
A service is on a G1 GC JVM with a 32GB heap and users report periodic multi-second stalls correlated with rising old-gen occupancy and eventual Full GCs. Heap dumps show a growing HashMap used as an in-process cache with no eviction. What is the most accurate diagnosis?
  • A. G1 is misconfigured; switch to the throughput (Parallel) collector to remove pauses
  • B. A memory leak: the unbounded cache retains objects, defeating generational collection until a Full GC compacts the whole heap ✓
  • C. The pauses are normal young-gen collections; increase Xmn to fix them
  • D. Network backpressure is stalling threads; the GC correlation is coincidental
Correct answer: B. An unbounded map holds strong references so objects are never reclaimed, old-gen fills, and G1 falls back to costly Full GCs — a classic leak, not a collector-tuning issue.
Two microservices, Orders and Inventory, must both succeed or both roll back when placing an order. The team wants high availability and avoids blocking. Between an orchestrated Saga and 2PC, which statement correctly captures the trade-off?
  • A. 2PC is preferred because Sagas cannot roll back once a step commits
  • B. A Saga uses compensating transactions and stays available under partition, but sacrifices isolation, allowing intermediate states other reads can observe ✓
  • C. 2PC and Saga both guarantee full ACID isolation across services
  • D. A Saga guarantees linearizability across both services without extra work
Correct answer: B. Sagas trade global isolation for availability by using compensations per step, so intermediate uncommitted-looking states are visible, unlike blocking 2PC.
You must ship a breaking change to a shared Protobuf/JSON contract consumed by dozens of independently deployed services you cannot upgrade atomically. Which rollout strategy is safe?
  • A. Reuse the existing field number but change its type, then deploy producer and all consumers simultaneously
  • B. Add the new field as optional alongside the old, dual-write both, migrate consumers, then remove the old field in a later release ✓
  • C. Delete the old field immediately and rely on consumers to ignore unknown fields
  • D. Bump the top-level version and force every consumer to redeploy within the same maintenance window
Correct answer: B. Backward/forward-compatible evolution requires additive changes and an expand-migrate-contract sequence so old and new consumers coexist during rollout.

Prep for another role

Questions are original, written and independently verified for HireHire's role interview quizzes. They reflect the kind of knowledge Software Engineer interviews test, not any specific company's questions. HireHire maps live tech & IT jobs across India, updated regularly. Last updated: July 2026.