Online coding interview: Given an array of integers. Find the largest increasing sub sequence of integers in the array. // 10, 3, 7, 9, 0, 15 // return index 1&3
Anonymous
/** * @param numArr Array of ints * @return start index and end index of the longest increasing sub sequence */ static int[] findMaxIncSubSeq(int[] numArr) { int[] increments = new int[numArr.length]; increments[0] = 1; for (int i = 1; i = numArr[i - 1]) { increments[i] = increments[i - 1] + 1; } else { increments[i] = 0; } } int max = increments[0]; int maxIdx = 0; for (int i = 0; i max) { max = increments[i]; maxIdx = i; } } return new int[]{maxIdx - max, maxIdx}; }
Check out your Company Bowl for anonymous work chats.