Amazon Phone Interview | AWS | AppFabric | Amazon Q

Anonymous User
555
Jul 30, 2024

Question:

Amazon has to process numerous critical business intelligence jobs a day.
Most of those tend to be very computationally heavy in nature such that they require a single virtual machine while they run and need to be guaranteed to run between certain times.
Given a set of jobs we need to know how many virtual machines we will need to provision?
Given a set of jobs with start and end times {(6,8), (2,5), (3,7)} calculate the number of virtual machines required to execute all those jobs?

My Attempt:
Thought this would be a merge intervals problem but I fumbled hard. This was my attempt:

public int totalVirtualMachines(int[][] jobIntervals) {
    
    if(jobIntervals == null || jobIntervals.length == 0)
        return 0;
    
    Arrays.sort(jobIntervals, Comparator.comparingInt( a -> a[0]));
    
    List<int[]> merged = new ArrayList<>();
    
    int[] currentInterval = jobIntervals[0];
    
    for(int i = 1; i < jobIntervals.length; i++) {
        
        int[] interval = jobIntervals[i];
        
        if(currentInterval[1] >= interval[0]) {
            
            currentInterval[1] = Math.max(currentInterval[1], interval[1]);
            
        }
        
        else {
            merged.add(currentInterval);
            
            currentInterval = interval;
            
            
        }
        
    }
    
    merged.add(currentInterval);
    
    return jobIntervals.size() - merged.size() + 1;
    
}

Anyone have advice on how to prepare for these kinds of interview questiosns? Questions I haven't seen before or don't have something similar on Leetcode I'm not sure how to solve. If it is some variation of a leetcode problem, I can do it but does anyone know if there is a variation for this?

Anyone know where Amazon gets their interview questions from?

Comments (4)