package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode.com/problems/kill-process/#/description
 */
public class Problem582 {
    public List<Integer> killProcess(List<Integer> pid, List<Integer> ppid, int kill) {
        List<Integer> result = new ArrayList<>();
        // TODO
        return result;
    }

    public static void main(String[] args) {
        Problem582 prob = new Problem582();
        System.out.println(prob.killProcess(Arrays.asList(1, 3, 10, 5), Arrays.asList(3, 0, 5, 3), 5)); // [5, 10]
    }
}

@@ -57,22 +57,23 @@
 va.util.
-Arrays
+HashMap
 ;%0Aimport
@@ -88,16 +88,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -356,15 +356,119 @@
     
-// TODO
+result.add(kill);%0A        Map%3CInteger, Node%3E tree = buildTree(pid, ppid);%0A        kill(tree.get(kill), result);
 %0A   
@@ -499,21 +499,22 @@
 %7D%0A%0A    p
-ublic
+rivate
  static 
@@ -522,188 +522,1198 @@
 oid 
-main(String%5B%5D args) %7B%0A        Problem582 prob = new Problem582();%0A        System.out.println(prob.killProcess(Arrays.asList(1, 3, 10, 5), Arrays.asList(3, 0, 5, 3), 5)); // %5B5, 10%5D
+kill(Node node, List%3CInteger%3E result) %7B%0A        for (Node n : node.children) %7B%0A            result.add(n.pid);%0A            kill(n, result);%0A        %7D%0A    %7D%0A%0A    private static Map%3CInteger, Node%3E buildTree(List%3CInteger%3E pid, List%3CInteger%3E ppid) %7B%0A        Map%3CInteger, Node%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C pid.size(); i++) %7B%0A            int parent = ppid.get(i);%0A            int child = pid.get(i);%0A%0A            Node parentNode = null;%0A            if (!map.containsKey(parent)) %7B%0A                parentNode = new Node(parent);%0A                map.put(parent, parentNode);%0A            %7D else %7B%0A                parentNode = map.get(parent);%0A            %7D%0A%0A            Node childNode = null;%0A            if (!map.containsKey(child)) %7B%0A                childNode = new Node(child);%0A                map.put(child, childNode);%0A            %7D else %7B%0A                childNode = map.get(child);%0A            %7D%0A            parentNode.children.add(childNode);%0A        %7D%0A        return map;%0A    %7D%0A%0A    private static class Node %7B%0A        private final int pid;%0A        private List%3CNode%3E children = new ArrayList%3C%3E();%0A%0A        public Node(int pid) %7B%0A            this.pid = pid;%0A        %7D
 %0A   

Solve problem 582