Amazon SDE-2 Interview Round1 : 03-Sept-25
Company: Amazon
Role: SDE II
Interview Stage: Phone Screen
Location: unknown
Year: 2025
Original Post Content:
I was asked to design a Hospital Emergency Room system where patients are admitted based on priority.
The priorities were defined as follows:
The requirement was to ensure that this priority order is always maintained.
My Approach:
I proposed using a PriorityQueue with a custom comparator to manage patients based on the given conditions.
I designed a Patient class with the following fields:
class Patient {
int id;
String name;
int age;
boolean isCritical;
int severity;
int timeOfArrival;
Patient(int id, String name, int age, boolean isCritical, int severity, int timeOfArrival) {
this.id = id;
this.name = name;
this.age = age;
this.isCritical = isCritical;
this.severity = severity;
this.timeOfArrival = timeOfArrival;
}
}
The interviewer asked clarifying questions that led me to add:
*timeOfArrival* → to handle tie-breaking when all conditions are the same.
*isCritical* → to identify patients in an emergency stage.
I was then asked to implement three functions:
*addPatient()* – Insert a new patient into the PriorityQueue.
*displayOrder()*– Print the current queue.
*getNextPatient()* – Retrieve the next patient from the PriorityQueue.
The main challenge was writing the custom comparator for the PriorityQueue that sorts in the following order:
*isCritical → age → severity → timeOfArrival.*
Custom Comparator Implementation:
PriorityQueue<Patient> pq = new PriorityQueue<>((a, b) -> {
// 1. Critical condition first
if (a.isCritical != b.isCritical) {
return Boolean.compare(b.isCritical, a.isCritical);
}
// 2. Age > 65 gets priority (then children < 12)
if ((a.age > 65 || a.age < 12) && (b.age > 65 || b.age < 12)) {
return Integer.compare(b.age, a.age); // higher age first, else lower age for children
} else if (a.age > 65 || a.age < 12) {
return -1; // a has higher priority
} else if (b.age > 65 || b.age < 12) {
return 1; // b has higher priority
}
// 3. Severity (higher severity first)
if (a.severity != b.severity) {
return Integer.compare(b.severity, a.severity);
}
// 4. Time of arrival (earlier patients first)
return Integer.compare(a.timeOfArrival, b.timeOfArrival);
});
Where I Struggled:
I could not complete the custom comparator during the interview and ended up providing only pseudocode.
Follow-up Questions:
What is the difference between offer() and add() in a PriorityQueue?
What is the time complexity of the add() operation?
Behavioral Round (Leadership Principles):
Q: Tell me about a time when you felt stuck in your project. What did you do to move forward?
✅ Takeaway:
This round tested both DSA problem-solving (through PriorityQueue + custom comparator design) and behavioral skills (leadership principles).
Key learning: Be confident in implementing comparators and always understand the internal workings of data structures like PriorityQueue.