How to Use This Guide
Software engineering interviews typically cover four main areas: coding, system design, technical knowledge, and behavioral questions. This guide provides questions and strategic approaches for each category.
Part 1: Coding Questions (20 Questions)
Array & String Questions
1. How would you find the two numbers in an array that add up to a target sum?
Answer approach: Use a hash map to store complements. For each number, check if its complement exists in the map. Time complexity: O(n), Space: O(n).
2. Reverse a string in place without using extra space.
Answer approach: Use two pointers, one at start and one at end. Swap characters and move pointers toward the center. Time: O(n), Space: O(1).
3. Find the longest substring without repeating characters.
Answer approach: Sliding window technique with a hash set to track seen characters. Expand right, contract left when duplicate found. Time: O(n).
4. Merge two sorted arrays into one sorted array.
Answer approach: Use two pointers, compare elements, and fill result array. For in-place merge, start from the end. Time: O(n+m).
5. Check if a string is a valid palindrome (ignoring non-alphanumeric characters).
Answer approach: Two pointers from both ends, skip non-alphanumeric, compare lowercase. Time: O(n), Space: O(1).
Linked List Questions
6. Detect if a linked list has a cycle.
Answer approach: Floyd's cycle detection (tortoise and hare). Fast pointer moves 2 steps, slow moves 1. If they meet, cycle exists. Time: O(n), Space: O(1).
7. Reverse a linked list.
Answer approach: Iterate through the list, changing each node's next pointer to the previous node. Track prev, current, and next. Time: O(n).
8. Find the middle of a linked list.
Answer approach: Two pointers—slow moves 1 step, fast moves 2. When fast reaches end, slow is at middle. Time: O(n).
Tree & Graph Questions
9. Validate if a binary tree is a valid binary search tree.
Answer approach: Recursively check that each node falls within valid min/max bounds. Update bounds as you traverse. Time: O(n).
10. Find the lowest common ancestor of two nodes in a binary tree.
Answer approach: Recursively search left and right subtrees. If both return non-null, current node is LCA. Time: O(n).
11. Implement BFS and DFS for a graph.
Answer approach: BFS uses a queue (level-order), DFS uses a stack or recursion. Both need visited tracking to avoid cycles.
12. Detect if an undirected graph has a cycle.
Answer approach: DFS with parent tracking. If you visit a node that's already visited and isn't the parent, cycle exists.
Dynamic Programming Questions
13. Climbing stairs: How many ways to reach step n if you can climb 1 or 2 steps?
Answer approach: Fibonacci pattern. dp[i] = dp[i-1] + dp[i-2]. Can optimize to O(1) space with just two variables.
14. Find the maximum subarray sum (Kadane's Algorithm).
Answer approach: Track current sum and max sum. Reset current sum to 0 if it goes negative. Time: O(n).
15. Coin change: minimum coins needed to make amount.
Answer approach: Bottom-up DP. For each amount 1 to target, find min coins using each coin denomination. Time: O(amount * coins).
Additional Coding Questions
16. Implement a LRU Cache.
Answer approach: Combine hash map for O(1) lookup with doubly linked list for O(1) removal. Most recently used at head.
17. Find all permutations of a string.
Answer approach: Backtracking. Fix each character at current position, recurse for rest. Time: O(n!).
18. Merge intervals.
Answer approach: Sort by start time. Iterate and merge overlapping intervals. Time: O(n log n) for sorting.
19. Valid parentheses: check if string has valid brackets.
Answer approach: Use stack. Push opening brackets, pop on closing. Check match. Stack should be empty at end.
20. Binary search implementation.
Answer approach: Maintain left and right pointers. Compare mid element, adjust bounds accordingly. Time: O(log n).
Part 2: System Design Questions (10 Questions)
21. Design a URL shortener (like bit.ly).
Key points: Hash function for short URLs, database for mapping, read-heavy system, caching, analytics tracking, expiration handling.
22. Design a rate limiter.
Key points: Token bucket or sliding window algorithm, distributed rate limiting with Redis, different limits per user/API.
23. Design Twitter's news feed.
Key points: Fan-out on write vs read, caching, ranking algorithms, pub/sub for real-time updates, handling celebrities.
24. Design a chat application.
Key points: WebSocket connections, message queues, presence indicators, message storage, read receipts, end-to-end encryption.
25. Design a distributed cache.
Key points: Consistent hashing, replication, eviction policies (LRU), cache invalidation, write-through vs write-back.
26. Design an e-commerce system.
Key points: Product catalog, inventory management, shopping cart, checkout flow, payment processing, order fulfillment.
27. Design YouTube video streaming.
Key points: Video encoding/transcoding, CDN distribution, adaptive bitrate streaming, metadata storage, recommendation engine.
28. Design a notification system.
Key points: Multiple channels (push, email, SMS), priority queues, delivery guarantees, rate limiting, user preferences.
29. Design Uber/ride-sharing location service.
Key points: Geospatial indexing (quadtree), real-time location updates, matching algorithm, ETA calculation.
30. Design a search autocomplete system.
Key points: Trie data structure, ranking by frequency, caching popular queries, personalization, real-time updates.
Part 3: Technical Knowledge Questions (10 Questions)
31. Explain the difference between SQL and NoSQL databases.
Answer: SQL is relational with structured schemas and ACID transactions. NoSQL is non-relational, offering flexibility and horizontal scaling. Choose based on data structure and scale requirements.
32. What is the CAP theorem?
Answer: In a distributed system, you can only guarantee two of three: Consistency, Availability, and Partition tolerance. Since network partitions are inevitable, you choose between CP (consistent) or AP (available).
33. Explain REST vs GraphQL.
Answer: REST uses multiple endpoints with fixed data structures. GraphQL uses a single endpoint where clients specify exact data needs. GraphQL reduces over-fetching but adds complexity.
34. What is database indexing and when would you use it?
Answer: Indexes speed up read queries by creating sorted data structures (B-trees). Use for frequently queried columns. Trade-off: slower writes and more storage.
35. Explain microservices vs monolith architecture.
Answer: Monolith is a single deployable unit. Microservices split into independent services. Microservices offer scalability and team autonomy but add complexity (networking, data consistency).
36. What is database sharding?
Answer: Horizontal partitioning of data across multiple databases. Enables scaling beyond single server limits. Challenges include choosing shard key and handling cross-shard queries.
37. Explain event-driven architecture.
Answer: Components communicate through events via message brokers (Kafka, RabbitMQ). Benefits: loose coupling, scalability, resilience. Challenges: eventual consistency, debugging complexity.
38. What are ACID properties in databases?
Answer: Atomicity (all or nothing), Consistency (valid state transitions), Isolation (concurrent transactions don't interfere), Durability (committed data persists).
39. Explain container orchestration with Kubernetes.
Answer: Kubernetes manages containerized workloads: deployment, scaling, networking, and health monitoring. Key concepts: pods, services, deployments, ingress.
40. What is a CDN and how does it work?
Answer: Content Delivery Network caches content at edge locations worldwide. Reduces latency by serving from geographically closer servers. Essential for global applications.
Part 4: Behavioral Questions (10 Questions)
41. Tell me about a challenging technical problem you solved.
Approach: Use STAR method. Describe the situation, your specific actions, and quantifiable results. Focus on your individual contribution.
42. Describe a time you disagreed with a technical decision.
Approach: Show you can disagree respectfully, advocate for your position with data, and commit once a decision is made.
43. How do you handle tight deadlines?
Approach: Discuss prioritization, communication with stakeholders, and making trade-offs. Give a specific example.
44. Tell me about a time you mentored someone.
Approach: Describe your teaching approach, how you adapted to their learning style, and the outcome of your mentorship.
45. How do you stay current with technology?
Approach: Be specific: blogs, podcasts, conferences, side projects. Show genuine curiosity and continuous learning.
46. Describe a project you're most proud of.
Approach: Choose something with clear impact. Explain your role, challenges overcome, and what you learned.
47. How do you handle receiving critical feedback?
Approach: Show openness to feedback, give an example of feedback you received and how you acted on it.
48. Tell me about a time you had to learn something quickly.
Approach: Describe your learning process, resources used, and how you applied the knowledge effectively.
49. How do you prioritize multiple competing tasks?
Approach: Discuss frameworks (urgency vs importance), stakeholder communication, and realistic examples.
50. Why do you want to work here?
Approach: Research the company. Connect their mission, technology, or culture to your genuine interests and career goals.
Interview Preparation Tips
- Practice coding on a whiteboard or shared document
- Talk through your thinking out loud
- Ask clarifying questions before diving in
- Test your solutions with examples
- Practice system design with common scenarios
- Prepare 5-7 strong STAR stories for behavioral questions
- Research the company and role thoroughly
Good luck with your interviews!