Round1 - Low Level Design
LP
Round 2 - Hiring Manager - System Design
LP
Round 3 - Coding
LP
Medium question, didnt come across in leetcode but could be solved using priority queue in under 20 mins
Round 4 - Coding
LP
Design a lottery system where a customer can buy a lottery ticket ranging from 1 cent to 100 dollars. At the end of sale of all lottery ticket we will have a lucky draw where a winner will be chosen randomly and the chances of winning a customer should be according to the price they have paid for the ticket in other words the one who paid more should have more chances of winning.
Interviewer had a certain solution in mind, struggled a lot to arrive at that, came up with something similar, not sure if this helped
import java.util.*;
class LotterySystem {
private final NavigableMap<Integer, String> ticketMap;
private final Random random;
private int totalWeight;
public LotterySystem() {
this.ticketMap = new TreeMap<>();
this.random = new Random();
this.totalWeight = 0;
}
public void buyTicket(String customer, int amount) {
if (amount < 1 || amount > 10000) {
throw new IllegalArgumentException("Ticket price must be between 1 cent and 100 dollars");
}
totalWeight += amount;
ticketMap.put(totalWeight, customer);
}
public String drawWinner() {
if (ticketMap.isEmpty()) {
throw new IllegalStateException("No tickets sold, cannot draw a winner");
}
int luckyNumber = random.nextInt(totalWeight) + 1;
return ticketMap.ceilingEntry(luckyNumber).getValue();
}
public static void main(String[] args) {
LotterySystem lottery = new LotterySystem();
lottery.buyTicket("Alice", 500); // Alice buys a ticket worth $5.00
lottery.buyTicket("Bob", 1000); // Bob buys a ticket worth $10.00
lottery.buyTicket("Charlie", 200); // Charlie buys a ticket worth $2.00
System.out.println("The winner is: " + lottery.drawWinner());
}
}Spent nearly half an hour in LP principle for each round. Its okay to repeat stories if the questions repeat. All the best!
Verdict: Accepted
Compensation Details -
https://leetcode.com/discuss/compensation/6389764/Amazon-London-SDE2