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,…which should be under notebook.…From our function second_largest, we're going to find…and return the second largest number in a given array,…except when the length of the array is one or 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 the 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 current number…that we're looking at currently…is the first number in this given list.…

So we're going to set largest to current number.…

Resume Transcript Auto-Scroll

Author

Released

4/14/2017

If you've nabbed an interview for a software development position, it's likely that you'll have to face a common hurdle—the coding interview. If you're not sure what to expect, or you'd like to brush up on the essential topics that candidates are often tested on, then this course is for you.

Follow YK Sugishita as he explains what to keep in mind as you prepare for coding interviews. YK covers useful concepts that can help you master your interview, followed by practice problems that test what you know. YK reviews key concepts such as two-dimensional arrays, time complexity, Big-O notation, and hash tables. To wrap up, he shares a few tips for acing your interview, such as how to come up with an optimal solution. Even if you're not prepping for an upcoming job interview, tackling the coding problems covered in this course is a great way to sharpen your programming skills.