https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/
PassingCars coding task - Learn to Code - Codility
Count the number of passing cars on the road.
app.codility.com

class Solution {
public int solution(int[] A) {
int sum = 0;
int result = 0;
for (int i = A.length - 1; i >= 0; i--) {
if (A[i] == 1) {
sum += 1;
} else {
result += sum;
}
if (result > 1000000000) {
return -1;
}
}
return result;
}
}| [Lesson 5] Prefix Sums - GenomicRangeQuery (0) | 2025.01.03 |
|---|---|
| [Lesson 5] Prefix Sums - CountDiv (0) | 2025.01.03 |
| [Lesson 4] Counting Elements - MissingInteger (0) | 2025.01.02 |
| [Lesson 4] Counting Elements - MaxCounters (0) | 2025.01.02 |
| [Lesson 4] Counting Elements - PermCheck (0) | 2025.01.02 |
댓글 영역