Coding Interview Questions: 12 Patterns to Master (With Examples)

By the HiReXL Career Team

There are thousands of coding problems online, but most interview questions are variations of a small number of patterns. Learning to recognize these patterns is far more effective than memorizing solutions. Here are 12 patterns behind the most common coding interview questions, with examples of each.

1. Hash maps and sets

Use a hash map when you need fast lookups or counting.

Example questions: Two Sum, find duplicates, group anagrams, first non-repeating character.

Key idea: trade memory for speed — O(n) instead of O(n²).

2. Two pointers

Move two indexes through a sorted array or string toward each other or in the same direction.

Example questions: valid palindrome, pair with target sum in a sorted array, remove duplicates in place, container with most water.

3. Sliding window

Maintain a window of elements that expands and shrinks as you scan.

Example questions: longest substring without repeating characters, maximum sum subarray of size k, minimum window substring.

4. Prefix sums

Precompute running totals to answer range queries quickly.

Example questions: subarray sum equals k, range sum queries, product of array except self.

5. Stacks and queues

Stacks handle nested or “most recent” logic; queues handle order.

Example questions: valid parentheses, next greater element, implement a queue using stacks, daily temperatures (monotonic stack).

Search sorted data — or a range of possible answers — in O(log n).

Example questions: search in rotated sorted array, find first and last position, minimum capacity to ship packages within D days.

7. Linked lists

Practice pointer manipulation carefully.

Example questions: reverse a linked list, detect a cycle (fast and slow pointers), merge two sorted lists, remove the nth node from the end.

8. Trees and recursion

Most tree problems use depth-first recursion.

Example questions: maximum depth of a binary tree, validate a binary search tree, lowest common ancestor, level order traversal.

9. Graphs: BFS and DFS

Model problems as nodes and edges.

Example questions: number of islands, clone graph, course schedule (topological sort), shortest path in a grid with BFS.

10. Heaps (priority queues)

Use heaps to repeatedly get the smallest or largest element.

Example questions: top k frequent elements, kth largest element, merge k sorted lists, meeting rooms.

11. Intervals

Sort by start time, then merge or compare.

Example questions: merge intervals, insert interval, non-overlapping intervals, meeting room scheduling.

12. Dynamic programming

Break problems into overlapping subproblems and store results.

Example questions: climbing stairs, coin change, longest increasing subsequence, house robber, longest common subsequence.

Tip: start with a recursive solution, add memoization, then convert to a bottom-up table if needed.

How to practice effectively

  1. Learn one pattern at a time and solve 5–10 problems for it
  2. Time yourself — aim for 20–30 minutes per medium problem
  3. Explain your approach out loud as if an interviewer were listening
  4. Review solutions after solving, and note better approaches
  5. Revisit problems a week later to confirm you remember the pattern

Pair this with our technical interview preparation plan. For language-specific prep, see Python, Java and JavaScript interview questions.

Know your Big O

Be ready to state the time and space complexity of every solution. Common complexities: O(1), O(log n), O(n), O(n log n) for sorting, and O(n²) for nested loops. Interviewers often ask, “Can you do better?” — knowing complexity tells you whether improvement is possible.

Frequently asked questions

How many coding problems should I practice?

Quality matters more than quantity. Many candidates do well after solving 100–150 problems across all major patterns with careful review.

Which language should I use in coding interviews?

Use the language you know best. Python is popular because it is concise, but Java, JavaScript, C++ and others are all accepted.

Are coding interviews only for software engineers?

No. Data engineers, ML engineers, SREs and some DevOps roles also include coding interviews, though often with more practical problems.

Got the interview? Make sure your resume tells the same story.

Interviewers read your resume right before they talk to you. HiReXL aligns it with the job description’s keywords so your experience and your answers match. HiReXL is built by 4As Consulting, a cloud and DevOps consulting firm. Looking for your next role? Submit your resume for open positions with PanAmerica Inc.

See how HiReXL helps →