Interview Prep

Technical Interview Questions for Developers

Prepare for coding interviews at top tech companies. These questions cover data structures, algorithms, databases, and OOP concepts frequently asked at FAANG, Microsoft, and leading startups worldwide.

Categories

🧮 Data Structures & Algorithms

Explain the difference between Array and Linked List.

Arrays store elements in contiguous memory, providing O(1) random access but O(n) insertion/deletion. Linked lists store elements in nodes with pointers, offering O(1) insertion/deletion at known positions but O(n) access time. Use arrays for frequent reads, linked lists for frequent insertions.

When would you use a HashMap vs TreeMap?

HashMap provides O(1) average lookup but no ordering. TreeMap provides O(log n) lookup with keys sorted. Use HashMap for fast lookups when order does not matter. Use TreeMap when you need sorted keys or range queries.

Explain Big O notation with examples.

Big O describes the worst-case time complexity. O(1) = constant (hash lookup). O(log n) = logarithmic (binary search). O(n) = linear (array scan). O(n log n) = linearithmic (merge sort). O(n²) = quadratic (nested loops). O(2ⁿ) = exponential (recursive Fibonacci).

How does a Hash Table handle collisions?

Common approaches: Chaining (each bucket holds a linked list of entries), Open Addressing (find next empty slot via linear/quadratic probing), and Double Hashing (use second hash function to find probe sequence). Most real-world implementations use chaining.

šŸ’» Coding Challenges

Reverse a linked list in-place.

Use three pointers: prev (null), current (head), next. Iterate through the list, reversing each pointer: next = current.next, current.next = prev, prev = current, current = next. Return prev as the new head. Time: O(n), Space: O(1).

Find the two numbers that sum to a target.

Use a HashMap to store seen numbers and their indices. For each number, check if (target - number) exists in the map. If yes, return both indices. If no, add current number to map. Time: O(n), Space: O(n).

Check if a string has all unique characters.

Approach 1: Use a boolean array of size 128 (ASCII). Iterate and check/set each char. Approach 2: Use a HashSet and check size. Approach 3: Sort and compare adjacent characters. Best: O(n) time, O(1) space with bit manipulation.

Merge two sorted arrays.

Use two pointers starting at the beginning of each array. Compare elements, append the smaller one to the result, and advance that pointer. Handle remaining elements. Time: O(n + m), Space: O(n + m) for the result array.

šŸ—„ļø Database & SQL

Explain database normalization.

Normalization organizes tables to reduce redundancy. 1NF: atomic values, no repeating groups. 2NF: remove partial dependencies (every non-key depends on the whole key). 3NF: remove transitive dependencies (non-key depends only on the key). BCNF: every determinant is a candidate key.

What is the difference between SQL JOIN types?

INNER JOIN returns matching rows from both tables. LEFT JOIN returns all left rows plus matching right rows (NULLs for non-matches). RIGHT JOIN returns all right rows plus matching left rows. FULL OUTER JOIN returns all rows from both tables.

How do indexes improve query performance?

Indexes create a B-Tree or Hash structure that allows the database to find rows without scanning the entire table. They speed up WHERE clauses, JOIN conditions, and ORDER BY operations. Trade-off: indexes slow down INSERT/UPDATE/DELETE operations.

šŸ—ļø Object-Oriented Programming

Explain the SOLID principles.

S: Single Responsibility — one class, one job. O: Open/Closed — open for extension, closed for modification. L: Liskov Substitution — subtypes must be substitutable. I: Interface Segregation — small, specific interfaces. D: Dependency Inversion — depend on abstractions, not concretions.

What is the difference between inheritance and composition?

Inheritance creates an IS-A relationship (Dog IS-A Animal). Composition creates a HAS-A relationship (Car HAS-A Engine). Prefer composition over inheritance for flexibility — it allows changing behavior at runtime and avoids tight coupling.

Explain polymorphism with an example.

Polymorphism lets objects of different types be treated through a common interface. Example: a Shape interface with a draw() method. Circle, Rectangle, and Triangle each implement draw() differently. When you call shape.draw(), the correct version runs based on the actual object type at runtime.

Ad Space Placeholder
ADVERTISEMENT