I have similar algorithm, but yours must be faster.

class Log { int id; String status; int ts; Log (int id, String status, int ts) { this.id = id; this.status = status; this.ts = ts; } } public int[] exclusiveTime(int n, List<String> logs) { int[] res = new int[n]; if (logs == null || logs.size() == 0) return res; int size = logs.size(); Stack<Log> stack = new Stack<>();//only start status will be stored in stack int idx = 0; while (idx < size) { String[] log = logs.get(idx++).split(":"); Log cur = new Log(Integer.parseInt(log[0]), log[1], Integer.parseInt(log[2])); if (stack.isEmpty()) stack.push(cur); else { Log prev = stack.peek(); if (prev.status.equals(cur.status)) { res[prev.id] += cur.ts - prev.ts; stack.push(cur); } else { res[prev.id] += cur.ts - prev.ts + 1; stack.pop(); if (!stack.isEmpty()) { Log fix = stack.pop(); fix.ts = cur.ts + 1; stack.push(fix); } } } } return res; }Exclusive Time of Functions