FastPrepMaximum Subarray Sum
Problems/Maximum Subarray Sum

Maximum Subarray Sum

Safe Security logoSafe Security● EasyONSITE INTERVIEW

Updated Jun 2026

QuestionFunctionExamples

Problem statement

You are given an integer array nums. Find the contiguous subarray with the largest sum and return that sum.

Function

maxSubArray(nums: int[]) → int

Examples

Example 1

nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6

The best contiguous subarray is [4,-1,2,1], whose sum is 6.

More Safe Security Onsite Interview questions

  • Count Subsets With a Target SumONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Pascal's TriangleBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Best Time to Buy and Sell StockAmazon · ONSITE INTERVIEW
  • Best Time to Buy and Sell StockKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
  • Maximum SubarrayMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum SubarraySquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • Best Time to Buy and Sell StockZoox · ONSITE INTERVIEW
  • Pascal's TriangleEricsson · ONSITE INTERVIEWEricsson interview questions
  • Best Time to Buy and Sell StockMotive · ONSITE INTERVIEWMotive interview questions
  • Maximum Profit with Repeated Stock TradesPalantir · ONSITE INTERVIEWPalantir interview questions
See Safe Security hiring insights
Saved
class Solution {
    public int maxSubArray(int[] nums) {
      // write your code here
    }
}
Checking account…