Maximum Subarray Sum
Updated
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[]) → intExamples
Example 1
nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6The best contiguous subarray is [4,-1,2,1], whose sum is 6.
More Safe Security Onsite Interview questions
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