This Python function takes in a list of strings and returns a new list with all the strings in reverse order.
Given a list of strings, write a Python function that takes in this list and returns a new list with all the strings in reverse order. Example input: ["hello", "world", "this", "is", "a", "test"] Example output: ["test", "a", "is", "this", "world", "hello"]
def reverse_list(list): return list[::-1] # This solution is optimal because it is O(n) time complexity and O(n) space complexity. # The time complexity is O(n) because the list is iterated through once. # The space complexity is O(n) because the list is copied and returned.
This solution is correct and demonstrates a good understanding of time and space complexity.
Evaluated at: 2022-11-21 00:16:19