Amazon SDE Challenge - April/ May 2022
Minimize difference
You are given a tree with Nvertices numbered from 1to N The th edge connects Vertex X and Vertex y bidirectionally You have to divide this tree into three connected components by cuttinc any two edges of the tree. Let the three components be C, C2 and C3 Let X, X2 and X3 be the XOR of all the vertices of the components C, C2 and C3 respectively
Task
Minimize the difference between the maximum and minimum xor values of the components In short, you have to minimize the value of max(X, X2 X3) min(X, X2 X3)
Notes
- A tree is an undirected. connected and acyclic graph.
- A set of nodes forms a connected component in a tree if any node from the set of nodes can reach any other node by traversing edges.
- The bitwise XOR of integers : and B A XOR B. is when A XOR B is written in base two. the digit in the 2ks place k 20i1if exactly one of A and B is 1 and C otherwise For example, XOR of (101)2 and (110)2, is (011)2.
- Cutting an edge means partitioning the vertices of the tree into two disioint subsets. In other words. cutting an edge results in an increase in the number of connected components.
1 |
|