Write a function to solve a specific algorithmic challenge and discuss its time and space complexity.