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.

Code solution to sample question #1

Code solution to sample question #1

- [Instructor] Let's see what my solution might look like in code. You can open this exercise file with some test cases with Jupyter Notebook. From our function, second largest, we're going to find and return the second largest number in a given array, except for when the length of the array is one or a zero. In that case, we'll just return none. And let's implement our function right here. In this function, we'll first initialize two variables, largest and second largest. We're going to use these two variables to keep track of the largest number we've seen so far and the second largest number we've seen so far as we iterate through each element in a given list. Let's just initialize them to none. And then we're going to iterate over each element in this list with a for loop. So for that, I'm going to write for current number in given list. In a for loop, if largest is still equal to none, that would mean that…

Contents