Minimum Energy to Collect Bags From Both Ends

Asked at Amazon · Coding Questions · Difficulty: Hard

Bags with weights `weights` are collected from either the leftmost or rightmost position. Collecting a bag costs its weight times `X` (from the left) or `Y` (from the right), plus an extra `El` (or `Er`) if it is collected from the same side as the immediately previous collection. Return the minimum total cost to collect all bags.

Loading the problem…