getting tle polo the penguin and test

problem link: PPTEST Problem - CodeChef

my code: CodeChef: Practical coding for everyone

PLEASE HELP OPTIMIZE MY CODE

THANKS IN ADVANCE!!

Hi ansh!!
your solution is simply recursively computing the solution to the problem with n=100, it has a complexity of O(2^n) ie O(2^100) which will simply timeout. Also while recursing you are computing results of same problems again and again…why not simply store the results of the previously computed problems somewhere so that you donot need to recurse for that particular problem? In order to do this bulid a table for previously computed solutions and use it to find the answers to next problems…this approach is a dynamic programming approach with a complexity of O(n*w)…which will pass the given time limit…Hope this Helps :slight_smile:

1 Like

use memorization concept

The problem link is dead. Do you know the new link of this problem?

Polo the Penguin and the Test Practice Coding Problem - CodeChef => 404 This problem has become part of curated practice.