Answer: Juspay | 21st October | Online Assessments
Answer · Posted Feb 2023
import java.util.*; public class Main { static class TreeNode{ String name; boolean isLocked; int id; TreeNode parent; int anc_locked; int des_locked; ArrayList<TreeNode> child= new ArrayList<>(); TreeNode(String name, TreeNode parent){ this.name=name; this.parent=parent; } } public static void main(String[] args) { int n = 3; int m = 2; String[] nodes = new String[]{"World","China","India"}; String[] queries = new String[]{"3 India 9", "1 World 9"}; Map<String, TreeNode> map= new HashMap<>(); TreeNode root= new TreeNode(nodes[0],null); map.put(nodes[0],root); Queue<TreeNode> queue = new LinkedList<>(); queue.add(root); int ...
The full answer & interview discussion are available to premium members.
Log in Create a free account