You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/g2301_2400/s2322_minimum_score_after_removals_on_a_tree/readme.md
+4-24
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Remove two **distinct** edges of the tree to form three connected components. Fo
11
11
1. Get the XOR of all the values of the nodes for **each** of the three components respectively.
12
12
2. The **difference** between the **largest** XOR value and the **smallest** XOR value is the **score** of the pair.
13
13
14
-
* For example, say the three components have the node values: `[4,5,7]`, `[1,9]`, and `[3,3,3]`. The three XOR values are `4 ^ 5 ^ 7 = <ins>**6**</ins>`, `1 ^ 9 = <ins>**8**</ins>`, and `3 ^ 3 ^ 3 = <ins>**3**</ins>`. The largest XOR value is `8` and the smallest XOR value is `3`. The score is then `8 - 3 = 5`.
14
+
* For example, say the three components have the node values: `[4,5,7]`, `[1,9]`, and `[3,3,3]`. The three XOR values are <code>4 ^ 5 ^ 7 = <ins>**6**</ins></code>, <code>1 ^ 9 = <ins>**8**</ins></code>, and <code>3 ^ 3 ^ 3 = <ins>**3**</ins></code>. The largest XOR value is `8` and the smallest XOR value is `3`. The score is then `8 - 3 = 5`.
15
15
16
16
Return _the **minimum** score of any possible pair of edge removals on the given tree_.
17
17
@@ -23,17 +23,7 @@ Return _the **minimum** score of any possible pair of edge removals on the given
23
23
24
24
**Output:** 9
25
25
26
-
**Explanation:** The diagram above shows a way to make a pair of removals.
27
-
28
-
- The 1<sup>st</sup> component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10.
29
-
30
-
- The 2<sup>nd</sup> component has node [0] with value [1]. Its XOR value is 1 = 1.
31
-
32
-
- The 3<sup>rd</sup> component has node [2] with value [5]. Its XOR value is 5 = 5.
33
-
34
-
The score is the difference between the largest and smallest XOR value which is 10 - 1 = 9.
35
-
36
-
It can be shown that no other pair of removals will obtain a smaller score than 9.
26
+
**Explanation:** The diagram above shows a way to make a pair of removals. - The 1<sup>st</sup> component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10. - The 2<sup>nd</sup> component has node [0] with value [1]. Its XOR value is 1 = 1. - The 3<sup>rd</sup> component has node [2] with value [5]. Its XOR value is 5 = 5. The score is the difference between the largest and smallest XOR value which is 10 - 1 = 9. It can be shown that no other pair of removals will obtain a smaller score than 9.
37
27
38
28
**Example 2:**
39
29
@@ -43,17 +33,7 @@ It can be shown that no other pair of removals will obtain a smaller score than
43
33
44
34
**Output:** 0
45
35
46
-
**Explanation:** The diagram above shows a way to make a pair of removals.
47
-
48
-
- The 1<sup>st</sup> component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0.
49
-
50
-
- The 2<sup>nd</sup> component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0.
51
-
52
-
- The 3<sup>rd</sup> component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0.
53
-
54
-
The score is the difference between the largest and smallest XOR value which is 0 - 0 = 0.
55
-
56
-
We cannot obtain a smaller score than 0.
36
+
**Explanation:** The diagram above shows a way to make a pair of removals. - The 1<sup>st</sup> component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0. - The 2<sup>nd</sup> component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0. - The 3<sup>rd</sup> component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0. The score is the difference between the largest and smallest XOR value which is 0 - 0 = 0. We cannot obtain a smaller score than 0.
57
37
58
38
**Constraints:**
59
39
@@ -64,4 +44,4 @@ We cannot obtain a smaller score than 0.
0 commit comments