Skip to content

Instantly share code, notes, and snippets.

@novikserg
Last active October 7, 2016 17:28
Show Gist options
  • Save novikserg/63413f060dde81297e75cf4ec47b6ee0 to your computer and use it in GitHub Desktop.
Save novikserg/63413f060dde81297e75cf4ec47b6ee0 to your computer and use it in GitHub Desktop.
# 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