employer cover photo
employer logo
employer logo

Jack Henry & Associates

Engaged employer

Jack Henry & Associates interview question

Given an array with each array elements containing a random cost (i.e {10, 5, 2, 200, 5, 1}). You can either step through element 1 by 1 or skip by 1 element (i.e array[0] > array[2] > array[3] > array[5]). Find the lowest cost from element 0 to N.

Interview Answers

Anonymous

27 July 2015

From element 3 to N: array[current] += ((array[current-1] < array[current-2]) ? array[current-1] : array[current-2]) return array[current]

Anonymous

21 Feb 2017

1. minCost = 0; 2. n, i = findSmallestWithIndex(range) 3. minCost += n 4. while( i< arr.length ) { minCost += min(arr[i+1], arr[i+2]) n, next_i = findSmallestWithIndex(arr[i+1], arr[i+2]) i = next_i + 1 }