Skip to main content

Coding Techniques

Not every coding interview problem is about applying a well-known algorithm or memorizing a specific data structure.

In fact, many interview questions are solved using ad-hoc, commonly encountered coding techniques—patterns of logic that don’t belong to a single algorithmic category but show up again and again across problems.

These techniques are extremely popular in interviews because they test what companies actually care about:

  • Can you reason through a problem step by step?
  • Can you derive an efficient solution from constraints?
  • Can you handle edge cases and tricky inputs?
  • Can you explain your thinking clearly as you code?

Mastering these techniques is essential for coding interviews, especially Two Pointers and Sliding Window, which appear disproportionately often in real interview loops.


Why Coding Techniques Matter in Interviews

Interviewers often prefer coding techniques over textbook algorithms because:

  • They don’t reward memorization
  • They force candidates to reason about state, boundaries, and invariants
  • They expose gaps in edge-case thinking
  • They show how well someone can translate problem constraints into code

Many candidates get stuck because they keep asking themselves:

“What algorithm is this?”

When the better question is:

“What state do I need to track, and how does it evolve?”

That’s where coding techniques come in.


Commonly Tested Coding Techniques

Below are the most important coding techniques you’ll encounter in interviews.

Two Pointers

Two pointers involves maintaining two indices that move through a data structure—often from opposite ends or at different speeds.

When to use it:

  • Sorted arrays or strings
  • Pair or triplet problems
  • Removing duplicates
  • Reversing or partitioning data

Key idea:

Use pointer movement to reduce unnecessary comparisons and avoid nested loops.


Sliding Window

Sliding window is used when working with contiguous subarrays or substrings while maintaining a running state.

When to use it:

  • Subarray / substring problems
  • Maximum or minimum over a range
  • Frequency counting
  • Constraint-based windows (e.g., “at most k distinct characters”)

Key idea:

Expand the window to include new elements, and shrink it when constraints are violated.

This technique is especially important—many interviewees fail sliding window problems not because of complexity, but because of incorrect window updates and edge cases.


Fast and Slow Pointers

Also known as the tortoise and hare technique, this pattern uses pointers moving at different speeds.

When to use it:

  • Cycle detection
  • Linked list problems
  • Finding middle elements
  • Detecting repeating states

Key idea:

If a cycle exists, the fast pointer will eventually meet the slow pointer.


Sweep Line

The sweep line technique processes events in a sorted order, typically along a timeline or number line.

When to use it:

  • Interval overlap problems
  • Scheduling conflicts
  • Range queries
  • Counting active intervals

Key idea:

Convert intervals into events (start/end), sort them, and process changes incrementally.


High-Level Comparison of Coding Techniques

TechniqueCommon InputsTypical Use CasesTime ComplexitySpace Complexity
Two PointersArrays, stringsPairs, partitions, reversalsO(n)O(1)
Sliding WindowArrays, stringsSubarrays, substrings, frequency trackingO(n)O(1)–O(k)
Fast & Slow PointersLinked lists, arraysCycle detection, middle elementO(n)O(1)
Sweep LineIntervals, rangesOverlaps, scheduling, eventsO(n log n)O(n)

Note: These techniques often replace brute-force O(n²) solutions with linear or near-linear ones.


Why Interviewers Love These Problems

Coding technique problems are popular because they:

  • Reveal how candidates think, not what they’ve memorized
  • Force careful edge case handling
  • Require clear invariants and pointer movement logic
  • Make it easy to probe with follow-ups:
    • “What if the input is empty?”
    • “What if all values are the same?”
    • “Can you do this in constant space?”

Strong candidates stand out by:

  • Talking through pointer updates
  • Explaining why the window grows or shrinks
  • Catching off-by-one errors early
  • Testing their logic against corner cases

Handling Test and Edge Cases

Coding technique problems often fail not because of the wrong idea, but because of missed edge cases. Interviewers pay close attention to how you reason about correctness.

1. Start With Minimal Inputs

Always consider:

  • Empty input
  • Single-element input
  • Smallest valid window or range

Ask: Do my pointers move? Should I return early?


2. Define Clear Pointer Invariants

Be explicit about:

  • What each pointer represents
  • When the window is valid or invalid
  • Whether boundaries are inclusive or exclusive

Unclear invariants lead to fragile code.


3. Walk Through One Example

Step through a concrete input and track:

  • Pointer movement
  • State updates (counts, sums, sets)
  • Boundary transitions

This quickly exposes off-by-one and update-order bugs.


4. Test Boundary Transitions

Most bugs happen when:

  • A window becomes valid or invalid
  • Pointers cross
  • Intervals start or end at the same point

Be precise about update order.


5. Say Your Tests Out Loud

Strong candidates narrate edge cases:

  • “Empty input returns early”
  • “Shrink window when constraint breaks”
  • “Fast reaching null means no cycle”

This signals correctness and confidence.


Final Takeaway

Coding techniques are the glue that connects raw problem statements to efficient solutions.

They appear constantly in interviews—not because they’re tricky, but because they expose how well you:

  • Translate constraints into logic
  • Track state over time
  • Reason about correctness and efficiency

If you master Two Pointers, Sliding Window, Fast & Slow Pointers, and Sweep Line, you’ll unlock a large percentage of coding interview problems without needing advanced algorithms.

In the next sections, we’ll apply these techniques repeatedly across arrays, strings, linked lists, and interval-based problems—exactly how they show up in real interviews.