Last active
October 7, 2016 17:28
-
-
Save novikserg/63413f060dde81297e75cf4ec47b6ee0 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
# full description: | |
# https://codility.com/demo/take-sample-test/ps/ | |
# tl;dr: Write a function that, given a zero-indexed non-empty array A consisting of N integers, returns the first covering prefix of A. | |
def solution(a) | |
last_unique = a.uniq.last | |
a.index { |el| el == last_unique } | |
end | |
array = (0..1_000_000).to_a | |
puts Benchmark.measure { | |
expect(solution(array)).to eq(1_000_000) | |
} # => 0.36s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment