Header Ads Widget

Smart English Sponsored Ads
Support free lessons by checking our sponsors 👇

50 FAANG Interview Questions in English + Model Answers (Free PDF Download)

 

50 FAANG Interview Questions in English + Model Answers

50 FAANG Interview Questions in English + Model Answers

Preparing for FAANG (Facebook/Meta, Amazon, Apple, Netflix, Google) interviews? These companies test a mix of technical skills (coding, algorithms, system design), behavioral traits (leadership, culture fit), and domain knowledge (e.g., ML for certain roles).

Tip: Use the STAR method (Situation, Task, Action, Result) for behavioral questions. For technical ones, think aloud, explain trade-offs, and write clean code.

Category 1: Coding & Algorithms (1–20)

1. Two Sum (LeetCode Easy)

Q: Given an array of integers nums and an integer target, return indices of two numbers that add up to target.

Model Answer (Python, O(n) time):

def twoSum(nums, target):

    seen = {}

    for i, num in enumerate(nums):

        complement = target - num

        if complement in seen:

            return [seen[complement], i]

        seen[num] = i

Explanation: Use a hash map to store seen numbers. One pass → O(n) time, O(n) space.


2. Longest Substring Without Repeating Characters

Q: Find length of longest substring without repeating chars.

Model Answer (Sliding Window):

def lengthOfLongestSubstring(s):

    char_set = set()

    left = res = 0

    for right in range(len(s)):

        while s[right] in char_set:

            char_set.remove(s[left])

            left += 1

        char_set.add(s[right])

        res = max(res, right - left + 1)

    return res

O(n) time, O(min(m, n)) space where m = alphabet size.


3. Merge k Sorted Lists

Q: Merge k sorted linked lists into one.

Model Answer (Min-Heap):

import heapq

def mergeKLists(lists):

    heap = [(node.val, i, node) for i, node in enumerate(lists) if node]

    heapq.heapify(heap)

    dummy = cur = ListNode()

    while heap:

        val, list_idx, node = heapq.heappop(heap)

        cur.next = node

        cur = cur.next

        if node.next:

            heapq.heappush(heap, (node.next.val, list_idx, node.next))

    return dummy.next

O(N log k) where N = total nodes.


4. Valid Parentheses

Model Answer (Stack):

def isValid(s):

    stack = []

    pairs = {')': '(', '}': '{', ']': '['}

    for c in s:

        if c in pairs:

            if not stack or stack.pop() != pairs[c]:

                return False

        else:

            stack.append(c)

    return not stack


5. LRU Cache

Q: Design LRU Cache with get and put in O(1).

Model Answer (HashMap + Doubly Linked List):

class ListNode:

    def __init__(self, key=0, val=0):

        self.key, self.val = key, val

        self.prev = self.next = None

class LRUCache:

    def __init__(self, capacity):

        self.cap = capacity

        self.cache = {}

        self.left, self.right = ListNode(), ListNode()

        self.left.next, self.right.prev = self.right, self.left

    

    def _remove(self, node):

        prev, nxt = node.prev, node.next

        prev.next, nxt.prev = nxt, prev

    

    def _insert(self, node):

        prev = self.right.prev

        prev.next = node

        self.right.prev = node

        node.prev, node.next = prev, self.right

    

    def get(self, key):

        if key in self.cache:

            self._remove(self.cache[key])

            self._insert(self.cache[key])

            return self.cache[key].val

        return -1

    

    def put(self, key, value):

        if key in self.cache:

            self._remove(self.cache[key])

        self.cache[key] = ListNode(key, value)

        self._insert(self.cache[key])

        if len(self.cache) > self.cap:

            lru = self.left.next

            self._remove(lru)

            del self.cache[lru.key]

6–20: Quick Model Answers (Common Patterns)

# Question Key Idea Time/Space
6Trapping Rain WaterTwo pointersO(n)/O(1)
7Word LadderBFSO(N×L)
8Course ScheduleTopological Sort (Kahn’s)O(V+E)
9Clone GraphDFS + HashMapO(V+E)
10Number of IslandsDFS/BFSO(m×n)
11Rotate ImageTranspose + ReverseO(n²)
12Serialize/Deserialize BSTPreorder DFSO(n)
13Longest Increasing SubsequenceDP + Binary SearchO(n log n)
14Median of Two Sorted ArraysBinary SearchO(log(m+n))
15Regular Expression MatchingDPO(m×n)
16Merge IntervalsSort + MergeO(n log n)
17Kth Largest ElementQuickselect / HeapO(n) avg
18Find Median from Data StreamTwo HeapsO(log n)
19Text JustificationGreedyO(n)
20Minimum Window SubstringSliding Window + CounterO(n)

(Full code available in PDF)

Category 2: System Design (21–30)

21. Design TinyURL

Model Answer:

  • API: POST /shorten → returns short code; GET /{code} → 301 redirect.
  • Short code: Base62 encode auto-increment ID or hash(longURL).
  • DB: (id, long_url, expiry). Use NoSQL for scale.
  • Cache: Redis for hot URLs.
  • Edge: Handle collisions with retry; rate limiting.

22. Design Twitter Timeline

Components:

  1. Write API → Fanout to followers’ Redis lists (push model for <1K followers).
  2. Read API → Merge K sorted lists (heap) from followed users + self.
  3. Cache: Redis sorted sets per user.
  4. Scale: Sharding by user_id.

23. Design Uber Backend

Key Features:

  • Location Service: Quadtree / Geohash indexing.
  • Matching: Nearest driver → ETA via Google Maps API.
  • ETA Calc: Graph (Dijkstra) + ML traffic model.
  • DB: Drivers → Cassandra (location updates); Rides → PostgreSQL.

24–30: Concise Answers

# System Core Idea
24Netflix RecommendationCollaborative + Content-based filtering
25WhatsAppErlang + Mnesia, WebSocket, E2E encryption
26Instagram FeedFanout-on-write + Rank by engagement ML
27Rate LimiterToken Bucket / Leaky Bucket (Redis)
28Distributed CacheConsistent Hashing + Replication
29API GatewayAuth, Rate Limit, Routing (Kong/Envoy)
30Message QueueKafka partitions + Consumer groups

Category 3: Behavioral & Leadership (31–40)

31. Tell me about a time you failed.

STAR Answer:

  • S: Led a microservice migration.
  • T: Deliver in 2 sprints.
  • A: Underestimated DB schema conflicts; launched with bugs.
  • R: Rolled back in 15 min, added schema validation → 100% success next sprint. Learned: Fail-fast with feature flags.

32. Disagree and Commit?

Answer: “At Amazon, I pushed for Go over Java for a low-latency service. Data showed only 5% gain. Leadership chose Java for ecosystem. I disagreed but committed—delivered 20% faster via caching. Principle respected.”

33–40: Model One-Liners

  1. Conflict with peer → “Used data in 1:1; aligned on A/B test.”
  2. Tight deadline → “Prioritized MVP; automated tests → shipped on time.”
  3. Mentored junior → “Pair-programmed; they led next feature.”
  4. Handled ambiguous req → “Clarified with PM via mocks; reduced rework 40%.”
  5. Dealt with legacy code → “Refactored incrementally with 95% test coverage.”
  6. Customer obsession → “Added analytics; reduced churn 12%.”
  7. Bias for action → “Launched beta in 48h; iterated on feedback.”
  8. Invent & Simplify → “Replaced 5 tools with one internal library.”

Category 4: OS, Networks, DB (41–50)

41. Virtual Memory

Answer: Paging + segmentation. Page table maps virtual → physical. TLB caches recent translations. Thrashing → increase RAM or reduce working set.


42. TCP vs UDP

TCPUDP
Reliable, orderedBest-effort
Handshake, flow controlNo overhead
HTTP, EmailDNS, Video

43. CAP Theorem

Answer: In distributed systems, only two of Consistency, Availability, Partition tolerance. Example: Cassandra (AP), MongoDB strong consistency mode (CP).


44. SQL: Find 2nd Highest Salary

SELECT MAX(salary) FROM employees

WHERE salary < (SELECT MAX(salary) FROM employees);


45. Index Types

  • B-Tree: Range scans (default).
  • Hash: Equality.
  • Bitmap: Low-cardinality columns.

46–50: Quick Facts

  1. Deadlock Prevention: Avoid circular wait (resource ordering).
  2. Load Balancer Algorithms: Round-robin, Least connections.
  3. OAuth 2.0 Flow: Authorization code → access token → API call.
  4. Consistency Models: Eventual (DynamoDB) vs Strong (Spanner).
  5. Microservices Anti-pattern: Distributed monolith (tight coupling).

Free PDF Download Script

# save_as_pdf.py

from fpdf import FPDF

import textwrap

questions = [

    ("1. Two Sum", "Given nums and target...", "```python\ndef twoSum(nums, target): ...```"),

    # Add all 50 Q&A here (copy from above)

]

pdf = FPDF()

pdf.add_page()

pdf.set_font("Arial", size=12)

pdf.cell(200, 10, txt="50 FAANG Interview Q&A", ln=1, align='C')

for i, (q, ques, ans) in enumerate(questions, 1):

    pdf.set_font("Arial", 'B', 12)

    pdf.multi_cell(0, 10, f"{i}. {q}")

    pdf.set_font("Arial", size=10)

    wrapped = textwrap.fill(ques, width=90)

    pdf.multi_cell(0, 8, wrapped)

    pdf.multi_cell(0, 8, ans)

    pdf.ln(5)

pdf.output("FAANG_50_Questions.pdf")

print("PDF generated: FAANG_50_Questions.pdf")

How to Use:

  1. Copy all 50 Q&A into questions list.
  2. Run python save_as_pdf.py.
  3. Get FAANG_50_Questions.pdf instantly!
Pro Tip: Practice on LeetCode, System Design Primer, and mock interviews. Good luck—you got this! 🚀

Post a Comment

0 Comments