Jakub Gwóźdź
12/02/2020, 9:49 AMJakub Gwóźdź
12/02/2020, 9:50 AMinternal fun findIndex(
sortedEntries: List<Int>,
expectedSum: Int,
indexOfExcluded: Int = -1
): Int {
var startIndex = indexOfExcluded + 1
var endIndex = sortedEntries.lastIndex
while (startIndex < endIndex) {
val sum = sortedEntries[startIndex] + sortedEntries[endIndex]
comparisons++
when {
sum == expectedSum -> return startIndex
sum < expectedSum -> startIndex++
sum > expectedSum -> endIndex--
else -> error("wtf")
}
}
return -1
}
and searches the entries in one goJoris PZ
12/02/2020, 10:13 AMJakub Gwóźdź
12/02/2020, 10:26 AMtodd.ginsberg
12/02/2020, 1:34 PMbjonnh
12/02/2020, 3:00 PMNir
12/02/2020, 3:57 PMJakub Gwóźdź
12/02/2020, 4:01 PMbjonnh
12/02/2020, 4:07 PM