Problem: Write a function that finds the second largest element in a given Python list or array. Learn what to do if you are asked to this in an actual coding interview.
- [Instructor] Here's Sample Interview Question number one with array or a Python list. Here's the problem: You're given an array or a Python list of integers. For example, this one on the screen, and I want you to write a function which takes the the given array and finds and returns the second largest number in this array. Let's call this function second largest. So second largest of this array on the screen should return four because five is the largest number in this array and four is the second largest. Now, whenever you get a question in your coding interview, you should always ask clarifying questions to make sure you have all the right assumptions.
For this question, you might ask, "could this array be empty?" The answer is yes, you should return none in that case. None in Python, by the way, is like no in some other languages, and it just means that it's an empty value. Could this array or Python list have only one element inside it? Yes, in that case, second largest should return none as well. What if we had, say, two two one. Then second largest should return two.
You might say, "well, it doesn't really make sense mathematically, but that's just how we define it here." And the interviewer is really the one who decides if your answer is correct, so you should always ask the interviewer what the correct thing to do would be if you're not sure. Now pause the video, solve the problem, and make sure to run your code to check if it's correct. You can use any language to solve this problem, and if you like to use Python, feel free to use the exercise file for this problem with Jupiter Notebook.
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.
- Honing your problem-solving skills
- Preparing for a coding interview
- Using Jupyter Notebook for sample problems in Python
- Using arrays to solve interview problems
- Working with and comparing strings
- Using two-dimensional arrays
- Learning the importance of time complexity in code
- Using Big-O notation to describe the time complexity of code
- Using hash tables and Python dictionaries in Python
- Asking clarifying questions during your interview
- Finding the most efficient solutions to problems
- Testing your proposed code solutions