Skip to content

Instantly share code, notes, and snippets.

@tensaix2j
Last active October 6, 2015 05:03
Show Gist options
  • Save tensaix2j/70ce19427e0d5e314d74 to your computer and use it in GitHub Desktop.
Save tensaix2j/70ce19427e0d5e314d74 to your computer and use it in GitHub Desktop.
def solution(a)
lpeak = []
sqrt_c = ( a.length ** 0.5 ).ceil
fcnt = [0] * ( sqrt_c + 1)
f_pt = 1
(1...a.length-1).each { |i|
if a[i-1] < a[i] && a[i] > a[i+1]
(f_pt..sqrt_c).each { |j|
if lpeak[j] == nil || i - lpeak[j] >= j
fcnt[j] += 1
lpeak[j] = i
end
}
f_pt += 1 if fcnt[f_pt] >= f_pt
end
}
return fcnt.max
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment