Maximum Subarray
Updated
Problem statement
Given an integer array nums, return the largest possible sum of a nonempty contiguous subarray.
Function
maxSubArray(nums: int[]) → longExamples
Example 1
nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6The subarray [4,-1,2,1] has the maximum sum 6.
Example 2
nums = [1]return = 1The only nonempty subarray is the single element.
Example 3
nums = [-8,-3,-6,-2,-5,-4]return = -2When every value is negative, the best nonempty subarray is the largest individual value.
Constraints
1 <= nums.length <= 100000.-1000000000 <= nums[i] <= 1000000000.- The answer fits in a signed 64-bit integer.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Best Time to Buy and Sell StockAmazon · ONSITE INTERVIEW
- Best Time to Buy and Sell StockMeta · PHONE SCREENMeta interview questions
- Speed Up a Slow FunctionCitadel · OA · PHONE SCREENCitadel interview questions
- Best Time to Buy and Sell StockSwiggy · PHONE SCREEN
- Best Time to Buy and Sell StockKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Suffix Maximum Frequency QueriesMicrosoft · PHONE SCREENMicrosoft interview questions
- Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Maximum SubarraySquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
- Best Time to Buy and Sell StockJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Best Time to Buy and Sell StockZoox · ONSITE INTERVIEW
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)