Pregunta de entrevista de Google

Implement std::vector's push_back() Also asked for maximum contiguous subarray problem

Respuesta de la entrevista

Anónimo

3 de oct de 2014

// Traverse the array and keep track of the max sum thus far public static int getMaxSubArray(int[] array) { int maxSum = array[0]; int[] sum = new int[array.length]; sum[0] = array[0]; for (int i = 1; i < array.length; i++) { sum[i] = Math.max(array[i], sum[i - 1] + array[i]); maxSum = Math.max(maxSum, sum[i]); } return maxSum; }