Pergunta de entrevista da empresa Meta

Given an array of integers, find the sub array with the largest sum. (must be done in linear time)

Respostas da entrevista

Sigiloso

11 de dez. de 2013

Looks similar to oj.leetcode.com/problems/maximum-subarray/

Sigiloso

9 de jan. de 2014

Kadane's Algorithm (http://en.wikipedia.org/wiki/Kadane's_Algorithm)

Sigiloso

2 de mar. de 2014

Here the java solution: M[i] = max(A[i], M[i-1] + A[i]) void largestSumSubArray(int[] a){ if (a.length != 0){ int[] m = new int[a.length]; m[0] = a[0]; int maxIndex = m[0]; for (int i = 1; i maxIndex) maxIndex = i; } boolean found = false; int i = maxIndex - 1; while (!found){ if (m[i] > 0) i--; } System.out.printf("%d - %d", i, maxIndex); } }

Sigiloso

1 de nov. de 2013

Assuming the sub array can be any size and only positive integers: you only need to check which of the two end numbers on the array is bigger and then take that the list that includes that number and not the other.

1