7171 Views

0 Likes

In this lesson, Alvin explores the strategy to solving the following interview problem:

Write a function,

is_prime, that takes in a number as an argument. The function should return a boolean indicating whether or not the given number is prime.A prime number is a number that is only divisible by two distinct numbers: 1 and itself.

For example, 7 is a prime because it is only divisible by 1 and 7. For example, 6 is not a prime because it is divisible by 1, 2, 3, and 6.

You can assume that the input number is a positive integer.

```
is_prime(2) # -> True
```

```
is_prime(3) # -> True
```

```
is_prime(4) # -> False
```

```
is_prime(5) # -> True
```

```
is_prime(6) # -> False
```

```
is_prime(7) # -> True
```

```
is_prime(8) # -> False
```

```
is_prime(2017) # -> True
```

```
is_prime(2048) # -> False
```

If you need additional support taking these DSA skills and actually applying them, take Alvin's *complete* data structures and algorithms course on Structy. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.

Use this link to get 20% off the entire Structy DSA learning experience.

Follow Alvin on LinkedIn: https://www.linkedin.com/in/alvin-zablan-b73a92117/

Related Videos

ðŸ‘‘

0:48

DSA Crash Course [Part 87] - Outro

ðŸ‘‘

5:27

DSA Crash Course [Part 86] - Array Stepper Walkthrough

ðŸ‘‘

5:39

DSA Crash Course [Part 85] - Array Stepper Approach

ðŸ‘‘

6:31

DSA Crash Course [Part 84] - Counting Change Walkthrough

ðŸ‘‘

6:26

DSA Crash Course [Part 83] - Counting Change Approach

ðŸ‘‘

5:52

DSA Crash Course [Part 82] - Summing Squares Walkthrough

ðŸ‘‘

6:22

DSA Crash Course [Part 81] - Summing Squares Approach

ðŸ‘‘

8:00

DSA Crash Course [Part 80] - Non Adjacent Sum Walkthrough

ðŸ‘‘

8:33

DSA Crash Course [Part 79] - Non Adjacent Sum Approach

ðŸ‘‘

5:34

DSA Crash Course [Part 78] - Max Path Sum Walkthrough

Explore TrendingLayoffsPerformance Improvement PlanSystem DesignInterpersonal CommunicationTech Lead