Академический Документы
Профессиональный Документы
Культура Документы
Link
MaxCounters
Complexity:
expected worst-case time complexity is O(N+M);
expected worst-case space complexity is O(N)
Execution:
The idea is to perform the specified operation as stated. It is not required to iterate over
the whole array if a new value is set for all the values. Just save the value and check it
when an increase on that position is performed.
Solution:
1
#include <algorithm>
2
3
vector<int> sol;
int current_max = 0;
int last_increase = 0;
7
8
9
10
11
12
13
14
15
16
sol[A[i]-1]++;
17
18
}
19
}
20
21
22
23
24
25
26
return sol;
}
27
Solution above for max counters is from https://www.martinkysel.com/codilitymaxcounters-solution/
https://www.martinkysel.com/codility-passingcars-solution/
https://www.martinkysel.com/hackerrank-solutions/
https://github.com/tpeczek/Codility
https://github.com/nfgrilo/Codility/tree/master/Lessons
https://codility.com/programmers/challenges/
https://codility.com/programmers/lessons/
https://codesays.com/solutions-to-training-by-codility/