Skip to content
Advertisement

Tag: greedy

How to make this greedy function faster?

I am trying to solve a problem and my code fails at one test case where the list is of length 25000. Is there any way I can make this faster. I tried using functools.lru_cache and I still can not run within the time required to complete. This is the problem from the site Given an array of non-negative integers

Minimize the maximum difference

I’m trying to solve this Problem from GFG with following approach: But i’m unable to pass the testcases: I’m unable to figure out fault in my logic or code. Could some suggest corrections or better approach? Answer I’m unable to figure out fault in my logic or code. As per your current logic, you decide to add or subtract k

Advertisement