I just browsed and found this online. Hope it helps (DP always seems beyond my knowledge ).
Exact same problem available in Leetcode.
Update :- Time complexity can be reduced.
if we make dp[i][diff] (bool variable) diff-> difference between left and right weight.
now you have three option:-
1> dont take it
2> include it in small weight side
3> include it in large weight side
now answer is dp[n-1]
@gupta_nitin can u write a code in this Programming problems and Competitions :: HackerRank and If get AC please explain your approach too.
Try the hardest variant out there. Suppose you actually want torque = distance*weight to equal both sides. Now the order both sides matters as well, and we want to make 2 extremely weird quanities equal. Do try this, it’s pretty cool.