About 7,390 results
Open links in new tab
  1. Maximum subarray sum in O (n) using prefix sum

    Oct 12, 2022 · Given an Array of Positive and Negative Integers, find out the Maximum Subarray Sum in that Array. Examples: Input1 : arr = {-2, -3, 4, -1, -2, 1, 5, -3} Output1 : 7 Input2 : arr = {4, -8, 9, -4, 1, -8, -1, 6} Output2 : 9. Kadane’s Algorithm solves this problem using Dynamic Programming approach in linear time. Here is another approach using ...

  2. Maximum Subarray Problem in Java - Baeldung

    Jan 8, 2024 · The maximum subarray problem is a task to find the series of contiguous elements with the maximum sum in any given array. For instance, in the below array, the highlighted subarray has the maximum sum(6): In this tutorial, we’ll take a look at two solutions for finding the maximum subarray in an array.

  3. Prefix Sum Array – Implementation and Applications

    Apr 11, 2025 · Maximum subarray sum modulo m: Given an array of n elements and an integer m. The task is to find the maximum value of the sum of its subarray modulo m i.e find the sum of each subarray mod m and print the maximum value of this modulo operation.

  4. Prefix Sum - AlgoMonster

    By computing and storing the prefix sum of an array, you can easily answer queries about the sum of any subarray in constant time. for num in arr: prefix_sum.append(prefix_sum[-1] + num) return prefix_sum. arr = [1, -20, -3, 30, 5, 4] print(prefix_sum_array(arr))

  5. Print subarray with maximum sum - GeeksforGeeks

    Sep 11, 2024 · Explanation: The subarray {6, -2, -3, 1, 5} has the largest sum of 7. The idea is to run two nested loops to iterate over all possible subarrays and find the maximum sum. The outer loop will mark the starting point of a subarray and inner …

  6. Maximum Subarray Sum (Kadane's Algorithm) - w3resource

    May 15, 2024 · Walkthrough examples involve step-by-step demonstrations of how to identify the maximum ‘subarray’ sum in a given array using "Kadane's Algorithm". For instance, consider the array [−2, 1, −3, 4, −1, 2, 1, −5, 4]. Walk through the algorithm's execution to find the maximum ‘subarray’ sum and the corresponding ‘subarray’.

  7. Maximum Good Subarray Sum solution in Java - blog.heycoach.in

    Dec 14, 2024 · Explore the Maximum Good Subarray Sum Solution in Java with detailed explanations, code examples, and related problems.

  8. 53. Maximum Subarray - LeetSolve

    Apr 4, 2022 · int maxSubArray (vector < int >& nums) { int maxSum = -10000; int currSum = 0; for (auto & num : nums) { currSum = currSum < 0? num : currSum + num; maxSum = max(maxSum, currSum); } return maxSum; } int main { vector < int > nums = {-2, 1,-3, 4,-1, 2, 1,-5, 4}; cout << maxSubArray(nums) << endl; nums = {1}; cout << maxSubArray(nums) << endl ...

  9. Maximum Subarray - LeetCode

    Maximum Subarray - Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6.

  10. Maximum Subarray Sum - Starcoder

    Given an array of n integers, your task is to find the maximum sum of values in a contiguous, nonempty subarray. Explanation. Using prefix sum, we can create an array with all the prefix (or partial) sums. Using this array, we can then find that all the sums formed can be found with one of the prefix sums subtracting another.

  11. Some results have been removed
Refresh