Free to get started

Coding interviewsbroken down

We'll walk you through the patterns behind interview questions one step at a time. That way a problem you've never seen still looks familiar.

Shortest Length Subarray Sum, slide 1 of 13: a and b start at 0. window_sum is 0 and shortest is None.
Shortest Length Subarray Sum, slide 2 of 13: b moves to 1. The window holds 2 and sums to 2.
Shortest Length Subarray Sum, slide 3 of 13: b moves to 2. The window holds 2, 3 and sums to 5.
Shortest Length Subarray Sum, slide 4 of 13: b moves to 3. The window holds 2, 3, 1 and sums to 6. That reaches the target. The shortest length is now 3.
Shortest Length Subarray Sum, slide 5 of 13: a moves to 1 and drops 2. The window sums to 4.
Shortest Length Subarray Sum, slide 6 of 13: b moves to 4. The window holds 3, 1, 1 and sums to 5.
Shortest Length Subarray Sum, slide 7 of 13: b moves to 5. The window holds 3, 1, 1, 3 and sums to 8. It's 4 long. The shortest length stays 3.
Shortest Length Subarray Sum, slide 8 of 13: a moves to 2 and drops 3. The window sums to 5.
Shortest Length Subarray Sum, slide 9 of 13: b moves to 6. The window holds 1, 1, 3, 4 and sums to 9. It's 4 long. The shortest length stays 3.
Shortest Length Subarray Sum, slide 10 of 13: a moves to 3 and drops 1. The window holds 1, 3, 4 and sums to 8. It's 3 long. The shortest length stays 3.
Shortest Length Subarray Sum, slide 11 of 13: a moves to 4 and drops 1. The window holds 3, 4 and sums to 7. It's 2 long. The shortest length is now 2.
Shortest Length Subarray Sum, slide 12 of 13: a moves to 5 and drops 3. The window holds 4 and sums to 4.
Shortest Length Subarray Sum, slide 13 of 13: We stop once b reaches the end and a can't move any further. Here a stops because the sum is 4, which is less than 6. The shortest length is 2.
1 / 13

Use ← → arrow keys

These are the real slides from the Shortest Length Subarray Sum lesson.
Plan

How long do you have?

We make you a study plan that fits the time you have before your interview.

What you'll learn each week

Week 1Two PointersSliding WindowIntervals
Week 2Linked ListBinary Search
Week 3Tree BFSGraph BFS
Week 4Graph DFSBacktrackingDynamic Programming

You can learn all 10 patterns.

That's 25 problems.

We give you fewer problems per pattern so you can learn more patterns.

Make my plan

You can also read our one-week, one-month and three-month study plans.

We've both been the interviewer and the candidate more times than we can count. We kept seeing people who could code well but didn't know how to start on a new problem. We built InterviewCrunch to teach that first step.

Anita & Andrew

Adding to a list

O(n) or O(1)

Here are two common methods to add elements to a list:

  • append() adds the element to the end of the list
  • insert() takes in a second argument that specifies what position to add the element at

Note

insert() is an O(n) complexity operation whereas append() is an O(1) operation. Use insert() sparingly. Use a queue if you only need to add to the front.

secret = ["I", "love", "lists"]
secret.append("!!")
secret.insert(1, "really")
print(secret)
main.py
Fundamentals

Learn the data structures first

Almost every interview problem is built on a list, a dictionary, or a set. Our lessons start there. They explain each one in plain words and give you examples you can run, like the one on this page.

  • The free lessons explain every structure and how fast each of its operations runs.
  • The advanced lessons add heaps, deques, trees, and graphs.
  • You also get two free cheat sheets to review it all later.
Two Pointers slide, step 1 of 11
Two Pointers slide, step 2 of 11
Two Pointers slide, step 3 of 11
Two Pointers slide, step 4 of 11
Two Pointers slide, step 5 of 11
Two Pointers slide, step 6 of 11
Two Pointers slide, step 7 of 11
Two Pointers slide, step 8 of 11
Two Pointers slide, step 9 of 11
Two Pointers slide, step 10 of 11
Two Pointers slide, step 11 of 11
1 / 11

Use ← → arrow keys

Patterns

Watch each algorithm run one step at a time

Each of the ten patterns we teach comes with visual slides that walk through the algorithm step by step. All the solutions for a pattern start from the same template. That means you can use what you learn on one problem on the next one.

Valid Palindrome

Easy

A phrase is a palindrome if it reads the same forward and backward after ignoring punctuation, capitalization, and spaces. Write a function that returns true if the given string is one.

"Han ah!" → True"Hugo" → False
def is_palindrome(s):
    left = 0
    right = len(s) - 1
    while left < right:
        if s[left] != s[right]:
            return False
        left += 1
        right -= 1
    return True

print(is_palindrome("step on no pets"))
main.py
Practice

Practice questions that feel like the real interview

Every pattern comes with practice problems like the ones interviewers actually ask. You write your code right in the browser and run it against test cases to see if it works.

Recognize

First you need to know which pattern to use

Lots of people get stuck on a problem they could have solved because they don't know where to start. You can practice that first step with this quiz. You read a problem and pick which pattern you'd use. We explain why the right pattern fits after you answer. The Daily 8 gives you eight new questions every day.

Try one right now

Reverse String

Easy

You need to reverse a list of characters in place, without building a second list. Which pattern fits?

Review

Cheat sheets you can earn

Every pattern has a one-page cheat sheet you can keep for review.

  • You earn each sheet by solving half of that pattern's problems.
  • You get the complete PDF booklet when you finish all ten patterns.
  • You can download the fundamentals sheets for free without an account.

Got an interview coming up?

Hundreds of engineers have prepped with InterviewCrunch. It's free to get started.