From b38a10c9611ca83ab29b3ea3a574294f5b6681d8 Mon Sep 17 00:00:00 2001 From: subbu4061 Date: Sat, 7 Feb 2026 16:25:55 -0800 Subject: [PATCH] Adding the solutions --- EmployeeImportance.java | 23 +++++++++++++++++ RottingOranges.java | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 EmployeeImportance.java create mode 100644 RottingOranges.java diff --git a/EmployeeImportance.java b/EmployeeImportance.java new file mode 100644 index 0000000..a144129 --- /dev/null +++ b/EmployeeImportance.java @@ -0,0 +1,23 @@ +// Time Complexity : O(n) +// Spcae Complexity: O(n) +// Explanaytion : I first store every employee in a HashMap using their id so that I can retrieve any employee in O(1) time. Then I use a queue to perform a BFS starting from the given id, adding all subordinates level by level. For each employee I dequeue, I add their importance to the total and push their subordinates into the queue. +class Solution { + public int getImportance(List employees, int id) { + Map map = new HashMap<>(); + Queue q = new LinkedList<>(); + for(int i=0; i q = new LinkedList<>(); + for(int i =0; i=0 && j>=0 && i