PhonePe Machine Coding Round..What's the best way to implement it on production systems?
Coding Round
Questions: You need to design a system that is able to track pending entities. An entity is identified using a unique ID and a list of hierarchical tags. There are 3 parts to this problem statement: startTracking, endTracking, and getCounts.
-
startTracking:
void startTracking(Integer id, List hierarchicalTags);
- id = Identifier of the entity
- hierarchicalTags = Tags that are properties of the entity. These tags are hierarchical in nature.
-
stopTracking:
void stopTracking(Integer id);
- id = Identifier of the transaction
-
getCounts:
Integer getCounts(List tags);
- tags = a hierarchy of tags, for which counts are to be retrieved
Sample Usage:
startTracking(1112, ["UPI", "Karnataka", "Bangalore"]); startTracking(2451, ["UPI", "Karnataka", "Mysore"]); startTracking(3421, ["UPI", "Rajasthan", "Jaipur"]); startTracking(1221, ["Wallet", "Karnataka", "Bangalore"]); getCounts(["UPI"]); // Output: 3 getCounts(["UPI", "Karnataka"]); // Output: 2 getCounts(["UPI", "Karnataka", "Bangalore"]); // Output: 1 getCounts(["Bangalore"]); // Output: 0 startTracking(4221, ["Wallet", "Karnataka", "Bangalore"]); stopTracking(1112); stopTracking(2451); getCounts(["UPI"]); // Output: 1 getCounts(["Wallet"]); // Output: 2 getCounts(["UPI", "Karnataka", "Bangalore"]); // Output: 0
Requirements:
- Implement the above with appropriate assumptions.
- Optimize for time/space complexity.
- Use in-memory data structures only.
- A working code is necessary for evaluation.
Candidate's Approach
No approach provided.
Interviewer's Feedback
Interviewers are not impressed by the solution provided.