MyInternships.in
20 QUESTIONS · JUNIOR TO SENIOR · WITH ANSWERS

DSA and Coding Interview Patterns Interview Questions and Answers

The pattern-based way to prepare for a software engineering internship coding round — Blind 75, NeetCode 150, sliding window, two pointers, dynamic programming, graphs and trees — with the reasoning an interviewer is actually listening for.

12 junior8 mid-level0 senior

How to use this set

Every question below is written the way an interviewer actually phrases it, followed by a model answer you could say out loud in 30–60 seconds, and — where it helps — the reason the question is asked and the trap most candidates fall into. Questions are tagged Junior, Mid or Senior so you can skip to your level.

This is one of 9 topic sets in the complete Internship Prep interview questions guide. Work through the fundamentals first, then the services your target role actually uses.

1
Junior level

How many LeetCode problems should I actually solve before an internship interview?

Answer: Between 120 and 200 problems solved properly is far more effective than 500 rushed. Work through a curated list — Blind 75 first, then NeetCode 150 — because they are chosen to cover each pattern once rather than to repeat the same idea.

Why interviewers ask this: Interviewers are testing pattern recognition, not recall. A candidate who has solved 150 problems across all patterns will recognise an unseen question; one who has solved 500 problems in three patterns will freeze on the fourth. Track which pattern each problem belongs to, and revisit any pattern where you needed the solution.

2
Junior level

What is the difference between Blind 75 and NeetCode 150, and which should I do first?

Answer: Blind 75 is the minimum viable coverage — one representative problem per core pattern. NeetCode 150 is a superset that adds a second and third problem per pattern so the pattern actually sticks. Do Blind 75 first to map the territory, then NeetCode 150 to build fluency.

Why interviewers ask this: If you have under four weeks, finish Blind 75 and revise it twice rather than starting NeetCode 150 and leaving it half done. Partial coverage of every pattern beats complete coverage of half of them.

3
Junior level

When do I use the sliding window pattern?

Answer: Use sliding window when the question asks for the best or a valid contiguous subarray or substring — longest, shortest, maximum sum, or one satisfying a constraint. It turns an O(n²) scan of every window into a single O(n) pass by expanding the right edge and shrinking the left.

Why interviewers ask this: The tell is the words "contiguous", "substring" or "subarray" plus an optimisation or constraint. The trap is forgetting to shrink: a window that only ever grows is just a prefix sum. Practise "Longest Substring Without Repeating Characters" and "Minimum Window Substring" — between them they cover both the fixed and variable window forms.

Python
def longest_unique(s):
    seen, left, best = {}, 0, 0
    for right, ch in enumerate(s):
        if ch in seen and seen[ch] >= left:
            left = seen[ch] + 1      # shrink past the duplicate
        seen[ch] = right
        best = max(best, right - left + 1)
    return best
4
Junior level

When is the two-pointer approach the right call?

Answer: Two pointers fit when the input is sorted (or can be sorted) and you are looking for a pair or triplet meeting a condition, or when you are comparing the array from both ends. It replaces a nested loop with one linear pass.

Why interviewers ask this: "Two Sum II", "3Sum", "Container With Most Water" and palindrome checks are the canonical set. The insight to state out loud is why moving a pointer is safe: in "Container With Most Water", moving the taller wall can never improve the answer, so moving the shorter one loses nothing.

5
Mid level

How do I recognise a dynamic programming problem in an interview?

Answer: Look for a question asking for the number of ways, the minimum or maximum cost, or whether something is achievable, where the answer for n depends on answers for smaller inputs and the same subproblem recurs. If a brute-force recursion would recompute the same state, it is DP.

Why interviewers ask this: Say the recurrence out loud before you code — "dp[i] is the best answer using the first i items, and dp[i] = max(dp[i-1], dp[i-2] + nums[i])". Interviewers give substantial credit for a correct recurrence even if you run out of time to optimise the space. Start top-down with memoisation; converting to bottom-up is mechanical afterwards.

Python
# House Robber — the canonical 1D DP
def rob(nums):
    prev2, prev1 = 0, 0
    for n in nums:
        prev2, prev1 = prev1, max(prev1, prev2 + n)
    return prev1
6
Mid level

Which DP patterns cover most interview questions?

Answer: Six cover the large majority: 1D linear DP (House Robber, Climbing Stairs), 0/1 knapsack and subset sum, unbounded knapsack (Coin Change), longest common subsequence on two strings, longest increasing subsequence, and DP on grids (Unique Paths, Minimum Path Sum).

Why interviewers ask this: Interns are rarely asked interval DP or bitmask DP. Time spent on those is better spent making the six above automatic, since one of them appears in most internship DP rounds.

7
Mid level

When do I use BFS versus DFS on a graph?

Answer: Use BFS when you need the shortest path in an unweighted graph or a level-by-level traversal, because BFS reaches every node by the fewest edges. Use DFS for connectivity, cycle detection, topological sort and any problem where you must explore a whole branch before backtracking.

Why interviewers ask this: The most common intern graph question is "number of islands", which either works. The distinguishing question is "shortest path in a maze" — DFS finds *a* path, BFS finds the *shortest*, and choosing DFS there is a correctness bug, not a style choice.

Python
from collections import deque
def shortest_path(grid, start, goal):
    q, seen = deque([(start, 0)]), {start}
    while q:
        (r, c), d = q.popleft()
        if (r, c) == goal: return d
        for nr, nc in ((r+1,c), (r-1,c), (r,c+1), (r,c-1)):
            if 0 <= nr < len(grid) and 0 <= nc < len(grid[0]) \
               and grid[nr][nc] != "#" and (nr, nc) not in seen:
                seen.add((nr, nc)); q.append(((nr, nc), d + 1))
    return -1
8
Mid level

What graph problems should I be able to write from memory?

Answer: Number of Islands, Clone Graph, Course Schedule (cycle detection plus topological sort), Word Ladder (BFS shortest path), and Union-Find for connected components. Dijkstra is worth knowing but is asked less often at intern level.

Why interviewers ask this: Course Schedule is the highest-value one: it forces you to model a real dependency problem as a graph, which is exactly the reasoning step interviewers want to see.

9
Mid level

Which binary tree traversals do I need, and when is each used?

Answer: Know inorder, preorder, postorder and level-order, recursively and iteratively. Inorder on a BST yields sorted order; preorder serialises a tree; postorder is for bottom-up work like computing height or deleting; level-order is BFS and answers anything phrased per level.

Why interviewers ask this: The pattern that unlocks most tree questions is postorder: return the information the parent needs from each child. Diameter, balanced-tree checks and lowest common ancestor all fall out of it.

Python
def diameter(root):
    best = 0
    def depth(node):                 # postorder: children first
        nonlocal best
        if not node: return 0
        l, r = depth(node.left), depth(node.right)
        best = max(best, l + r)      # path through this node
        return 1 + max(l, r)         # what the parent needs
    depth(root)
    return best
10
Mid level

When would a trie be the right data structure?

Answer: Use a trie when you need prefix operations over a set of strings — autocomplete, "does any word start with this", or word-search over a board. It gives O(L) lookup in the length of the word regardless of how many words are stored.

Why interviewers ask this: The interview tell is the word "prefix" or a dictionary being searched repeatedly. Implement Trie and Word Search II are the two standard questions; the second is the one that shows why a trie beats checking each word separately.

11
Junior level

What bit manipulation should I know for an internship interview?

Answer: XOR to find the single non-repeating number, n & (n-1) to clear the lowest set bit and count set bits, checking a bit with (n >> i) & 1, and using a bitmask as a small set. That covers nearly every intern-level bit question.

Why interviewers ask this: The two properties worth memorising are x ^ x == 0 and x ^ 0 == x — they make "Single Number" a one-liner. Do not over-invest here: bit manipulation is a small slice of most interview loops.

Python
def single_number(nums):
    out = 0
    for n in nums: out ^= n   # pairs cancel, the loner survives
    return out
12
Junior level

How do I analyse time and space complexity out loud?

Answer: State the size variables first ("n is the number of nodes, m the edges"), then count the dominant repeated work, then state the extra space excluding the output. Give the answer as a bound with a one-line justification, not just a symbol.

Why interviewers ask this: Say "O(n log n) because we sort once and then do a linear pass" rather than "O(n log n)". Two frequent errors: forgetting that recursion costs stack space, and calling a solution O(n) when it builds an O(n) intermediate list per element.

Preparing for a Internship Prep role?

Browse live Internship Prep cloud internships and fresher jobs hiring across India right now.

Browse Internships
13
Junior level

What are the time complexities of common sorting algorithms?

Answer: Merge sort is O(n log n) always, with O(n) extra space and stability. Quicksort averages O(n log n) but degrades to O(n²) on bad pivots and sorts in place. Heap sort is O(n log n) in place but unstable. Counting and radix sort are O(n + k) and only work on bounded integer keys.

Why interviewers ask this: The follow-up is usually "which does your language use?" — Python's sort and Java's sort for objects are Timsort, a stable merge/insertion hybrid; Java's sort for primitives is a dual-pivot quicksort, which is why it is not stable.

14
Junior level

How should I structure the first five minutes of a coding interview?

Answer: Restate the problem in your own words, ask about input size and edge cases, give one concrete example and walk it through, then state your approach and its complexity — and only then write code. Confirm the approach before typing.

Why interviewers ask this: Candidates who code immediately and get it right still score lower than candidates who state the approach first, because the interviewer is grading communication and problem-solving as separate axes. It also protects you: if the approach is wrong, you lose two minutes rather than twenty.

15
Junior level

I am stuck in the middle of a coding round. What is the right move?

Answer: Say what you have tried, what specifically is blocking you, and what you would try next. Then propose the brute-force solution and offer to optimise it. A working brute force with a stated path to improvement scores far better than silence.

Why interviewers ask this: Interviewers are allowed to give hints and expect to. Going quiet for four minutes reads as an inability to collaborate, which is a stronger negative signal than not finding the optimal solution.

16
Junior level

How do I practise so that the pattern sticks?

Answer: After solving, close the editor and re-solve the same problem from scratch two days later. Write one line naming the pattern and the trigger that should have told you to use it. Review that list weekly instead of solving new problems every day.

Why interviewers ask this: This is spaced retrieval and it is the single highest-return change most candidates can make. Solving 200 problems once produces recognition of about 200 problems; solving 120 problems three times produces recognition of the underlying patterns.

17
Junior level

Should I use Python, Java or C++ in the interview?

Answer: Use the language you are fastest and most accurate in, unless the role explicitly requires another. Python has the least syntax overhead for interview problems; C++ is expected for quant and systems roles; Java is fine everywhere.

Why interviewers ask this: Whatever you pick, know its collections cold — in Python that is dict, set, collections.deque, heapq and sorted with a key; fumbling the standard library costs more time than any language difference.

18
Mid level

What does a heap or priority queue get used for in interviews?

Answer: Top-K problems, merging K sorted lists, running medians, and any greedy algorithm that repeatedly needs the current smallest or largest element. It gives O(log n) insert and extract instead of re-sorting.

Why interviewers ask this: "Kth largest element" is the canonical question. Note that Python's heapq is a min-heap only — push negated values for a max-heap, a detail that trips up candidates under time pressure.

Python
import heapq
def k_largest(nums, k):
    h = []
    for n in nums:
        heapq.heappush(h, n)
        if len(h) > k: heapq.heappop(h)   # keep only the k biggest
    return h[0]
19
Mid level

How much do intern interviews weight recursion and backtracking?

Answer: Moderately — expect one backtracking question in a longer loop. Subsets, Permutations, Combination Sum and N-Queens cover the template: choose, recurse, un-choose.

Why interviewers ask this: Write the template once and reuse it. The commonest bug is mutating a shared list and appending it without copying, so every result ends up identical.

Python
def subsets(nums):
    out, path = [], []
    def bt(i):
        if i == len(nums):
            out.append(path[:])      # COPY, or every row aliases path
            return
        bt(i + 1)                    # skip nums[i]
        path.append(nums[i]); bt(i + 1); path.pop()
    bt(0)
    return out
20
Junior level

What is a realistic four-week DSA plan alongside college?

Answer: Week 1: arrays, strings, hashing, two pointers, sliding window. Week 2: linked lists, stacks, queues, binary search. Week 3: trees, graphs, heaps. Week 4: dynamic programming plus two full timed mock interviews. Two to three problems a day, reviewed, beats ten skimmed.

Why interviewers ask this: Put the mocks in week 4 rather than at the end of preparation, so you still have time to fix what they expose. Most candidates discover their gap is talking while coding, not the algorithms.

Continue your Internship Prep interview prep

See all 9 Internship Prep topics →

Ready to apply for Internship Prep roles?

Cloud internships and fresher jobs across India — filtered to roles that actually name Internship Prep in the requirements.

Browse Internships

Canonical: https://myinternships.in/tech-internship-prep/dsa-coding-patterns