From the course: Get Ready for Your Coding Interview

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Visual solution to sample question #1

Visual solution to sample question #1

From the course: Get Ready for Your Coding Interview

Visual solution to sample question #1

- [Instructor] So how should we solve this problem of finding the second largest in a given array of numbers? When you start solving a coding interview problem, you should first visually show your solution instead of jumping into your code right away. So I'm going to show you my solution visually right here. The idea of my solution is going to be, I'm going to take a look at each number in this array or Python list one by one. As we go, we're going to keep track of the largest number that we've seen so far, and the second largest number that we've seen so far. To do this, we're going to use variables called largest and second largest in our function. Let's just initialize them to none at first. When we were looking at this element, the first element, largest becomes 1. And when we are looking at the second element, the largest number we've seen so far is 3. And the second largest number we've seen so far will be 1, until…

Contents