Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,360 views

For proper oa or interview experiences list of all top tech companies visit :

https://oa.desiqna.in

https://interview.desiqna.in

 

in Online Assessments by Expert (46,090 points) | 1,360 views

1 Answer

0 like 0 dislike

Online Assessment Question :

image

image

image

 

by Expert (46,090 points)
0 0
// https://www.desiqna.in/9248/amazon-internship-coding-questions-solutions-2022-london
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        
        for(int i=0;i<n;++i)
            arr[i] = s.nextInt();
        
        long res = f(arr,n);
        System.out.println(res);
    }
    public static long f(int[] arr,int n){
        long max = 0;
        long sum = 0;
        for(int a : arr)
            sum += a;
        
        int movingsum = 0;
        for(int a : arr){
            movingsum += a;
            max = Math.max(max,Math.max(movingsum,sum));
            sum -= a;
        }
        
        return max;
    }
}