You can try TDD-ing the problem. Although TDD is usually not the right approach for coming up with algorithms or solving coding challenges, it can guide your thinking a bit. Write a test for most simple input, solve the problem for this input. Iterate and write tests for longer inputs.
I will repeat that TDD will not give you the most elegant answer, but you will at least have an basic implementation. TDD just gives you one of protocols that you can use to solve problems.