Round 1
Questions: You are tasked with managing a set of jobs, each identified by a string ID and associated with a weight. Implement a system where you can submit jobs and select the job with the maximum weight. If a job with the same ID already exists, you should sum up its weight with the new weight provided.
Implement the following two methods:
1. submit(String jobID, int weight)
- Accepts a jobID (string) and weight (integer).
- If the job with the given jobID already exists, add the new weight to the existing weight.
- If the job does not exist, create a new job with the given jobID and weight.
2. select()
- Returns the jobID of the job with the maximum weight.
- If there are multiple jobs with the same maximum weight, return the one that was submitted last.
- If no jobs exist, return null.
Examples:
# Example 1 submit("A", 2) submit("B", 6) submit("C", 3) submit("D", 4) submit("A", 3) select() # Returns "B" select() # Returns "A" select() # Returns "D" submit("A", 2) select() # Returns "C" select() # Returns "A" select() # Returns null # Example 2 submit("X", 10) # Adds job "X" with weight 10 submit("Y", 5) # Adds job "Y" with weight 5 submit("Z", 7) # Adds job "Z" with weight 7 submit("X", 4) # Updates job "X" by adding weight 4 (total weight of X = 14) submit("Y", 10) # Updates job "Y" by adding weight 10 (total weight of Y = 15) submit("Z", 7) # Updates job "Z" by adding weight 2 (total weight of Z = 14) select() # Returns "Y" weight is 15 select() # Returns "X" weight is 14 and was added first select() # Returns "Z" weight is 14 select() # Returns null select() # Returns null
Boilerplate Java Code with Class Job and Solution Class JobSolution
import java.util.HashMap; import java.util.Map; class Job { String jobID; int weight; Job(String jobID, int weight) { this.jobID = jobID; this.weight = weight; } } class JobSolution { // Submit a job with the given ID and weight. public void submit(String jobID, int weight) { // Implement this method } // Select the job with the highest weight. public String select() { // Implement this method return null; } }
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.
Round 2
Questions: Convert String to Integer given very basic constraints that it will fit in the Integer boundaries. Could have negative numbers too. Cannot use existing Parser like Integer.Parse(int).
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.