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

#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }

1 Answers  


how to test pierrot divisor

0 Answers  


main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }

2 Answers   IBM,


Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.

5 Answers   Amazon, Microsoft,


how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1 loop) and maximum 2 variables using C.

19 Answers   Cap Gemini, Infosys,






main() { int i=5,j=6,z; printf("%d",i+++j); }

2 Answers  


how to return a multiple value from a function?

2 Answers   Wipro,


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

2 Answers  


void main() { int c; c=printf("Hello world"); printf("\n%d",c); }

2 Answers  


Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped

1 Answers   IBM,


how to check whether a linked list is circular.

11 Answers   Microsoft,


Categories