79105661

Date: 2024-10-19 18:39:55
Score: 1
Natty:
Report link

After the proposed solution, here should be the final one and now it passes all performance tests:

        int result = 0;
        int ones = 0;
        int len = a.length;

        for (int i = len - 1; i >= 0; i--) {
            if (a[i] == 1) {
                ones++;
            } else {
                result += ones;
            }
        }

        return (result > 1000000000 || result < 0) ? -1 : result;

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Mostafa Abdelhamid