TikTok interview question

Some Dynamics Programming question And code gradient descent update