Build Failures Time : O(nlogm) Space : O(1) 12345678910111213141516int 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;}