Longest Beautiful Sequence

Problem
Best Submission

I’m stuck on how to solve the last subtask. Someone told me to split the numbers in half, but I’m not sure how to add this on to my solution.
Does it necessitate a completely different algorithm in and of itself?