The Wayback Machine - https://web.archive.org/web/20220607044804/https://www.geeksforgeeks.org/amazon-interview-experience-for-sde-ii-2/
Skip to content
Related Articles

Related Articles

Amazon Interview Experience for SDE-II

Improve Article
Save Article
Like Article
  • Last Updated : 03 Jun, 2022

I got a call from an Amazon recruiter. She sent me the coding test link which I had to complete within a week. The given link consisted of three rounds of challenges and each round was mandatory to complete successfully the given assessment.  Below were the rounds.

Online Round (Coding Test – 90 mins):

Prob1.  Amazon Shopping recently launched a new item whose daily customer ratings for n days are represented by the array ratings. They monitor these ratings to identify products that are not performing well. Find the number of groups that can be formed consisting of 1 or more consecutive days such that the ratings continuously decrease over the days.

The ratings are consecutively decreasing if it has the form: r,r-1,r-2.. and so on, where r is the rating on the first days of the group being considered. Two groups are considered different if they contain the ratings of different consecutive days.

My Solutions 

Java




/*package whatever //do not write package name here */
  
import java.util.*;
  
public class Test {
  
//testing
public static void main(String args[]) {
   
 Integer[] m_Arr = {4,3,5,4,3};
 List<Integer> m_ratings = Arrays.asList(m_Arr);
   
 long m_ans = countDecreasingRatings(m_ratings);
 System.out.println(m_ans); //9
   
}
  
public static long countDecreasingRatings(List<Integer> ratings){
    
  long mload = 0;
  long result = 0;
    
  for(int i = 0; i < ratings.size();i++){
   if (mload ==0){
    mload = 1;
   }
   else{
     if (ratings.get(i-1) == ratings.get(i)+1){
    mload ++;
  }
    
  else{
     result += sumOfNNumbers(mload);
     mload = 1;
   }
   }
  }
  result += sumOfNNumbers(mload);
  return result; 
 }
  
 private static long sumOfNNumbers(long m){
   if (m%2 ==0){
    return ((m/2)*(m+1));
   }
   else{
       return m*((m+1))/2;
   }
 }
}

Prob2. Amazon Academy recently organized a scholarship test on its platform. A total of n students participated in the test. Each student received a unique roll number, i. Each student’s rank is stored at rank[i]. Each student gets a unique rank, so the rank is a permutation of values 1 through n.

For improved collaboration, the students are to be divided into groups. Use the following rules to find the imbalance in a group of students.

  • A group has k students where 1 <=k<=n. Groups are formed of k students in the ranks with consecutive roll  numbers i.e  I, (i+1)..(i+k-1)
  • The ranks of the students in a group are then sorted ascending to an array, here named  sorted_rank.
  • The imbalance of the group is then defined as the number of students j, who are more than 1 rank
    beneath the rank of student just ahead of them,i.e sorted_rank[j] – sorted_rank[j-1] > 1

Java




/*package whatever //do not write package name here */
  
import java.util.*;
  
public class Test {
      
    //testing
    public static void main(String args[]) {
          
        Integer[] m_Arr = {4,1,3,2};
        List<Integer> m_ratings = Arrays.asList(m_Arr);
          
        long m_ans = findTotalm_imbalance(m_ratings);
        System.out.println(m_ans); //3
          
    }
      
    public static long findTotalm_imbalance(List<Integer> rank){
           
         long m_imbalance = 0;
          int r  = 0;
            
          TreeSet<Integer> m_set = new TreeSet<>();
            
          while ( r < rank.size()-1) {
              m_set.clear();
              m_set.add(rank.get(r));
              long curm_imbalance = 0;
                
              for (int i = r + 1; i < rank.size();i++) {
                  Integer e = rank.get(i);
                  m_set.add(e);
                  Integer f = m_set.lower(e);
                  Integer c = m_set.higher(e);
                    
                  if (f == null) {
                      curm_imbalance += ((c-e)>1?1:0);
                  }
                    
                  else if (c == null) {
                      curm_imbalance += (((e-f)>1)?1:0);
                  }
                    
                  else {
                      curm_imbalance += (c-f)>1?-1:0;
                      curm_imbalance += (((c-e)>1)?1:0);
                      curm_imbalance += ((e-f))>1?1:0;
                  }
                  m_imbalance += curm_imbalance;
              }
              r ++;
          }
            
          return m_imbalance;     
    }
  
}

Work Simulation ( typically takes 15 minutes)

  • Work Simulation – typically takes 15 minutes, work through software development decisions faced by SDEs at Amazon.

Work Style Surveys(typically takes 10 minutes)

  • Work Style Surveys – typically takes 10 minutes, 2 surveys – answer questions about how you approach software engineering work and your approach to work in general


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!