TLE in "Plus Multiply" Problem (PLMU)

It is showing partially correct i this python code
All the given test cases are getting passed.

Just count number of 0’s ans 2’s in the array…

1 Like

sorry @mohitfps10 didn’t get you …

Try the Editorial :slight_smile:


i get the point but still i want to know what’s wrong in my code?

You have accurately transcribed the requirement into code, but it will take far too long on an array of the size required.

To succeed, you need to use a far more efficient method of evaluating the input, which the editorial describes. PLMU - Editorial

One thing that is skipped over there is calculating how many ways to choose two items from k. While this is a special case of a binomial coefficient, you can think of it like this: choose any item (k options), then choose any other item (k-1 options) then account for making the same choice in the other order (divide by 2): k(k-1)/2.

1 Like