Program to find the largest sum of contiguous integers in
the array. O(n)

Answers were Sorted based on User's Feedback



Program to find the largest sum of contiguous integers in the array. O(n)..

Answer / harsha

Going by the answer 7..

max=0;
sum=0;

for i in 0 .. n
sum = sum + numbers[i];
if( sum > max ) {
max = sum;
}
else if (sum<0) {
sum=0;
}

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C Code Interview Questions

How do you write a program which produces its own source code as its output?

7 Answers  


# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }

1 Answers  


x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);

2 Answers  


how to return a multiple value from a function?

5 Answers   Wipro,


can u give me the c codings for converting a string into the hexa decimal form......

1 Answers  






what is variable length argument list?

2 Answers  


In a gymnastic competition, scoring is based on the average of all scores given by the judges excluding the maximum and minimum scores. Let the user input the number of judges, after that, input the scores from the judges. Output the average score. Note: In case, more than two judges give the same score and it happens that score is the maximum or minimum then just eliminate two scores. For example, if the number of judges is 5 and all of them give 10 points each. Then the maximum and minimum score is 10. So the computation would be 10+10+10, this time. The output should be 10 because 30/3 is 10.

0 Answers   TCS,


#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }

2 Answers  


writte a c-programm to display smill paces

2 Answers  


Write a program that produces these three columns sequence nos. using loop statement Sequence nos. Squared Squared + 5 1 1 6 2 4 9 3 9 14 4 16 21 5 25 30

1 Answers   GoDB,


void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }

3 Answers  


how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!

8 Answers   GATE,


Categories