ThoughtSpot Interview Question

A Binary Search Problem and a DP problem.