Algorithm logic
I need to solve the following problem with an algorithm: [PROBLEM]. Input: [INPUT]. Expected output: [OUTPUT]. Explain the logic/approach first (in steps), then implement in [LANGUAGE], and comment on the complexity (time/space). If there is a simpler or more efficient approach, mention it.