I am trying to optimize this as best as I can. Here are two possible solutions I have developed and their respective time and space complexity.
Can you pl