Kotlin refactoring O(n) algorithm

How to optimize the code search by keys?