Amazon Interview Question for SDE1s


Country: India




Comment hidden because of low score. Click to expand.
1
of 1 vote

public int solve(int[] array){
        if(array.length<=1){
            return 0;
        }

        int mod = (int)(1e9+7);
        int sum = 0;
        int pre_sum = array[0];
        for(int i=1;i<array.length;i++){
              sum += (pre_sum%array[i]);
              pre_sum+=array[i];
              sum %= mod;
              pre_sum %= mod;
        }

        int suffix_sum = array[array.length-1];
        for(int i=array.length-2;i>=0;i--){
            sum += (suffix_sum%array[i]);
            suffix_sum += array[i];
            sum %= mod;
            suffix_sum %= mod;
        }

        return sum;
    }

- lixx3527 July 27, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you explain me the idea behind your solution

- rajksingh3878 June 21, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The solution is for sorted array.

- Ak July 01, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Have anyone solved it ?

- Anonymous July 02, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SumOfIntegers {
    public static void main(String[] args) {
        int[] arr = new int[] {1,2,3};
        long sum = 0;
        for(int i=0;i<arr.length;i++){
            int k= (i+1)%3;
            sum+=arr[i]%arr[k];
            sum+=arr[k]%arr[i];
        }

        sum+=sum%(Math.pow(10, 9)+7);

        System.out.println(sum);
    }

}

- shashi July 16, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you explain the logic in detail?

- Srinivas September 11, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SumOfIntegers {
public static void main(String[] args) {
int[] arr = new int[] {1,2,3};
long sum = 0;
for(int i=0;i<arr.length;i++){
int k= (i+1)%3;
sum+=arr[i]%arr[k];
sum+=arr[k]%arr[i];
}

sum+=sum%(Math.pow(10, 9)+7);

System.out.println(sum);
}
}

- shashi July 16, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class Solution
{
public static void main(String[] args)
{
int[] A = new int[] {1, 2, 3};
int n = A[A.length-1];
long sum = 0;
for(int i = 1; i <= n; i++)
{
int q = n / i;
int r = n % i;
sum += (long)((i*(i-1)/2)*q + r*(r+1)/2);
}
System.out.println(sum % (long)(Math.pow(10, 9)+7));
}
}

- Anonymous January 21, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

import java.util.*;
public class Solution
{
public static void main(String[] args)
{
int[] A = new int[] {1, 2, 3};
int n = A[A.length-1];
long sum = 0;
for(int i = 1; i <= n; i++)
{
int q = n / i;
int r = n % i;
sum += (long)((i*(i-1)/2)*q + r*(r+1)/2);
}
System.out.println(sum % (long)(Math.pow(10, 9)+7));
}
}

- palashwankar June 19, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

Please dont post solutions without understanding question.

- code reviewer June 19, 2019 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More