When facing problems it’s often a good idea to write a brute force solver and a test case generator (if it’s feasible for the problem you’re looking at). That way you can find cases where your algorithm fail, and from that hopefully deduce what you’re doing wrong. On top of that you can always write some cases you know the answer to by hand, which is especially useful if you want to check corner cases you know of.
In this case you should be able to write a brute force solution that tries to pick all combinations of 1 segment, 2 segments, 3 segments and so on and greedily try to see if they can be put down in a way that fulfills the constraints. The complexity for such a solution is worse than exponential, but it’s guaranteed to be correct! Now generate test cases and see if you can find cases where the correct brute force code and your solution differs.
This kind of approach is also useful if you’re working on optimizing code. Continuously check that the optimization/changes you’ve done doesn’t break your solution. For harder problems it’s not uncommon for me to have either a test script running whenever I save my file, or just have a while loop running in s shell that throws random test cases at my code continuously. When you think you have found a solution that should perform well enough you can use your generator to stress test your solution as well!