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
๐Ÿ—„๏ธ ๐—ง๐—ผ๐—ฝ ๐Ÿฑ ๐—™๐—ฅ๐—˜๐—˜ ๐—ฆ๐—ค๐—Ÿ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐Ÿš€

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
๐—”๐—œ/๐— ๐—Ÿ ๐—ฟ๐—ผ๐—น๐—ฒ๐˜€ ๐—ฎ๐—ฟ๐—ฒ ๐—ณ๐—ฎ๐˜€๐˜๐—ฒ๐˜€๐˜-๐—ด๐—ฟ๐—ผ๐˜„๐—ถ๐—ป๐—ด ๐—ฐ๐—ฎ๐—ฟ๐—ฒ๐—ฒ๐—ฟ ๐—ณ๐—ถ๐—ฒ๐—น๐—ฑ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ๐Ÿ˜

The demand is real, salaries are high, and the talent gap is wide open

Enrol for AI/ML Certification Program by CCE, IIT Mandi!

Eligibility: Open to everyone
Duration: 6 Months
Program Mode: Online
Taught By: IIT Mandi Professors

Deadline :- 23rd May

๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—ก๐—ผ๐˜„๐Ÿ‘‡ :-

https://pdlink.in/4nmI024
.
๐ŸŽ“Get Placement Assistance With 5000+ Companies
๐Ÿš€ Coding Interview Questions with Answers โ€” Part 6

๐Ÿ“Š Sorting, Searching & Dynamic Programming

๐Ÿš€ 51. How do you implement quicksort and mergesort? 
Both are divide-and-conquer sorting algorithms.

๐Ÿ”น Quicksort 
๐Ÿ”น Idea 
1. Pick pivot
2. Partition array
3. Recursively sort halves

๐Ÿ”น Python Quicksort 

def quicksort(arr):
    if len(arr) <= 1:
        return arr

    pivot = arr[len(arr)//2]

    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]

    return quicksort(left) + middle + quicksort(right)

print(quicksort([5,2,8,1,3]))


๐Ÿ”น Complexity 
Case: Best/Average โ†’ Complexity: O(n log n) 
Case: Worst โ†’ Complexity: O(nยฒ) 

๐Ÿ”น Mergesort 
๐Ÿ”น Idea 
1. Split array
2. Sort recursively
3. Merge sorted halves

๐Ÿ”น Python Mergesort 

def mergesort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr)//2

    left = mergesort(arr[:mid])
    right = mergesort(arr[mid:])

    return merge(left, right)

def merge(left, right):
    result = []
    i = j = 0

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

    result.extend(left[i:])
    result.extend(right[j:])

    return result


๐Ÿ”น Complexity 
Case: All Cases โ†’ Complexity: O(n log n) 

๐Ÿ”น Interview Tip 
Mergesort is stable. Quicksort is usually faster in practice.

๐Ÿš€ 52. How do you implement binary search in a rotated sorted array? 
Example: 
Target: 0[4][5][6][7][0][1][2] 

๐Ÿ”น Key Idea 
One half is always sorted. 

๐Ÿ”น Python Solution 

def search(nums, target):
    left, right = 0, len(nums)-1

    while left <= right:
        mid = (left + right)//2

        if nums[mid] == target:
            return mid

        if nums[left] <= nums[mid]:
            if nums[left] <= target < nums[mid]:
                right = mid - 1
            else:
                left = mid + 1
        else:
            if nums[mid] < target <= nums[right]:
                left = mid + 1
            else:
                right = mid - 1

    return -1


๐Ÿ”น Complexity 
Time: O(log n) 
Space: O(1) 

๐Ÿ”น Interview Tip 
Very common medium-level interview problem.

๐Ÿš€ 53. How do you implement insertion sort and when is it useful? 
Insertion sort inserts elements into correct position.

๐Ÿ”น Python Solution 

def insertion_sort(arr):
    for i in range(1, len(arr)):
        key = arr[i]
        j = i - 1

        while j >= 0 and arr[j] > key:
            arr[j+1] = arr[j]
            j -= 1

        arr[j+1] = key

    return arr


๐Ÿ”น Complexity 
Case: Best โ†’ Complexity: O(n) 
Case: Average/Worst โ†’ Complexity: O(nยฒ) 

๐Ÿ”น When Useful? 
โœ… Small datasets 
โœ… Nearly sorted arrays 
โœ… Online sorting 

๐Ÿ”น Interview Tip 
Simple but important for fundamentals.

๐Ÿš€ 54. How do you find the k-th largest element?

๐Ÿ”น Efficient Approach 
Use: Min Heap OR Quickselect 

๐Ÿ”น Heap Solution 

import heapq

def kth_largest(nums, k):
    return heapq.nlargest(k, nums)[-1]

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


๐Ÿ”น Output 


๐Ÿ”น Complexity 
Time: O(n log k) 
Space: O(k) 

๐Ÿ”น Interview Tip 
Quickselect is often asked as optimization.

๐Ÿš€ 55. What is the difference between DFS and backtracking? 
Both use recursion, but purpose differs.

๐Ÿ”น DFS 
Goal: Traverse/search graph or tree 

๐Ÿ”น Backtracking 
Goal: Try all possibilities and undo choices 

๐Ÿ”น Example Problems 
DFS: Tree traversal, Graph traversal 
Backtracking: N-Queens, Sudoku, Permutations 

๐Ÿ”น Key Difference 
DFS: Traversal, No undo step 
Backtracking: Decision making, Includes undo step 

๐Ÿ”น Interview Tip 
Backtracking = DFS + constraint checking + undoing choices.

๐Ÿš€ 56. How do you solve the โ€œN-Queensโ€ problem? 
Place N queens so none attack each other.

๐Ÿ”น Backtracking Solution

def solve_n_queens(n):
    board = [-1] * n
    result = []
โค1
def is_safe(row, col):
    for r in range(row):
        c = board[r]
        if c == col or abs(c-col) == abs(r-row):
            return False
    return True

def backtrack(row):
    if row == n:
        result.append(board[:])
        return

    for col in range(n):
        if is_safe(row, col):
            board[row] = col
            backtrack(row + 1)

backtrack(0)
return result

๐Ÿ”น Complexity
O(N!)

๐Ÿ”น Interview Tip
Classic backtracking interview problem.

๐Ÿš€ 57. How do you generate subsets / permutations?

๐Ÿ”น Subsets
๐Ÿ”น Backtracking Solution
def subsets(nums):
    result = []

    def backtrack(start, path):
        result.append(path)

        for i in range(start, len(nums)):
            backtrack(i + 1, path + [nums[i]])

    backtrack(0, [])
    return result

๐Ÿ”น Permutations
def permutations(nums):
    result = []

    def backtrack(path, remaining):
        if not remaining:
            result.append(path)

        for i in range(len(remaining)):
            backtrack(
                path + [remaining[i]],
                remaining[:i] + remaining[i+1:]
            )

    backtrack([], nums)
    return result

๐Ÿ”น Interview Tip
Backtracking patterns are extremely important.

๐Ÿš€ 58. How do you solve coin-change / unbounded-knapsack?

๐Ÿ”น Coin Change Problem
Goal: Minimum coins to form amount

๐Ÿ”น Dynamic Programming Solution
def coin_change(coins, amount):
    dp = [float('inf')] * (amount + 1)
    dp[0] = 0

    for coin in coins:
        for i in range(coin, amount + 1):
            dp[i] = min(
                dp[i],
                dp[i - coin] + 1
            )

    return dp[amount] if dp[amount] != float('inf') else -1

๐Ÿ”น Complexity
Time: O(amount ร— coins) 
Space: O(amount)

๐Ÿ”น Interview Tip
Very popular DP interview question.

๐Ÿš€ 59. How do you compute Fibonacci efficiently (DP vs matrix exponentiation)?

๐Ÿ”น DP Solution
def fib(n):
    if n <= 1:
        return n

    a, b = 0, 1
    for _ in range(2, n + 1):
        a, b = b, a + b

    return b

๐Ÿ”น Complexity
Time: O(n) 
Space: O(1)

๐Ÿ”น Matrix Exponentiation
Uses matrix power. 
Complexity: O(log n) 
Very efficient for huge numbers.

๐Ÿ”น Interview Tip
Interviewers may ask optimization beyond DP.

๐Ÿš€ 60. How do you implement longest increasing subsequence (LIS)?

๐Ÿ”น DP Solution
def lis(nums):
    dp = [1] * len(nums)

    for i in range(len(nums)):
        for j in range(i):
            if nums[i] > nums[j]:
                dp[i] = max(dp[i], dp[j] + 1)

    return max(dp)

๐Ÿ”น Complexity
Time: O(nยฒ) 
Space: O(n)

๐Ÿ”น Optimized LIS
Uses: Binary search + Greedy 
Complexity: O(n log n)

๐Ÿ”น Interview Tip
LIS is one of the most important DP problems.

๐Ÿ”ฅ Double Tap โค๏ธ For Part-7
โค3
๐——๐—ฎ๐˜๐—ฎ ๐—ฆ๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐˜„๐—ถ๐˜๐—ต ๐—”๐—œ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ | ๐Ÿญ๐Ÿฌ๐Ÿฌ% ๐—๐—ผ๐—ฏ ๐—”๐˜€๐˜€๐—ถ๐˜€๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ๐Ÿ˜

Build Python, Machine Learning, and AI Skills

๐Ÿ’ซ60+ Hiring Drives Every Month | Receive 1-on-1 mentorship

12.65 Lakhs Highest Salary | 500+ Partner Companies

๐—•๐—ผ๐—ผ๐—ธ ๐—ฎ ๐—™๐—ฅ๐—˜๐—˜ ๐—ฆ๐—ฒ๐˜€๐˜€๐—ถ๐—ผ๐—ป :- ๐Ÿ‘‡:-

 Online :- https://pdlink.in/4fdWxJB

๐Ÿ”น Hyderabad :- https://pdlink.in/4kFhjn3

๐Ÿ”น Pune:-  https://pdlink.in/45p4GrC

๐Ÿ”น Noida :-  https://linkpd.in/DaNoida

Hurry Up ๐Ÿƒโ€โ™‚๏ธ! Limited seats are available.
โค1