Google Interview Question

it was Dynamic Programming question