Help me with Google L3 Interview Question

Revision en1, by tausif95, 2023-07-03 12:08:57

Find minimum absolute difference between 2 elements in an array that are at least n indices apart.

Example 1: num = [1, 1, 1, 1, 3, 3, 3, 3, 4, 4, 4, 6, 6, 6, 11, 11, 11, 11] n = 5 The answer should be 1

Example 2: num = [24, 1400, 1900, 1200, 98, 89, 123, 27] n = 2 The answer should be 3

I got the naive solution to this problem, not sure what the optimize solution should be I was wondering whether someone else would be able to show me how to solve it.

Tags array

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English tausif95 2023-07-03 12:08:57 513 Initial revision (published)