Created
March 25, 2021 21:44
-
-
Save jordanterry/dd5467956dff57e02c8c27f45e512a5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun checkIfServerIsUnhealthy( | |
errorRates: DoubleArray, | |
time: Int, | |
timeRange: Int, | |
minimumErrorThreshold: Double | |
): Boolean { | |
if (timeRange > errorRates.size) throw IllegalArgumentException() | |
var left = time - timeRange + 1 | |
var right = time + timeRange | |
if (left < 0) { | |
val difference = left * -1 | |
left += difference | |
right += difference | |
} | |
var upperBound = right | |
if (upperBound > errorRates.size) { | |
val difference = upperBound - errorRates.size | |
upperBound -= difference | |
} | |
for (i in right until upperBound) { | |
var isUnhealthy = true | |
for (j in left until right) { | |
if (errorRates[j] < minimumErrorThreshold) isUnhealthy = false | |
} | |
if (isUnhealthy) return true | |
left++ | |
right++ | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment