Learn

Technical Interview Problems in Python: Lists

Review

Lists are a fundamental data structure for any program. When faced with a technical interview problem using lists, here are a few strategies to keep in mind:

- Be comfortable with variables which represent indices in the list, or
*pointers*.- Accessing the first and last values with indices.
- Modding by the list length will ensure a valid index. (
`num % length_of_list`

). - Pointers can sometimes substitute for copying a list.

- Ordered datasets unlock a lot of solutions.
- Sorted data can be searched in
`O(logN)`

time using binary search. - Sorting can be done in
`O(N*logN)`

time.

- Sorted data can be searched in
- Find the “naive” solution and push to optimize.
- Interviewers want the optimal solution, but at least talk through the inefficient approach.

### Instructions

Run the code to see the difference in execution speed between optimal and naive solutions!

**Sometimes the solution which optimizes for space will run slower**.