6 kyu
Element equals its index
504 of 1,998sgerodes
Description:
Given a sorted array of distinct integers, write a function index_equals_value
that returns the lowest index for which array[index] == index
.
Return -1
if there is no such index.
Your algorithm should be very performant.
[input] array of integers ( with 0
-based nonnegative indexing )
[output] integer
Examples:
input: [-8,0,2,5]
output: 2 # since array[2] == 2
input: [-1,0,3,6]
output: -1 # since no index in array satisfies array[index] == index
Random Tests Constraints:
Array length: 200 000
Amount of tests: 1 000
Time limit: 1.5 s
If you liked this Kata check out my more complex creations:
Find the neighbourhood in big dimensions. Neighbourhood collection
The Rubik's cube
Arrays
Algorithms
Similar Kata:
Stats:
Created | Aug 13, 2018 |
Published | Aug 13, 2018 |
Warriors Trained | 5444 |
Total Skips | 119 |
Total Code Submissions | 59375 |
Total Times Completed | 1998 |
Python Completions | 504 |
JavaScript Completions | 1404 |
Haskell Completions | 30 |
Rust Completions | 102 |
Total Stars | 149 |
% of votes with a positive feedback rating | 88% of 303 |
Total "Very Satisfied" Votes | 255 |
Total "Somewhat Satisfied" Votes | 26 |
Total "Not Satisfied" Votes | 22 |
Total Rank Assessments | 7 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |