I am trying to solve this problem:
There is a rod of length N lying on x-axis with its left end at x = 0 and right end at x = N. Now, there are M weak points on this rod denoted by positive integer values(all less than N) A1, A2, …, AM. You have to cut rod at all these weak points. You can perform these cuts in any order. After a cut, rod gets divided into two smaller sub-rods. Cost of making a cut is the length of the sub-rod in which you are making a cut.
Your aim is to minimise this cost. Return an array denoting the sequence in which you will make cuts. If two different sequences of cuts give same cost, return the lexicographically smallest.
This question is a variant of Rod cutting problem and is often asked in Google interviews. Thus, this question is also well studied. I found posts on Stackoverflow and GeeksForGeeks about this question but I am still at loss to understand because these solutions are directly implemented bottom up.
To get a sense of how this question is to be thought, I am looking for a simple recursive solution first.