kadane's algorithm
C
public int kadane(int[] arr){
int max_so_far = 0, curr_max = Integer.MIN_VALUE;
for(int i: arr){
max_so_far += i;
if(max_so_far<0) max_so_far = 0;
if(max_so_far>curr_max) curr_max = max_so_far;
}
return curr_max;
}# Python program to find maximum contiguous subarray
def maxSubArraySum(a,size):
max_so_far =a[0]
curr_max = a[0]
for i in range(1,size):
curr_max = max(a[i], curr_max + a[i])
max_so_far = max(max_so_far,curr_max)
return max_so_far
# Driver function to check the above function
a = [-2, -3, 4, -1, -2, 1, 5, -3]
print"Maximum contiguous sum is" , maxSubArraySum(a,len(a))
#This code is contributed by _Devesh Agrawal_
static int maxSubArraySum(int a[],int size)
{
int max_so_far = 0, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_ending_here < 0)
max_ending_here = 0;
/* Do not compare for all
elements. Compare only
when max_ending_here > 0 */
else if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
}
return max_so_far;
}
// This code is contributed by ANKITRAI1
Also in C:
- Title
- múltiplos entre dos numeros en c
- Category
- C
- Title
- c print array
- Category
- C
- Title
- sustituir un dígito por otro
- Category
- C
- Title
- java.lang.SecurityException: Permission denied (missing INTERNET permission?)
- Category
- C
- Title
- classification report to excel
- Category
- C
- Title
- tar cmd
- Category
- C
- Title
- left me on read
- Category
- C
- Title
- delete docker image repository none
- Category
- C
- Title
- remove an element from a set
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- c bit access union
- Category
- C
- Title
- sum of arrays
- Category
- C
- Title
- switch case c
- Category
- C
- Title
- c fill 2d array
- Category
- C
- Title
- code wars responsable drinker
- Category
- C
- Title
- concatenate two strings in c
- Category
- C
- Title
- c isdigit function
- Category
- C
- Title
- factorial of a given number in c
- Category
- C
- Title
- get current used proxy windows 7
- Category
- C
- Title
- download android ndk r 16
- Category
- C
- Title
- last element from list javascript
- Category
- C
- Title
- ModuleNotFoundError: No module named 'easydict'
- Category
- C
- Title
- sue murry
- Category
- C
- Title
- suma de n numeros recursiva
- Category
- C
- Title
- limit of integer in c
- Category
- C
- Title
- how to check where the last char is in a string c
- Category
- C
- Title
- C why is is & nit used in scan f fr string
- Category
- C
- Title
- docker logs follow
- Category
- C
- Title
- arduino millis()
- Category
- C
- Title
- C largest unsigned int
- Category
- C
- Title
- debian install npm
- Category
- C
- Title
- c print hello world
- Category
- C
- Title
- kadane's algorithm
- Category
- C
- Title
- read files in c
- Category
- C
- Title
- How to pull images from Docker Registry
- Category
- C
- Title
- how to download file in powershell
- Category
- C
- Title
- -> operator
- Category
- C
- Title
- how to call the tkinter insert command from another class
- Category
- C
- Title
- c printf uint32_t
- Category
- C
- Title
- too few arguments to function in c
- Category
- C
- Title
- pop and push shows black screen which needs to be pressed back flutter
- Category
- C
- Title
- c program to perform transpose of a matrix
- Category
- C
- Title
- malloc in c
- Category
- C
- Title
- text wrap terminal colour
- Category
- C
- Title
- how to ascii art in c
- Category
- C
- Title
- es palindromo
- Category
- C
- Title
- es vocal
- Category
- C
- Title
- oop244
- Category
- C
- Title
- get_session` is not available when using TensorFlow 2.0.
- Category
- C
- Title
- c check if char is number
- Category
- C
- Title
- Switch Mode C Programming
- Category
- C
- Title
- arduino vscode upload choosing sketch
- Category
- C
- Title
- heitai bestial
- Category
- C
- Title
- hentai clochette
- Category
- C
- Title
- docker images command
- Category
- C
- Title
- pi in c language
- Category
- C
- Title
- root in C
- Category
- C
- Title
- strcat in c
- Category
- C
- Title
- keras conv2d batchnorm
- Category
- C
- Title
- multiplication in c
- Category
- C
- Title
- what is conio.h
- Category
- C
- Title
- c radians
- Category
- C
- Title
- how to do matrix multiplication in c
- Category
- C
- Title
- error: ‘cout’ was not declared in this scope
- Category
- C
- Title
- css selector for sibling element
- Category
- C
- Title
- print in c
- Category
- C
- Title
- c how to define a variable
- Category
- C
- Title
- buscar caracter
- Category
- C
- Title
- c matrix sintax
- Category
- C
- Title
- what is the meaningof noremap
- Category
- C
- Title
- a enum data type in c with loop
- Category
- C
- Title
- bash: apt-add-repository: command not found
- Category
- C
- Title
- pasar a binario recursivo
- Category
- C
- Title
- error: dereferencing pointer to incomplete type
- Category
- C
- Title
- printf in c
- Category
- C
- Title
- strrev in c
- Category
- C
- Title
- change no_turbo
- Category
- C
- Title
- Declare macro
- Category
- C
- Title
- how to put quotes inside string c
- Category
- C
- Title
- how to store a user input with spaces in c
- Category
- C
- Title
- slurm array job
- Category
- C
- Title
- docker run port mapping
- Category
- C
- Title
- c defined value sum
- Category
- C
- Title
- what is restrict keyword in c
- Category
- C
- Title
- append to list in c
- Category
- C
- Title
- C/c drop mime
- Category
- C
- Title
- typedef vs #define
- Category
- C
- Title
- a enum data type in c
- Category
- C
- Title
- accessing elements 2D array using pointers
- Category
- C
- Title
- c program to find the sum of given number
- Category
- C
- Title
- vbnet create and write on file
- Category
- C
- Title
- how to remove \n from a string c
- Category
- C
- Title
- strtok
- Category
- C
- Title
- curl post request
- Category
- C
- Title
- .\main.c:4:8: error: expected declaration specifiers or '...' before '\x6f726c64'
- Category
- C
- Title
- entity framework core discard changes
- Category
- C
- Title
- msdos
- Category
- C
- Title
- does strcat null terminate
- Category
- C
- Title
- matplotlib plot circle marker
- Category
- C
- Title
- infinite loop using while
- Category
- C