Find the minimum height difference between a hill and any hill visible after a gap.
Unlock detailed company stats for this questionUpgrade
You are given an array of heights of hills. A hiker can see the hills ahead of him only after a certain gap distance x: if x = 2 and he is at index i, he can see hills from index i+2 onward (e.g. from i = 1 he sees 3, 4, ..., n). Find the minimum height difference between a hill and any hill visible from it.
Example: heights = [2, 4, 9, 10], gap = 2. At i = 0 he can see i = 2 and i = 3, minimum difference 7. At i = 1 he sees i = 3, minimum difference 6. From indexes 2 and 3 no hill is visible. The final answer is 6.
My ordered-set approach gave TLE after 13 of 20 test cases.
Community answers
No answers contributed by the community yet.
Related questions
What is the difference between findFirst and findAny in streams?What is the difference between TLS and mTLS?What's the difference between HTTP and HTTPS?Related courses

Course

Course
Course
