Practice Strategy & Tips
Knowing how to solve problems is only half the battle. This lesson covers time management, pattern recognition, a study plan, and answers to the most common questions about coding interviews for AI/ML roles.
Time Management During the Interview
Most coding interviews are 45 minutes. Here is how to allocate your time for maximum impact:
| Phase | Time | What to Do | Common Mistakes |
|---|---|---|---|
| 1. Understand | 3–5 min | Restate the problem, ask about edge cases, clarify constraints (input size, value range, duplicates) | Jumping into code without asking questions |
| 2. Plan | 5–8 min | Describe brute force approach and its complexity. Then describe the optimal approach. Get interviewer buy-in before coding. | Starting to code the brute force without thinking about optimization |
| 3. Code | 15–20 min | Write clean, modular code. Use meaningful variable names. Talk through your logic as you code. | Writing in silence, using single-letter variables, no comments |
| 4. Test | 5–8 min | Trace through code with a simple example. Test edge cases (empty, single element, all same). Fix bugs calmly. | Saying "I think it works" without actually testing |
| 5. Discuss | 3–5 min | State final time/space complexity. Discuss trade-offs. Mention alternative approaches. | Not mentioning complexity at all |
Common Patterns Cheat Sheet
Most coding problems fall into one of these patterns. Learning to recognize the pattern is the fastest way to solve new problems.
| Pattern | When to Use | Key Data Structure | Time Complexity |
|---|---|---|---|
| Hash Map | Need O(1) lookup, counting, or grouping | dict, Counter, defaultdict | O(n) |
| Two Pointers | Sorted array, finding pairs, palindromes | Array (sorted) | O(n) |
| Sliding Window | Contiguous subarray/substring with constraint | Array + hash map | O(n) |
| Binary Search | Sorted data, monotonic condition, search on answer | Array (sorted) | O(log n) |
| Stack | Matching brackets, next greater element, undo operations | List (as stack) | O(n) |
| Monotonic Stack | Next greater/smaller, histogram problems | Stack of indices | O(n) |
| Fast & Slow Pointers | Cycle detection, middle of linked list | Linked list | O(n) |
| Greedy | Optimal substructure, interval problems, scheduling | Sorted array | O(n log n) |
| BFS | Shortest path (unweighted), level-order traversal | Queue (deque) | O(V + E) |
| DFS | Exhaustive search, connected components, backtracking | Stack / recursion | O(V + E) |
Pattern Recognition Decision Tree
# Mental decision tree for choosing the right pattern:
# 1. Is the input sorted?
# -> Binary Search or Two Pointers
# 2. Do I need O(1) lookup?
# -> Hash Map (dict/set)
# 3. Am I looking for a contiguous subarray?
# -> Sliding Window (if fixed/variable size constraint)
# -> Kadane's Algorithm (if max sum)
# 4. Am I dealing with intervals?
# -> Sort by start or end time -> Greedy or Merge Intervals
# 5. Do I need "next greater/smaller" element?
# -> Monotonic Stack
# 6. Am I traversing a linked list?
# -> Two pointers (fast/slow for cycle, gap for nth from end)
# 7. Can I make locally optimal choices?
# -> Greedy (verify greedy choice property first!)
# 8. Do I need to try all possibilities?
# -> BFS (shortest), DFS/Backtracking (all solutions)
Python Quick Reference for Interviews
# ====== ESSENTIAL PYTHON OPERATIONS ======
# --- Strings ---
s = "hello world"
s.split() # ['hello', 'world']
s.replace('l', 'r') # 'herro worrd'
s[::-1] # 'dlrow olleh' (reverse)
s.startswith('hel') # True
s.isalnum() # False (has space)
ord('a') # 97
chr(97) # 'a'
# --- Lists ---
nums = [3, 1, 4, 1, 5]
nums.sort() # In-place: [1, 1, 3, 4, 5]
sorted(nums) # Returns new sorted list
nums.sort(key=lambda x: -x) # Descending
nums.append(9) # O(1)
nums.pop() # O(1) remove last
nums.pop(0) # O(n) remove first - AVOID
max(nums), min(nums) # O(n) each
sum(nums) # O(n)
# --- Deque (for O(1) both ends) ---
from collections import deque
q = deque()
q.append(1) # Right: O(1)
q.appendleft(0) # Left: O(1)
q.pop() # Right: O(1)
q.popleft() # Left: O(1)
# --- Heap (min-heap) ---
import heapq
h = [3, 1, 4, 1, 5]
heapq.heapify(h) # O(n) - convert to min-heap
heapq.heappush(h, 2) # O(log n)
heapq.heappop(h) # O(log n) - returns smallest
heapq.nlargest(3, h) # Top 3 largest
# For max-heap: negate values
max_heap = [-x for x in nums]
heapq.heapify(max_heap)
largest = -heapq.heappop(max_heap)
# --- Infinity ---
float('inf') # Positive infinity
float('-inf') # Negative infinity
# --- Integer limits ---
import sys
sys.maxsize # Largest int (platform-dependent)
# --- Useful itertools ---
from itertools import combinations, permutations, product
list(combinations([1,2,3], 2)) # [(1,2), (1,3), (2,3)]
list(permutations([1,2,3], 2)) # [(1,2), (1,3), (2,1), ...]
# --- Bisect (binary search on sorted list) ---
import bisect
arr = [1, 3, 5, 7]
bisect.bisect_left(arr, 5) # 2 (index where 5 IS)
bisect.bisect_right(arr, 5) # 3 (index AFTER 5)
bisect.insort(arr, 4) # Insert maintaining sort
2-Week Study Plan for AI/ML Engineers
| Day | Topic | Lesson | Problems |
|---|---|---|---|
| 1 | Foundations + Python tips | Lesson 1 | Contains duplicate, basic complexity analysis |
| 2–3 | Arrays & Strings | Lesson 2 | Two sum, max subarray, rotate, anagram, sliding window |
| 4–5 | Hash Maps & Sets | Lesson 3 | Top K frequent, group anagrams, LRU cache, TF-IDF |
| 6 | Stacks & Queues | Lesson 4 | Valid parentheses, min stack, monotonic stack |
| 7 | Linked Lists | Lesson 5 | Reverse, cycle detect, merge sorted, remove nth |
| 8–9 | Binary Search | Lesson 6 | Rotated array, find peak, 2D matrix, median, threshold |
| 10–11 | Greedy Algorithms | Lesson 7 | Intervals, task scheduler, jump game, platforms |
| 12–13 | Review & practice | All lessons | Redo problems from memory, time yourself |
| 14 | Mock interview | This page | Pick 2 random problems, solve in 45 min total |
Frequently Asked Questions
Quality over quantity. Solving 50–100 problems well (understanding the pattern, being able to solve them again from memory) is better than rushing through 300 problems. Focus on the patterns covered in this course — they cover 80% of what you will encounter in AI/ML interviews. The 33 problems in this course are a solid foundation.
Yes and no. The DSA problems are similar (arrays, hash maps, binary search), but AI/ML interviews tend to favor medium-difficulty problems rather than hard LeetCode questions. The emphasis is on clean code, explaining your approach, and connecting solutions to real-world ML applications. You might also get ML-specific coding problems (implement linear regression, build a data pipeline).
Python is the best choice for AI/ML coding interviews. It is the standard language in the ML ecosystem, and interviewers expect it. Python's concise syntax lets you write solutions faster, and built-in data structures (dict, set, Counter, deque) eliminate boilerplate. The only exception is quant/trading firms, which sometimes prefer C++.
Do not panic. (1) Start with the brute force approach — even a working O(n²) solution shows competence. (2) Explain your thought process — interviewers give partial credit for good reasoning. (3) Ask for hints — this shows collaboration skills. (4) If you get a hint, build on it rather than abandoning your approach. Many candidates pass without finding the optimal solution because they demonstrated strong problem-solving skills.
Very important. You should state the time and space complexity of every solution you write or propose. Interviewers use it to evaluate whether you understand scalability. At minimum, know these: hash map operations are O(1) average, sorting is O(n log n), nested loops are O(n²), binary search is O(log n). Always explain WHY the complexity is what it is, not just the notation.
DP is less commonly tested in ML interviews compared to SWE interviews, but it can appear at Google and other top companies. Focus on understanding the concept (overlapping subproblems, optimal substructure) and know 2–3 classic problems (fibonacci, coin change, longest common subsequence). The greedy algorithms in this course are tested more frequently than DP at most AI companies.
Practice under realistic conditions: set a 45-minute timer, use a plain text editor (not an IDE), and solve problems without running code. Do mock interviews with friends or use platforms like Pramp. During the actual interview, take a deep breath before starting, write pseudocode first, and remember that the interviewer wants you to succeed. They are evaluating whether they would enjoy working with you.
After completing this course: (1) Practice on LeetCode — filter by the patterns you learned here (hash map, binary search, greedy). (2) Read "Cracking the Coding Interview" for additional problem sets. (3) Use NeetCode's roadmap for a visual study path. (4) Do timed mock interviews on Pramp or interviewing.io. (5) Review the ML-specific courses on this platform for the ML coding round.
Final Checklist Before Your Interview
Technical Readiness
- Can solve 2 medium problems in 45 minutes
- Know all 10 patterns from the cheat sheet
- Can state Big-O for every solution
- Comfortable with Python collections module
- Can write code without IDE autocomplete
Communication Readiness
- Practice thinking aloud while coding
- Can explain brute force before optimizing
- Comfortable asking clarifying questions
- Can discuss trade-offs (time vs. space)
- Know how to ask for and use hints
Logistics
- Test your camera, microphone, and internet
- Have water and a notepad nearby
- Know the interview platform (CoderPad, HackerRank)
- Prepare 2–3 questions to ask the interviewer
- Get a good night's sleep
Lilly Tech Systems