Snowflake Interview Question

hard dp problem on the OA