Amazon Interview Question: Find the max subsequent sum f... | Glassdoor.co.in

Interview Question

Software Design Engineer In Test Interview Hyderabad

Find the max subsequent sum for a random array of numbers

Answer

Interview Answer

2 Answers

3

int maxSum(int arr[], int size)
{
  int maxSum= 0;
  int currMaxSum = 0;
  for (int i = 0; i < size ; i++)
  {
     currMaxSum += arr[i];
     if (currMaxSum < 0)
      {
           currMaxSum = 0;
      }
      if (maxSum < currMaxSum )
       {
             maxSum = currMaxSum ;
        }
     }
    returb naxSum;

  }
}

Rahul Gupta on 16-Jun-2013
0

private static int findMaxSubSeqSum(ArrayList allRecords)
    {
        int maxSum = 0;

        int prevSum = 0;
        int currentSum = 0;
        for (int i = 0; i maxSum)
            {
                maxSum = currentSum;
            }
            if (currentSum < prevSum)
            {
                currentSum = 0;
            }
        }
        return maxSum;
    }

Dhimant on 25-Jun-2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.