Coding Interview Resources
52.1K subscribers
817 photos
7 files
502 links
This channel contains the free resources and solution of coding problems which are usually asked in the interviews.

Managed by: @love_data
Download Telegram
Top 100 Data Science Interview Questions

Data Science Basics
1. What is data science and how is it different from data analytics?
2. What are the key steps in a data science lifecycle?
3. What types of problems does data science solve?
4. What skills does a data scientist need in real projects?
5. What is the difference between structured and unstructured data?
6. What is exploratory data analysis and why do you do it first?
7. What are common data sources in real companies?
8. What is feature engineering?
9. What is the difference between supervised and unsupervised learning?
10. What is bias in data and how does it affect models?

Statistics and Probability
11. What is the difference between mean, median, and mode?
12. What is standard deviation and variance?
13. What is probability distribution?
14. What is normal distribution and where is it used?
15. What is skewness and kurtosis?
16. What is correlation vs causation?
17. What is hypothesis testing?
18. What are Type I and Type II errors?
19. What is p-value?
20. What is confidence interval?

Data Cleaning and Preprocessing
21. How do you handle missing values?
22. How do you treat outliers?
23. What is data normalization and standardization?
24. When do you use Min-Max scaling vs Z-score?
25. How do you handle imbalanced datasets?
26. What is one-hot encoding?
27. What is label encoding?
28. How do you detect data leakage?
29. What is duplicate data and how do you handle it?
30. How do you validate data quality?

Python for Data Science
31. Why is Python popular in data science?
32. Difference between list, tuple, set, and dictionary?
33. What is NumPy and why is it fast?
34. What is Pandas and where do you use it?
35. Difference between loc and iloc?
36. What are vectorized operations?
37. What is lambda function?
38. What is list comprehension?
39. How do you handle large datasets in Python?
40. What are common Python libraries used in data science?

Data Visualization
41. Why is data visualization important?
42. Difference between bar chart and histogram?
43. When do you use box plots?
44. What does a scatter plot show?
45. What are common mistakes in data visualization?
46. Difference between Seaborn and Matplotlib?
47. What is a heatmap used for?
48. How do you visualize distributions?
49. What is dashboarding?
50. How do you choose the right chart?

Machine Learning Basics
51. What is machine learning?
52. Difference between regression and classification?
53. What is overfitting and underfitting?
54. What is train-test split?
55. What is cross-validation?
56. What is bias-variance tradeoff?
57. What is feature selection?
58. What is model evaluation?
59. What is baseline model?
60. How do you choose a model?

Supervised Learning
61. How does linear regression work?
62. Assumptions of linear regression?
63. What is logistic regression?
64. What is decision tree?
65. What is random forest?
66. What is KNN and when do you use it?
67. What is SVM?
68. How does Naive Bayes work?
69. What are ensemble methods?
70. How do you tune hyperparameters?

Unsupervised Learning
71. What is clustering?
72. Difference between K-means and hierarchical clustering?
73. How do you choose value of K?
74. What is PCA?
75. Why is dimensionality reduction needed?
76. What is anomaly detection?
77. What is association rule mining?
78. What is DBSCAN?
79. What is cosine similarity?
80. Where is unsupervised learning used?

Model Evaluation Metrics
81. What is accuracy and when is it misleading?
82. What is precision and recall?
83. What is F1 score?
84. What is ROC curve?
85. What is AUC?
86. Difference between confusion matrix metrics?
87. What is log loss?
88. What is RMSE?
89. What metric do you use for imbalanced data?
90. How do business metrics link to ML metrics?
3
Deployment and Real-World Practice
91. What is model deployment?
92. What is batch vs real-time prediction?
93. What is model drift?
94. How do you monitor model performance?
95. What is feature store?
96. What is experiment tracking?
97. How do you explain model predictions?
98. What is data versioning?
99. How do you handle failed models?
100. How do you communicate results to non-technical stakeholders?

Double Tap ♥️ For Detailed Answers
8
Want to start your career in 𝗔𝗜 & 𝗗𝗮𝘁𝗮 𝗦𝗰𝗶𝗲𝗻𝗰𝗲😍?

Learn from IIIT Bangalore & upGrad

💫 Beginner Friendly
💫 Industry Recognized Certificate
💫High Demand Career Skills

𝗕𝗼𝗼𝗸 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗻𝘀𝗲𝗹𝗹𝗶𝗻𝗴👇Now & explore your career roadmap

https://pdlink.in/4twH9xg

🎓Top roles you can target:
* Data Analyst , AI Engineer ,Machine Learning Engineer & Data Scientist
1
If you interview at Google, you’ll be grilled on graph problems and real-world use cases, like Google Maps.

If you interview at Amazon, expect stack/queue questions straight out of their backend systems, think processing millions of print jobs and browser back buttons.

If you interview at Atlassian or Oracle, don’t be surprised if DSA problems are tied to actual product scenarios, like task tracking, caching, and visitor analytics.

Every DSA round cares about:
→ Can you map the right data structure to a real problem?
→ Do you understand WHY Google uses graphs, why Amazon cares about queues, why Microsoft loves sets and tries?

After coaching students and professionals for the last 8+ years and helping them get placed across the board at Google, Amazon, Atlassian, Juspay, Swiggy, and many more companies.

I can tell you with 100% certainty that without mastering these 8 essential data structures and their problems, you won’t be able to clear coding interviews.

Here are the 8 Data Structures You Must Know:

→ 1. Arrays:
Foundation for all DSA. Fast access, easy to use, but slow for inserts/deletes in the middle. Used everywhere, think memory management, and basic storage.

– Learn which pattern to use for which problem
– Map interview keywords to real solutions
– Practice 5–6 Leetcode must-solves per pattern
– Track your progress and build a real interview toolkit }

→ 2. Linked Lists:
Great for inserts/deletes, bad for random access. Useful in implementing queues, stacks, and real-world apps like undo operations.

→ 3. Hash Maps:
Fast key-value lookups, like dictionaries. Power most caching systems and help in solving “find duplicates” or “group by” problems.

→ 4. Stacks & Queues:
Think of your browser history (stack), print jobs (queue), or undo-redo (stack). Interviewers love these for testing order and flow.

→ 5. Trees (including Binary Search Trees):
Used for hierarchical data, searching, sorting, and in system internals. Master BSTs for fast lookups and ordered storage.

→ 6. Tries (Prefix Trees):
Special tree for autocomplete, spell checkers, and prefix matching. Autocomplete in search bars is built on tries.

→ 7. Heaps:
Perfect for getting the min/max element fast. Used in priority queues, scheduling jobs, and heapsort.

→ 8. Graphs:
Most complex but super important. Used in Google Maps, social networks, recommendations, network routing. You need to understand adjacency lists, DFS, BFS, and shortest path algorithms.

Bottom line:
Don’t just practice random Leetcode problems. Master these data structures, and also understand real-world use cases so you don't fall into the trap of tricky questions.
2👍2
🗄️ 𝗧𝗼𝗽 𝟱 𝗙𝗥𝗘𝗘 𝗦𝗤𝗟 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 🚀

SQL is one of the most important skills for Data Analyst & Tech jobs in 2026 🔥
These FREE certification courses can help you learn SQL from scratch & boost your resume 💼

Learn:
SQL Queries & Databases 🗄️
Data Analysis Basics 📊
Real-world Projects
Beginner to Advanced Concepts

𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:- 
 
https://pdlink.in/4dCHiKI
 
💯 Beginner Friendly + FREE Certificates 🎓
💼 Perfect for Students, Freshers & Career Switchers
50 Must-Know Web Development Concepts for Interviews 🌐💼

📍 HTML Basics
1. What is HTML?
2. Semantic tags (article, section, nav)
3. Forms and input types
4. HTML5 features
5. SEO-friendly structure

📍 CSS Fundamentals
6. CSS selectors & specificity
7. Box model
8. Flexbox
9. Grid layout
10. Media queries for responsive design

📍 JavaScript Essentials
11. let vs const vs var
12. Data types & type coercion
13. DOM Manipulation
14. Event handling
15. Arrow functions

📍 Advanced JavaScript
16. Closures
17. Hoisting
18. Callbacks vs Promises
19. async/await
20. ES6+ features

📍 Frontend Frameworks
21. React: props, state, hooks
22. Vue: directives, computed properties
23. Angular: components, services
24. Component lifecycle
25. Conditional rendering

📍 Backend Basics
26. Node.js fundamentals
27. Express.js routing
28. Middleware functions
29. REST API creation
30. Error handling

📍 Databases
31. SQL vs NoSQL
32. MongoDB basics
33. CRUD operations
34. Indexes & performance
35. Data relationships

📍 Authentication & Security
36. Cookies vs LocalStorage
37. JWT (JSON Web Token)
38. HTTPS & SSL
39. CORS
40. XSS & CSRF protection

📍 APIs & Web Services
41. REST vs GraphQL
42. Fetch API
43. Axios basics
44. Status codes
45. JSON handling

📍 DevOps & Tools
46. Git basics & GitHub
47. CI/CD pipelines
48. Docker (basics)
49. Deployment (Netlify, Vercel, Heroku)
50. Environment variables (.env)

Double Tap ♥️ For More
2
𝗔𝗜 𝗮𝗻𝗱 𝗠𝗟 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 𝗯𝘆 𝗖𝗖𝗘, 𝗜𝗜𝗧 𝗠𝗮𝗻𝗱𝗶😍

Freshers get 15 LPA Average Salary with AI & ML Skills!

💻 100% Online
6 Months Duration
👨‍🏫 Learn from IIT Professors
📌 Open for Students ,Freshers & Working Professionals

💼 Placement Assistance with 5000+ Companies
📈 High Demand Skills for Future Tech Jobs

Top companies are hiring for candidates with 𝗔𝗜, 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 skills in 2026

🔥Deadline :- 17th May

  𝗔𝗽𝗽𝗹𝘆 𝗡𝗼𝘄👇 :- 

https://pdlink.in/4nmI024
.
Get Placement Assistance With 5000+ Companies
1
🚀 Coding Interview Questions with Answers — Part 1

🧠 1. What is an array and how is it stored in memory?
An array is a data structure used to store multiple elements of the same data type in a contiguous block of memory.

Example: arr = [10, 20, 30, 40]

🔹 Key Features
- Fixed size (in most languages)
- Fast access using index
- Stores elements sequentially

🔹 Memory Representation
If an integer takes 4 bytes:

Index | Value | Memory Address
0 | 10 | 1000
1 | 20 | 1004
2 | 30 | 1008
3 | 40 | 1012

Each element is stored next to the previous one.

🔹 Time Complexity
Operation | Complexity
Access | O(1)
Search | O(n)
Insert/Delete (middle) | O(n)

🔹 Interview Tip
Arrays are preferred when:
- Fast indexing is needed
- Memory efficiency matters
- Data size is mostly fixed

🚀 2. What is the difference between an array and a linked list?

Feature | Array | Linked List
Memory | Contiguous | Non-contiguous
Access Speed | O(1) | O(n)
Insert/Delete | Slow | Fast
Size | Fixed | Dynamic
Extra Memory | Less | More (pointer storage)

🔹 Array Example: arr = [1, 2, 3]
🔹 Linked List Example: 1 → 2 → 3 → NULL
Each node stores: Data + Pointer to next node

🔹 When to Use
Use Arrays: Random access needed, Cache-friendly operations
Use Linked Lists: Frequent insertions/deletions, Dynamic memory allocation

🔹 Interview Tip
Linked lists solve resizing problems of arrays but sacrifice fast access speed.

🚀 3. Explain time complexity using Big-O notation
Big-O notation measures how an algorithm grows as input size increases.

🔹 Common Complexities
Complexity | Meaning
O(1) | Constant
O(log n) | Logarithmic
O(n) | Linear
O(n log n) | Efficient sorting
O(n²) | Nested loops
O(2ⁿ) | Exponential

🔹 Example:
for i in range(n):
print(i)
This runs n times. ➡️ Complexity = O(n)

🔹 Nested Loop Example:
for i in range(n):
for j in range(n):
print(i, j)

➡️ Complexity = O(n²)

🔹 Why It Matters
Interviewers use Big-O to evaluate: Scalability, Efficiency, Optimization skills

🔹 Interview Tip
Always discuss: Time complexity, Space complexity, Trade-offs

🚀 4. How do you implement a stack using an array?
A stack follows the LIFO principle: Last In, First Out

Operations: Push, Pop, Peek

🔹 Python Implementation:
class Stack:
def init(self):
self.stack = []

def push(self, value):
self.stack.append(value)

def pop(self):
if self.is_empty():
return "Stack Underflow"
return self.stack.pop()

def peek(self):
if self.is_empty():
return None
return self.stack[-1]

def is_empty(self):
return len(self.stack) == 0

🔹 Example:
s = Stack()
s.push(10)
s.push(20)
print(s.pop()) # 20

🔹 Complexity
Operation | Complexity
Push | O(1)
Pop | O(1)
Peek | O(1)

🔹 Real-World Uses
Undo feature, Browser history, Function call stack, Expression evaluation

🚀 5. How do you implement a queue using an array or linked list?
A queue follows the FIFO principle: First In, First Out

Operations: Enqueue, Dequeue

🔹 Queue Using Array:
class Queue:
def init(self):
self.queue = []

def enqueue(self, value):
self.queue.append(value)

def dequeue(self):
if not self.queue:
return "Empty Queue"
return self.queue.pop(0)

⚠️ Problem: pop(0) takes O(n) because elements shift.

🔹 Queue Using Linked List:
from collections import deque

q = deque()
q.append(10)
q.append(20)
print(q.popleft())

🔹 Complexity
Operation | Complexity
Enqueue | O(1)
Dequeue | O(1)

🔹 Real-World Uses
CPU scheduling, Task queues, Messaging systems, BFS traversal

🚀 6. How does a hash table work?
A hash table stores key-value pairs using a hash function.

🔹 Example:
student = {
"name": "John",
"age": 22
}

🔹 Working: 
1. Key goes into hash function 
2. Hash function generates index 
3. Value stored at that index 

🔹 Example Flow 
hash("age") → index 5 
Store: table[5] = 22
1
🚀 7. How do you handle collisions in a hash table?
A collision happens when two keys generate the same index.

🔹 Example:
hash("abc") = 5
hash("xyz") = 5
Both want index 5.

🔹 Collision Handling Techniques

1️⃣ Chaining
Store multiple values in a linked list.
Index 5: abc → xyz

2️⃣ Open Addressing
Find another empty slot.
Methods: Linear probing, Quadratic probing, Double hashing

🔹 Linear Probing Example
Index occupied? Move to next slot.

🔹 Interview Tip
Most interviewers expect Chaining and Linear probing to be explained clearly.

🚀 8. What is a binary tree and a binary search tree (BST)?

🔹 Binary Tree
A tree where each node has at most 2 children.
10
/ \
5 20

🔹 Binary Search Tree (BST)
Special binary tree where: Left < Root < Right
10
/ \
5 20

🔹 BST Advantages
Fast searching, Sorted traversal, Efficient insert/delete

🔹 Complexity
Operation | Average
Search | O(log n)
Insert | O(log n)
Delete | O(log n)

Worst case: O(n)

🔹 Interview Tip
BST questions are among the most asked DSA interview topics.

🚀 9. How do you traverse a tree (inorder, preorder, postorder)?
Tree traversal means visiting all nodes.

🔹 Inorder Traversal
Left → Root → Right
def inorder(root):
if root:
inorder(root.left)
print(root.val)
inorder(root.right)

➡️ Used in BST to get sorted order.

🔹 Preorder Traversal
Root → Left → Right
Used for: Tree copying, Serialization

🔹 Postorder Traversal
Left → Right → Root
Used for: Deletion, Bottom-up processing

🔹 Complexity
All traversals: Time O(n), Space O(h)

🚀 10. What is recursion and when is it useful?
Recursion is when a function calls itself.

🔹 Example:
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)

🔹 Recursive Flow
factorial(4) = 4 × factorial(3) = 4 × 3 × factorial(2)...

🔹 Key Components
1. Base case
2. Recursive case

🔹 Where Recursion is Useful
Trees, Graphs, DFS, Backtracking, Divide & Conquer

🔹 Interview Tip
Always explain: Base condition, Stack usage, Time complexity

🔹 Common Mistake
Missing base case causes: Stack Overflow Error

🔥 Double Tap ❤️ For Part-2
5
🚀 𝗕𝗲𝗰𝗼𝗺𝗲 𝗝𝗼𝗯-𝗥𝗲𝗮𝗱𝘆 𝗶𝗻 𝗗𝗮𝘁𝗮 𝗦𝗰𝗶𝗲𝗻𝗰𝗲 & 𝗔𝗜 𝘄𝗶𝘁𝗵 𝗜𝗻𝗱𝘂𝘀𝘁𝗿𝘆 𝗘𝘅𝗽𝗲𝗿𝘁𝘀! 📊

Learn the most in-demand skills of 2026

💫Data Science ,AI,ML &Python & SQL

💼 Get Placement Assistance
🎓 Beginner Friendly Program
💻 Learn Online from Anywhere
📈 Build Skills Companies Actually Hire For

🔥 AI is changing every industry — this is the best time to upskill and secure high-paying tech jobs.

𝐑𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐍𝐨𝐰 👇:-

 https://pdlink.in/4fdWxJB

Limited Seats Available – Apply Fast!
1
🚀 Coding Interview Questions with Answers — Part 2

🌱 Arrays, Strings & Two-Pointers

🚀 11. How do you remove duplicates from a sorted array?
Since the array is already sorted, duplicates appear together.

🔹 Best Approach
Use the Two-Pointer Technique.
- One pointer tracks unique elements
- Another scans the array

🔹 Python Solution
def remove_duplicates(arr):
    if not arr:
        return 0

    i = 0

    for j in range(1, len(arr)):
        if arr[j]!= arr[i]:
            i += 1
            arr[i] = arr[j]

    return i + 1

arr = [1,1,2,2,3,4,4]
length = remove_duplicates(arr)
print(arr[:length])

🔹 Output
[1][2][3][4]

🔹 Complexity
Time → O(n)
Space → O(1)

🔹 Interview Tip
This is one of the most common two-pointer interview problems.

🚀 12. How do you solve “Two Sum” efficiently?
Problem: Find two numbers whose sum equals target.

🔹 Brute Force
for i in range(len(arr)):
    for j in range(i+1, len(arr)):
        if arr[i] + arr[j] == target:
            return [i, j]
Complexity → O(n²)

🔹 Optimized HashMap Solution
def two_sum(arr, target):
    hashmap = {}

    for i, num in enumerate(arr):
        complement = target - num

        if complement in hashmap:
            return [hashmap[complement], i]

        hashmap[num] = i

print(two_sum([2,7,11,15], 9))

🔹 Output
[0][1]

🔹 Complexity
Time → O(n)
Space → O(n)

🔹 Interview Tip
Hashing is the key optimization here.

🚀 13. How do you reverse a string or array?

🔹 Reverse String
s = "hello"
print(s[::-1])

Output → olleh

🔹 Two-Pointer Method
def reverse_array(arr):
    left = 0
    right = len(arr) - 1

    while left < right:
        arr[left], arr[right] = arr[right], arr[left]

        left += 1
        right -= 1

    return arr

print(reverse_array([1,2,3,4]))

🔹 Complexity
Time → O(n)
Space → O(1)

🔹 Interview Tip
Interviewers often prefer the two-pointer approach.

🚀 14. How do you find the maximum subarray sum (Kadane’s Algorithm)?
Problem: Find contiguous subarray with maximum sum.

🔹 Kadane’s Algorithm
def max_subarray(arr):
    current_sum = arr[0]
    max_sum = arr[0]

    for num in arr[1:]:
        current_sum = max(num, current_sum + num)
        max_sum = max(max_sum, current_sum)

    return max_sum

print(max_subarray([-2,1,-3,4,-1,2,1,-5,4]))

🔹 Output
6

Subarray:
[4, -1, 2, 1]

🔹 Complexity
Time → O(n)
Space → O(1)

🔹 Interview Tip
Kadane’s Algorithm is a very high-frequency interview question.

🚀 15. How do you rotate an array?
Rotate array by k positions.

🔹 Python Solution
def rotate(arr, k):
    k = k % len(arr)
    return arr[-k:] + arr[:-k]

print(rotate([1,2,3,4,5], 2))

🔹 Output
[4][5][1][2][3]

🔹 Complexity
Time → O(n)
Space → O(n)

🔹 In-Place Optimization
Can be solved in O(1) extra space using reversal algorithm.

🚀 16. How do you find the first missing positive number?
Problem: Find smallest missing positive integer.
Example: [3,4,-1,1]
Output: 2

🔹 Optimized Solution Idea
Place each number at its correct index.
1 → index 0
2 → index 1

🔹 Python Solution
def first_missing_positive(nums):
    n = len(nums)

    for i in range(n):
        while 1 <= nums[i] <= n and nums[nums[i]-1]!= nums[i]:
            nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1]

    for i in range(n):
        if nums[i]!= i + 1:
            return i + 1

    return n + 1

print(first_missing_positive([3,4,-1,1]))

🔹 Complexity
Time → O(n)
Space → O(1)

🔹 Interview Tip
This is considered a hard interview problem.

🚀 17. How do you implement sliding-window problems?
Sliding window helps optimize subarray/substring problems.

🔹 Example Problem
Maximum sum of subarray of size k.
def max_sum(arr, k):
    window_sum = sum(arr[:k])
    max_sum = window_sum

    for i in range(k, len(arr)):
        window_sum += arr[i] - arr[i-k]
        max_sum = max(max_sum, window_sum)

    return max_sum

print(max_sum([1,2,3,4,5], 3))

🔹 Output
12

🔹 Complexity
Time → O(n)
Space → O(1)

🔹 Interview Tip
Sliding window is heavily used in:
- Substrings
- Subarrays
- Streaming data
2
🚀 18. How do you merge two sorted arrays?

🔹 Python Solution
def merge(arr1, arr2):
i = j = 0
result = []

while i < len(arr1) and j < len(arr2):
if arr1[i] < arr2[j]:
result.append(arr1[i])
i += 1
else:
result.append(arr2[j])
j += 1

result.extend(arr1[i:])
result.extend(arr2[j:])

return result

print(merge([1,3,5], [2,4,6]))

🔹 Output
[1][2][3][4][5][6]

🔹 Complexity
Time → O(n + m)
Space → O(n + m)

🔹 Interview Tip
This is the foundation of Merge Sort.

🚀 19. How do you find the longest substring without repeating characters?

🔹 Sliding Window + HashSet
def longest_substring(s):
char_set = set()
left = 0
max_len = 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])
max_len = max(max_len, right - left + 1)

return max_len

print(longest_substring("abcabcbb"))

🔹 Output
3

Substring:
"abc"

🔹 Complexity
Time → O(n)
Space → O(n)

🔹 Interview Tip
Very frequently asked in FAANG interviews.

🚀 20. How do you implement a circular buffer?
A circular buffer reuses empty spaces efficiently.

🔹 Visualization
[1, 2, 3, _, _]

After removal:
[_, 2, 3, _, _]

Next insert goes to empty slot.

🔹 Python Implementation
class CircularBuffer:
def init(self, size):
self.buffer = [None] * size
self.size = size
self.head = 0
self.tail = 0
self.count = 0

def enqueue(self, value):
if self.count == self.size:
return "Buffer Full"

self.buffer[self.tail] = value
self.tail = (self.tail + 1) % self.size
self.count += 1

def dequeue(self):
if self.count == 0:
return "Buffer Empty"

value = self.buffer[self.head]
self.head = (self.head + 1) % self.size
self.count -= 1

return value

🔹 Uses
- Streaming systems
- Audio processing
- Producer-consumer problems
- Network buffers

🔹 Complexity
Enqueue → O(1)
Dequeue → O(1)

🔥 Double Tap ❤️ For Part-3
3
𝗣𝗿𝗼𝗱𝘂𝗰𝘁 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 𝘄𝗶𝘁𝗵 𝗔𝗜 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 by iHUB IIT Roorkee 😍

Freshers get paid 12 LPA average salary for the role of Associate Product Manager! 💼

𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝘀:
Learn from IIT Roorkee Professors
Placement support from 5,000+ companies
Professional Certification in Product Management with Applied AI
100% Online Program
Open to Everyone

📅𝗗𝗲𝗮𝗱𝗹𝗶𝗻𝗲: 17th May 2026

  𝗔𝗽𝗽𝗹𝘆 𝗡𝗼𝘄👇 :- 

https://pdlink.in/4ddJZ5C

Limited Seats Available — Apply Soon!
🚀 Coding Interview Questions with Answers — Part 3 

🔗 Linked Lists

🚀 21. How do you reverse a singly linked list? 
A singly linked list can be reversed by changing the direction of pointers.

🔹 Example 
Before: 
1 → 2 → 3 → NULL 

After: 
3 → 2 → 1 → NULL 

🔹 Iterative Solution

class Node:
    def __init__(self, data):
        self.data = data
        self.next = None

def reverse(head):
    prev = None
    current = head

    while current:
        next_node = current.next
        current.next = prev

        prev = current
        current = next_node

    return prev


🔹 Complexity 
Time → O(n) 
Space → O(1) 

🔹 Interview Tip 
This is one of the most important linked-list questions.

🚀 22. How do you detect a cycle in a linked list? 
Use Floyd’s Cycle Detection Algorithm. 
Also called: Tortoise and Hare Algorithm 

🔹 Idea 
• Slow pointer moves 1 step
• Fast pointer moves 2 steps
• If they meet → cycle exists

🔹 Python Solution

def has_cycle(head):
    slow = fast = head

    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next

        if slow == fast:
            return True

    return False


🔹 Complexity 
Time → O(n) 
Space → O(1) 

🔹 Interview Tip 
Very common interview question.

🚀 23. How do you find the middle node of a linked list? 
Use two pointers.

🔹 Approach 
• Slow pointer → moves 1 step
• Fast pointer → moves 2 steps

When fast reaches end: 
slow = middle 

🔹 Python Solution

def middle_node(head):
    slow = fast = head

    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next

    return slow


🔹 Complexity 
Time → O(n) 
Space → O(1) 

🔹 Interview Tip 
Two-pointer technique is heavily used in linked lists.

🚀 24. How do you merge two sorted linked lists? 

🔹 Example 
1 → 3 → 5 
2 → 4 → 6 

Merged: 
1 → 2 → 3 → 4 → 5 → 6 

🔹 Python Solution

def merge_lists(l1, l2):
    dummy = Node(0)
    current = dummy

    while l1 and l2:
        if l1.data < l2.data:
            current.next = l1
            l1 = l1.next
        else:
            current.next = l2
            l2 = l2.next

        current = current.next

    current.next = l1 or l2

    return dummy.next


🔹 Complexity 
Time → O(n + m) 
Space → O(1) 

🔹 Interview Tip 
This problem is the base concept behind merge sort on linked lists.

🚀 25. How do you find and remove a duplicate in a list? 

🔹 Using HashSet

def remove_duplicates(head):
    seen = set()

    current = head
    prev = None

    while current:
        if current.data in seen:
            prev.next = current.next
        else:
            seen.add(current.data)
            prev = current

        current = current.next

    return head


🔹 Complexity 
Time → O(n) 
Space → O(n) 

🔹 Without Extra Space 
Can also be solved using nested loops: O(n²) 

🔹 Interview Tip 
Interviewers may ask: Can you solve it without extra memory?

🚀 26. How do you implement a dummy head in linked-list problems? 
A dummy node simplifies edge cases.

🔹 Why Useful? 
Without dummy node: Handling head insertion/deletion becomes complex 
With dummy node: Logic becomes cleaner 

🔹 Example

dummy = Node(0)
dummy.next = head


🔹 Use Cases 
Remove nodes 
Merge lists 
Partition lists 
Reverse sublists 

🔹 Interview Tip 
Using dummy nodes often makes solutions cleaner and bug-free.

🚀 27. How do you delete a node given only that node (no head)? 
Important constraint: No access to head pointer 

🔹 Trick 
Copy next node value into current node.

🔹 Python Solution

def delete_node(node):
    node.data = node.next.data
    node.next = node.next.next


🔹 Limitation 
Cannot delete last node because no next node exists.

🔹 Interview Tip 
Classic interview trick question.
2
🚀 28. How do you implement a circular linked list?

In a circular linked list: Last node → points to head instead of NULL.

🔹 Visualization 
1 → 2 → 3 
↑       ↓ 
← ← ← ←

🔹 Python Example
class Node:
  def init(self, data):
    self.data = data
    self.next = None

head = Node(1)
second = Node(2)
third = Node(3)

head.next = second
second.next = third
third.next = head

🔹 Uses
Round-robin scheduling
Multiplayer games
Music playlists
CPU scheduling

🚀 29. How do you split a list into equal parts?

🔹 Approach
1. Count total nodes
2. Divide length
3. Break links carefully

🔹 Example
1 → 2 → 3 → 4 → 5 → 6

Split into 2 parts:
1 → 2 → 3
4 → 5 → 6

🔹 Python Idea
length = count_nodes(head)
part_size = length // k
extra = length % k

Distribute remaining nodes one by one.

🔹 Complexity
Time → O(n)
Space → O(1)

🔹 Interview Tip
Frequently appears in partitioning problems.

🚀 30. How do you implement a doubly linked list?
A doubly linked list stores: prev pointer + next pointer

🔹 Visualization
NULL ← 1 ⇄ 2 ⇄ 3 → NULL

🔹 Python Implementation
class Node:
  def init(self, data):
    self.data = data
    self.prev = None
    self.next = None

🔹 Advantages
Bidirectional traversal
Easier deletion
Efficient backtracking

🔹 Disadvantages
More memory
Extra pointer management

🔹 Real-World Uses
Browser history
Undo/redo
Navigation systems
Music players

🔹 Complexity
Insert/Delete → O(1)
Search → O(n)

🔥 Double Tap ❤️ For Part-4
2
🚀 Coding Interview Questions with Answers — Part 4

🗂️ Stacks, Queues & Heaps

🚀 31. How do you implement a stack with a max-stack (O(1) max query)?

A Max Stack supports:
• Push
• Pop
• Get Maximum Element in O(1)

🔹 Idea
Maintain:
1. Main stack
2. Max stack

Max stack stores current maximums.

🔹 Python Solution

class MaxStack:
    def __init__(self):
        self.stack = []
        self.max_stack = []

    def push(self, value):
        self.stack.append(value)

        if not self.max_stack or value >= self.max_stack[-1]:
            self.max_stack.append(value)

    def pop(self):
        if self.stack[-1] == self.max_stack[-1]:
            self.max_stack.pop()

        return self.stack.pop()

    def get_max(self):
        return self.max_stack[-1]


🔹 Complexity
Operation - Complexity
Push - O(1) 
Pop - O(1) 
Get Max - O(1) 

🔹 Interview Tip
Very common design-based stack question.

🚀 32. How do you implement a queue using two stacks?

Queues are FIFO. Stacks are LIFO. 
We can combine two stacks.

🔹 Idea
Stack1 → enqueue 
Stack2 → dequeue

🔹 Python Solution

class Queue:
    def __init__(self):
        self.s1 = []
        self.s2 = []

    def enqueue(self, value):
        self.s1.append(value)

    def dequeue(self):
        if not self.s2:
            while self.s1:
                self.s2.append(self.s1.pop())

        return self.s2.pop()


🔹 Complexity
Operation - Complexity
Enqueue - O(1) 
Dequeue - Amortized O(1) 

🔹 Interview Tip
Interviewers love this because it tests understanding of stack behavior.

🚀 33. How do you design a stack that supports getMin() in O(1)?

Very similar to Max Stack.

🔹 Idea
Maintain:
• Main stack
• Min stack

🔹 Python Solution

class MinStack:
    def __init__(self):
        self.stack = []
        self.min_stack = []

    def push(self, value):
        self.stack.append(value)

        if not self.min_stack or value <= self.min_stack[-1]:
            self.min_stack.append(value)

    def pop(self):
        if self.stack[-1] == self.min_stack[-1]:
            self.min_stack.pop()

        return self.stack.pop()

    def get_min(self):
        return self.min_stack[-1]


🔹 Complexity
Operation - Complexity
Push - O(1) 
Pop - O(1) 
Get Min - O(1) 

🔹 Interview Tip
This is one of the highest-frequency interview problems.

🚀 34. What is a monotonic stack and when is it useful?

A monotonic stack maintains elements in:
• Increasing order OR
• Decreasing order

🔹 Uses
Next Greater Element 
Largest Rectangle in Histogram 
Stock Span Problem 
Daily Temperatures 

🔹 Example

arr = [2, 1, 3]

stack = []

for num in arr:
    while stack and stack[-1] > num:
        stack.pop()

    stack.append(num)


🔹 Complexity
Most monotonic stack problems: 
O(n) 

because every element is pushed and popped once.

🔹 Interview Tip
Extremely important pattern for medium/hard problems.

🚀 35. How do you implement a priority queue / heap?

A heap is a complete binary tree.

Types:
• Min Heap
• Max Heap

🔹 Python Min Heap

import heapq

heap = []

heapq.heappush(heap, 10)
heapq.heappush(heap, 5)
heapq.heappush(heap, 20)

print(heapq.heappop(heap))


🔹 Output
5

🔹 Complexity
Operation - Complexity
Insert - O(log n) 
Delete - O(log n) 
Peek - O(1) 

🔹 Uses
Task scheduling 
Dijkstra’s algorithm 
Top K problems 
Priority processing 

🚀 36. How do you find the top K frequent elements?

🔹 Approach
1. Count frequency using hashmap
2. Use heap

🔹 Python Solution

from collections import Counter
import heapq

def top_k(nums, k):
    freq = Counter(nums)

    return heapq.nlargest(k, freq.keys(), key=freq.get)

print(top_k([1, 1, 1, 2, 2, 3], 2))


🔹 Output
[1, 2]

🔹 Complexity
Complexity - Value
Time - O(n log k) 
Space - O(n) 

🔹 Interview Tip
Heap + hashmap combination is frequently tested.
🚀 37. How do you merge K sorted lists?

🔹 Efficient Approach
Use a Min Heap.

Heap stores: 
smallest current node

🔹 Python Idea

import heapq
heapq.heappush(heap, (node.val, node))


Repeatedly:
• Pop smallest node
• Add next node from same list

🔹 Complexity 
Complexity - Value 
Time - O(n log k) 
Space - O(k) 

Where: 
n = total nodes 
k = number of lists 

🔹 Interview Tip 
Very common hard interview problem.

🚀 38. How do you implement LRU / LFU cache?

🔹 LRU Cache 
LRU: Least Recently Used 
Remove least recently accessed item.

🔹 Efficient Design 
Use: 
1. HashMap
2. Doubly Linked List

🔹 Python LRU Example

python
from collections import OrderedDict

class LRUCache:
    def init(self, capacity):
        self.cache = OrderedDict()
        self.capacity = capacity

    def get(self, key):
        if key not in self.cache:
            return -1

        self.cache.move_to_end(key)

        return self.cache[key]

    def put(self, key, value):
        if key in self.cache:
            self.cache.move_to_end(key)

        self.cache[key] = value

        if len(self.cache) > self.capacity:
            self.cache.popitem(last=False)

🔹 Complexity 
Operation - Complexity 
Get - O(1) 
Put - O(1) 

🔹 Interview Tip 
LRU cache is a FAANG-favorite system design question.

🚀 39. How do you check for balanced parentheses?

Use a stack.

🔹 Idea 
• Push opening brackets.
• When closing bracket appears: Check top of stack

🔹 Python Solution

python
def is_valid(s):
    stack = []

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

    for char in s:
        if char in mapping.values():
            stack.append(char)

        elif char in mapping:
            if not stack or stack.pop() != mapping[char]:
                return False

    return not stack

print(is_valid("({[]})"))

🔹 Output 
True 

🔹 Complexity 
Complexity - Value 
Time - O(n) 
Space - O(n) 

🔹 Uses 
Compilers 
Expression parsing 
Syntax validation 

🚀 40. How do you implement a circular queue?

Circular queue reuses empty spaces efficiently.

🔹 Visualization 
Front → [1,2,3,_,_] 

After dequeue + enqueue: 
[,2,3,4,] 

🔹 Python Implementation`

python
class CircularQueue:
    def init(self, size):
        self.queue = [None] * size
        self.front = 0
        self.rear = 0
        self.size = size
        self.count = 0

    def enqueue(self, value):
        if self.count == self.size:
            return "Full"

        self.queue[self.rear] = value
        self.rear = (self.rear + 1) % self.size
        self.count += 1

    def dequeue(self):
        if self.count == 0:
            return "Empty"

        value = self.queue[self.front]
        self.front = (self.front + 1) % self.size
        self.count -= 1

        return value
`


🔹 Complexity 
Operation - Complexity 
Enqueue - O(1) 
Dequeue - O(1) 

🔹 Real-World Uses 
CPU scheduling 
Streaming systems 
Buffers 
Embedded systems 

🔥 Double Tap ❤️ For Part-5
3
🧠 Things Senior Developers Do Differently

Break problems into smaller parts
Write code for humans, not just machines
Think about scalability early
Read error messages carefully
Reuse instead of rewrite
Focus on consistency over cleverness

React ❤️ for more insights like this
2
SQL Interview Roadmap – Step-by-Step Guide to Crack Any SQL Round 💼📊

Whether you're applying for Data Analyst, BI, or Data Engineer roles — SQL rounds are must-clear. Here's your focused roadmap:

1️⃣ Core SQL Concepts
🔹 Understand RDBMS, tables, keys, schemas
🔹 Data types, NULLs, constraints
🧠 Interview Tip: Be able to explain Primary vs Foreign Key.

2️⃣ Basic Queries
🔹 SELECT, FROM, WHERE, ORDER BY, LIMIT
🧠 Practice: Filter and sort data by multiple columns.

3️⃣ Joins – Very Frequently Asked!
🔹 INNER, LEFT, RIGHT, FULL OUTER JOIN
🧠 Interview Tip: Explain the difference with examples.
🧪 Practice: Write queries using joins across 2–3 tables.

4️⃣ Aggregations & GROUP BY
🔹 COUNT, SUM, AVG, MIN, MAX, HAVING
🧠 Common Question: Total sales per category where total > X.

5️⃣ Window Functions
🔹 ROW_NUMBER(), RANK(), DENSE_RANK(), LAG(), LEAD()
🧠 Interview Favorite: Top N per group, previous row comparison.

6️⃣ Subqueries & CTEs
🔹 Write queries inside WHERE, FROM, and using WITH
🧠 Use Case: Filtering on aggregated data, simplifying logic.

7️⃣ CASE Statements
🔹 Add logic directly in SELECT
🧠 Example: Categorize users based on spend or activity.

8️⃣ Data Cleaning & Transformation
🔹 Handle NULLs, format dates, string manipulation (TRIM, SUBSTRING)
🧠 Real-world Task: Clean user input data.

9️⃣ Query Optimization Basics
🔹 Understand indexing, query plan, performance tips
🧠 Interview Tip: Difference between WHERE and HAVING.

🔟 Real-World Scenarios
🧠 Must Practice:
• Sales funnel
• Retention cohort
• Churn rate
• Revenue by channel
• Daily active users

🧪 Practice Platforms
LeetCode (Easy–Hard SQL)
StrataScratch (Real business cases)
Mode Analytics (SQL + Visualization)
HackerRank SQL (MCQs + Coding)

💼 Final Tip:
Explain why your query works, not just what it does. Speak your logic clearly.

💬 Tap ❤️ for more!
2