Snowflake interview question

hard dp problem on the OA