[AlgoExpert] Build Failures

Build Failures

  • Time : O(nlogm)
  • Space : O(1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int buildFailures(vector<vector<bool>> buildRuns) {
int res = 0, count = 0, n = buildRuns.size();
double rate = 1.0;
for(auto& runs : buildRuns) {
int success = rend(runs) - upper_bound(rbegin(runs), rend(runs), false);
double cur = 1.0 * success / runs.size();
if(cur < rate) {
res = max(res, ++count);
} else {
count = 1;
}
rate = cur;
}
return res <= 1 ? -1 : res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/06/02/PS/AlgoExpert/build-failures/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.