Atlassian interview question

Asked on DP and time complexity from basic to optimal