Back to problems

Array Challenge: Left-Comparison Running Counter

Algorithm · Akuna Capital · Medium

Requirements For every position i in an array: Begin with its counter set to 0. Check a[i] against all earlier entries (a[i-1], a[i-2], ..., a[0]). When an earlier value exceeds it, decrease the counter by their absolute difference; when that value is below it, increase the counter by the absolute difference. Produce an array containing the completed counter for each position. Examples arr[0] = 5: there are no preceding values, so the counter is 0. arr[1] = 2: against 5…

Checking your access…