Google interview question

array problem and dynamic programming problem