You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum, within a given one-dimensional array A[1...n] of numbers.
5
+
This is one of the most popular problems and is asked in almost all of the Technical Interviews of top Companies.
6
+
Kadne's algorithm can be used to find the sum of the largest sum contiguous subarray or modified to find the subarray itself.
7
+
8
+
Contributor's Note:
9
+
This is a pretty easy algorithm to understand, although, seems a little scary by its name. I faced this problem in the interviews of companies like Walmart and Amazon.
10
+
11
+
For a Video based Explanation, check out my favorite video on this topic:
12
+
https://youtu.be/jnoVtCKECmQ
13
+
14
+
*/
15
+
16
+
importjava.util.*;
17
+
18
+
classkadane{
19
+
publicstaticvoidmain(String[] args)
20
+
{
21
+
Scanners = newScanner(System.in);
22
+
23
+
System.out.print("Enter Size of Array :");
24
+
intarr_size = s.nextInt();
25
+
26
+
int[] arr = newint[arr_size];
27
+
28
+
inti;
29
+
30
+
System.out.println("Enter Elements : ");
31
+
32
+
for(i=0;i<arr_size;i++)
33
+
arr[i] = s.nextInt();
34
+
35
+
System.out.print("The maximum contiguous subarray sum is : ");
0 commit comments