Algorithm · Bloomberg · Medium
Problem: Van Eck-Style Sequence (Find the n-th Value) For an integer n where n >= 1, construct an integer array a using the rules below: Set a[0] to 0. For every i >= 1: When a[i-1] occurred earlier in the sequence (meaning some j satisfies 0 <= j <= i-2 and a[j] == a[i-1]), find the latest such position, namely the greatest j, and call it last_index. Then: a[i] = (i - 1) - last_index If that preceding value has never occurred at an earlier position: a[i] = 0 Return a[n-1].…
Checking your access…