From 726ca323b371d2faaf03049c075d616fa7a002ae Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 27 Jul 2025 15:47:25 +0300 Subject: [PATCH 1/3] Added tasks 3627-3630 --- .../Solution.java | 18 ++++ .../readme.md | 43 +++++++++ .../Solution.java | 47 ++++++++++ .../readme.md | 44 ++++++++++ .../Solution.java | 88 +++++++++++++++++++ .../readme.md | 59 +++++++++++++ .../Solution.java | 41 +++++++++ .../readme.md | 71 +++++++++++++++ .../SolutionTest.java | 18 ++++ .../SolutionTest.java | 23 +++++ .../SolutionTest.java | 23 +++++ .../SolutionTest.java | 23 +++++ 12 files changed, 498 insertions(+) create mode 100644 src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/Solution.java create mode 100644 src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/readme.md create mode 100644 src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/Solution.java create mode 100644 src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/readme.md create mode 100644 src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/Solution.java create mode 100644 src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/readme.md create mode 100644 src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java create mode 100644 src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/readme.md create mode 100644 src/test/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/SolutionTest.java create mode 100644 src/test/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/SolutionTest.java create mode 100644 src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java create mode 100644 src/test/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/SolutionTest.java diff --git a/src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/Solution.java b/src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/Solution.java new file mode 100644 index 000000000..3db4c23cb --- /dev/null +++ b/src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/Solution.java @@ -0,0 +1,18 @@ +package g3601_3700.s3627_maximum_median_sum_of_subsequences_of_size_3; + +// #Medium #Weekly_Contest_460 #2025_07_27_Time_22_ms_(100.00%)_Space_129.50_MB_(86.95%) + +import java.util.Arrays; + +public class Solution { + public long maximumMedianSum(int[] nums) { + int n = nums.length; + Arrays.sort(nums); + int m = n / 3; + long sum = 0; + for (int i = n - 2; i >= n - 2 * m; i = i - 2) { + sum = sum + nums[i]; + } + return sum; + } +} diff --git a/src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/readme.md b/src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/readme.md new file mode 100644 index 000000000..78578f28c --- /dev/null +++ b/src/main/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/readme.md @@ -0,0 +1,43 @@ +3627\. Maximum Median Sum of Subsequences of Size 3 + +Medium + +You are given an integer array `nums` with a length divisible by 3. + +You want to make the array empty in steps. In each step, you can select any three elements from the array, compute their **median**, and remove the selected elements from the array. + +The **median** of an odd-length sequence is defined as the middle element of the sequence when it is sorted in non-decreasing order. + +Return the **maximum** possible sum of the medians computed from the selected elements. + +**Example 1:** + +**Input:** nums = [2,1,3,2,1,3] + +**Output:** 5 + +**Explanation:** + +* In the first step, select elements at indices 2, 4, and 5, which have a median 3. After removing these elements, `nums` becomes `[2, 1, 2]`. +* In the second step, select elements at indices 0, 1, and 2, which have a median 2. After removing these elements, `nums` becomes empty. + +Hence, the sum of the medians is `3 + 2 = 5`. + +**Example 2:** + +**Input:** nums = [1,1,10,10,10,10] + +**Output:** 20 + +**Explanation:** + +* In the first step, select elements at indices 0, 2, and 3, which have a median 10. After removing these elements, `nums` becomes `[1, 10, 10]`. +* In the second step, select elements at indices 0, 1, and 2, which have a median 10. After removing these elements, `nums` becomes empty. + +Hence, the sum of the medians is `10 + 10 = 20`. + +**Constraints:** + +* 1 <= nums.length <= 5 * 105 +* `nums.length % 3 == 0` +* 1 <= nums[i] <= 109 \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/Solution.java b/src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/Solution.java new file mode 100644 index 000000000..981f0db4b --- /dev/null +++ b/src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/Solution.java @@ -0,0 +1,47 @@ +package g3601_3700.s3628_maximum_number_of_subsequences_after_one_inserting; + +// #Medium #Weekly_Contest_460 #2025_07_27_Time_12_ms_(100.00%)_Space_45.76_MB_(72.28%) + +public class Solution { + public long numOfSubsequences(String s) { + long tc = 0; + char[] chs = s.toCharArray(); + for (char c : chs) { + tc += (c == 'T') ? 1 : 0; + } + long ls = 0; + long cs = 0; + long lcf = 0; + long ctf = 0; + long lct = 0; + long ocg = 0; + long tp = 0; + for (char curr : chs) { + long rt = tc - tp; + long cg = ls * rt; + ocg = (cg > ocg) ? cg : ocg; + if (curr == 'L') { + ls++; + } else { + if (curr == 'C') { + cs++; + lcf += ls; + } else { + if (curr == 'T') { + lct += lcf; + ctf += cs; + tp++; + } + } + } + } + long fcg = ls * (tc - tp); + ocg = fcg > ocg ? fcg : ocg; + long maxi = 0; + long[] bo = {lcf, ctf, ocg}; + for (long op : bo) { + maxi = op > maxi ? op : maxi; + } + return lct + maxi; + } +} diff --git a/src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/readme.md b/src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/readme.md new file mode 100644 index 000000000..baf680746 --- /dev/null +++ b/src/main/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/readme.md @@ -0,0 +1,44 @@ +3628\. Maximum Number of Subsequences After One Inserting + +Medium + +You are given a string `s` consisting of uppercase English letters. + +You are allowed to insert **at most one** uppercase English letter at **any** position (including the beginning or end) of the string. + +Return the **maximum** number of `"LCT"` subsequences that can be formed in the resulting string after **at most one insertion**. + +**Example 1:** + +**Input:** s = "LMCT" + +**Output:** 2 + +**Explanation:** + +We can insert a `"L"` at the beginning of the string s to make `"LLMCT"`, which has 2 subsequences, at indices [0, 3, 4] and [1, 3, 4]. + +**Example 2:** + +**Input:** s = "LCCT" + +**Output:** 4 + +**Explanation:** + +We can insert a `"L"` at the beginning of the string s to make `"LLCCT"`, which has 4 subsequences, at indices [0, 2, 4], [0, 3, 4], [1, 2, 4] and [1, 3, 4]. + +**Example 3:** + +**Input:** s = "L" + +**Output:** 0 + +**Explanation:** + +Since it is not possible to obtain the subsequence `"LCT"` by inserting a single letter, the result is 0. + +**Constraints:** + +* 1 <= s.length <= 105 +* `s` consists of uppercase English letters. \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/Solution.java b/src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/Solution.java new file mode 100644 index 000000000..cd3867c7a --- /dev/null +++ b/src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/Solution.java @@ -0,0 +1,88 @@ +package g3601_3700.s3629_minimum_jumps_to_reach_end_via_prime_teleportation; + +// #Medium #Weekly_Contest_460 #2025_07_27_Time_116_ms_(99.81%)_Space_76.00_MB_(67.96%) + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; + +public class Solution { + public int minJumps(int[] nums) { + int n = nums.length; + if (n == 1) { + return 0; + } + int maxVal = 0; + for (int v : nums) { + maxVal = Math.max(maxVal, v); + } + boolean[] isPrime = sieve(maxVal); + @SuppressWarnings("unchecked") + ArrayList[] posOfValue = new ArrayList[maxVal + 1]; + for (int i = 0; i < n; i++) { + int v = nums[i]; + if (posOfValue[v] == null) { + posOfValue[v] = new ArrayList<>(); + } + posOfValue[v].add(i); + } + boolean[] primeProcessed = new boolean[maxVal + 1]; + int[] dist = new int[n]; + Arrays.fill(dist, -1); + ArrayDeque q = new ArrayDeque<>(); + q.add(0); + dist[0] = 0; + while (!q.isEmpty()) { + int i = q.poll(); + int d = dist[i]; + if (i == n - 1) { + return d; + } + if (i + 1 < n && dist[i + 1] == -1) { + dist[i + 1] = d + 1; + q.add(i + 1); + } + if (i - 1 >= 0 && dist[i - 1] == -1) { + dist[i - 1] = d + 1; + q.add(i - 1); + } + int v = nums[i]; + if (v <= maxVal && isPrime[v] && !primeProcessed[v]) { + for (int mult = v; mult <= maxVal; mult += v) { + ArrayList list = posOfValue[mult]; + if (list != null) { + for (int idx : list) { + if (dist[idx] == -1) { + dist[idx] = d + 1; + q.add(idx); + } + } + } + } + primeProcessed[v] = true; + } + } + return -1; + } + + private boolean[] sieve(int n) { + boolean[] prime = new boolean[n + 1]; + if (n >= 2) { + Arrays.fill(prime, true); + } + if (n >= 0) { + prime[0] = false; + } + if (n >= 1) { + prime[1] = false; + } + for (int i = 2; (long) i * i <= n; i++) { + if (prime[i]) { + for (int j = i * i; j <= n; j += i) { + prime[j] = false; + } + } + } + return prime; + } +} diff --git a/src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/readme.md b/src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/readme.md new file mode 100644 index 000000000..6a4a54f15 --- /dev/null +++ b/src/main/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/readme.md @@ -0,0 +1,59 @@ +3629\. Minimum Jumps to Reach End via Prime Teleportation + +Medium + +You are given an integer array `nums` of length `n`. + +You start at index 0, and your goal is to reach index `n - 1`. + +From any index `i`, you may perform one of the following operations: + +* **Adjacent Step**: Jump to index `i + 1` or `i - 1`, if the index is within bounds. +* **Prime Teleportation**: If `nums[i]` is a prime number `p`, you may instantly jump to any index `j != i` such that `nums[j] % p == 0`. + +Return the **minimum** number of jumps required to reach index `n - 1`. + +**Example 1:** + +**Input:** nums = [1,2,4,6] + +**Output:** 2 + +**Explanation:** + +One optimal sequence of jumps is: + +* Start at index `i = 0`. Take an adjacent step to index 1. +* At index `i = 1`, `nums[1] = 2` is a prime number. Therefore, we teleport to index `i = 3` as `nums[3] = 6` is divisible by 2. + +Thus, the answer is 2. + +**Example 2:** + +**Input:** nums = [2,3,4,7,9] + +**Output:** 2 + +**Explanation:** + +One optimal sequence of jumps is: + +* Start at index `i = 0`. Take an adjacent step to index `i = 1`. +* At index `i = 1`, `nums[1] = 3` is a prime number. Therefore, we teleport to index `i = 4` since `nums[4] = 9` is divisible by 3. + +Thus, the answer is 2. + +**Example 3:** + +**Input:** nums = [4,6,5,8] + +**Output:** 3 + +**Explanation:** + +* Since no teleportation is possible, we move through `0 → 1 → 2 → 3`. Thus, the answer is 3. + +**Constraints:** + +* 1 <= n == nums.length <= 105 +* 1 <= nums[i] <= 106 \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java b/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java new file mode 100644 index 000000000..58b174fd0 --- /dev/null +++ b/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java @@ -0,0 +1,41 @@ +package g3601_3700.s3630_partition_array_for_maximum_xor_and_and; + +// #Hard #Weekly_Contest_460 #2025_07_27_Time_77_ms_(100.00%)_Space_51.20_MB_(30.86%) + +public class Solution { + public long maximizeXorAndXor(int[] nums) { + int n = nums.length; + int full = 1 << n; + int[] xorMask = new int[full]; + int[] andMask = new int[full]; + int[] orMask = new int[full]; + for (int mask = 1; mask < full; mask++) { + int lb = mask & -mask; + int i = Integer.numberOfTrailingZeros(lb); + int prev = mask ^ lb; + xorMask[mask] = xorMask[prev] ^ nums[i]; + andMask[mask] = prev == 0 ? nums[i] : andMask[prev] & nums[i]; + orMask[mask] = orMask[prev] | nums[i]; + } + long best = 0; + int all = full - 1; + for (int b = 0; b < full; b++) { + long andB = andMask[b]; + int rest = all ^ b; + if (andB + 2L * orMask[rest] <= best) { + continue; + } + for (int a = rest; ; a = (a - 1) & rest) { + int c = rest ^ a; + long sum = xorMask[a] + andB + xorMask[c]; + if (sum > best) { + best = sum; + } + if (a == 0) { + break; + } + } + } + return best; + } +} diff --git a/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/readme.md b/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/readme.md new file mode 100644 index 000000000..4bcfa6e79 --- /dev/null +++ b/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/readme.md @@ -0,0 +1,71 @@ +3630\. Partition Array for Maximum XOR and AND + +Hard + +You are given an integer array `nums`. + +Partition the array into **three** (possibly empty) **subsequences** `A`, `B`, and `C` such that every element of `nums` belongs to **exactly** one subsequence. + +Your goal is to **maximize** the value of: `XOR(A) + AND(B) + XOR(C)` + +where: + +* `XOR(arr)` denotes the bitwise XOR of all elements in `arr`. If `arr` is empty, its value is defined as 0. +* `AND(arr)` denotes the bitwise AND of all elements in `arr`. If `arr` is empty, its value is defined as 0. + +Return the **maximum** value achievable. + +**Note:** If multiple partitions result in the same **maximum** sum, you can consider any one of them. + +**Example 1:** + +**Input:** nums = [2,3] + +**Output:** 5 + +**Explanation:** + +One optimal partition is: + +* `A = [3], XOR(A) = 3` +* `B = [2], AND(B) = 2` +* `C = [], XOR(C) = 0` + +The maximum value of: `XOR(A) + AND(B) + XOR(C) = 3 + 2 + 0 = 5`. Thus, the answer is 5. + +**Example 2:** + +**Input:** nums = [1,3,2] + +**Output:** 6 + +**Explanation:** + +One optimal partition is: + +* `A = [1], XOR(A) = 1` +* `B = [2], AND(B) = 2` +* `C = [3], XOR(C) = 3` + +The maximum value of: `XOR(A) + AND(B) + XOR(C) = 1 + 2 + 3 = 6`. Thus, the answer is 6. + +**Example 3:** + +**Input:** nums = [2,3,6,7] + +**Output:** 15 + +**Explanation:** + +One optimal partition is: + +* `A = [7], XOR(A) = 7` +* `B = [2,3], AND(B) = 2` +* `C = [6], XOR(C) = 6` + +The maximum value of: `XOR(A) + AND(B) + XOR(C) = 7 + 2 + 6 = 15`. Thus, the answer is 15. + +**Constraints:** + +* `1 <= nums.length <= 19` +* 1 <= nums[i] <= 109 \ No newline at end of file diff --git a/src/test/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/SolutionTest.java b/src/test/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/SolutionTest.java new file mode 100644 index 000000000..70a038a0b --- /dev/null +++ b/src/test/java/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/SolutionTest.java @@ -0,0 +1,18 @@ +package g3601_3700.s3627_maximum_median_sum_of_subsequences_of_size_3; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maximumMedianSum() { + assertThat(new Solution().maximumMedianSum(new int[] {2, 1, 3, 2, 1, 3}), equalTo(5L)); + } + + @Test + void maximumMedianSum2() { + assertThat(new Solution().maximumMedianSum(new int[] {1, 1, 10, 10, 10, 10}), equalTo(20L)); + } +} diff --git a/src/test/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/SolutionTest.java b/src/test/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/SolutionTest.java new file mode 100644 index 000000000..655082298 --- /dev/null +++ b/src/test/java/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/SolutionTest.java @@ -0,0 +1,23 @@ +package g3601_3700.s3628_maximum_number_of_subsequences_after_one_inserting; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void numOfSubsequences() { + assertThat(new Solution().numOfSubsequences("LMCT"), equalTo(2L)); + } + + @Test + void numOfSubsequences2() { + assertThat(new Solution().numOfSubsequences("LCCT"), equalTo(4L)); + } + + @Test + void numOfSubsequences3() { + assertThat(new Solution().numOfSubsequences("L"), equalTo(0L)); + } +} diff --git a/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java b/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java new file mode 100644 index 000000000..d8af7687c --- /dev/null +++ b/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java @@ -0,0 +1,23 @@ +package g3601_3700.s3629_minimum_jumps_to_reach_end_via_prime_teleportation; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minJumps() { + assertThat(new Solution().minJumps(new int[] {1, 2, 4, 6}), equalTo(2)); + } + + @Test + void minJumps2() { + assertThat(new Solution().minJumps(new int[] {2, 3, 4, 7, 9}), equalTo(2)); + } + + @Test + void minJumps3() { + assertThat(new Solution().minJumps(new int[] {4, 6, 5, 8}), equalTo(3)); + } +} diff --git a/src/test/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/SolutionTest.java b/src/test/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/SolutionTest.java new file mode 100644 index 000000000..dffe6988d --- /dev/null +++ b/src/test/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/SolutionTest.java @@ -0,0 +1,23 @@ +package g3601_3700.s3630_partition_array_for_maximum_xor_and_and; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maximizeXorAndXor() { + assertThat(new Solution().maximizeXorAndXor(new int[] {2, 3}), equalTo(5L)); + } + + @Test + void maximizeXorAndXor2() { + assertThat(new Solution().maximizeXorAndXor(new int[] {1, 3, 2}), equalTo(6L)); + } + + @Test + void maximizeXorAndXor3() { + assertThat(new Solution().maximizeXorAndXor(new int[] {2, 3, 6, 7}), equalTo(15L)); + } +} From b55c8149cd82a5ade478bac400b4d6b5248a21c0 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 27 Jul 2025 16:02:11 +0300 Subject: [PATCH 2/3] Added tests --- .../SolutionTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java b/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java index d8af7687c..051fe92e2 100644 --- a/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java +++ b/src/test/java/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/SolutionTest.java @@ -20,4 +20,22 @@ void minJumps2() { void minJumps3() { assertThat(new Solution().minJumps(new int[] {4, 6, 5, 8}), equalTo(3)); } + + @Test + void minJumps4() { + assertThat( + new Solution() + .minJumps( + new int[] { + 893, 786, 607, 137, 69, 381, 790, 233, 15, 42, 7, 764, 890, 269, + 84, 262, 870, 514, 514, 650, 269, 485, 760, 181, 489, 107, 585, + 428, 862, 563 + }), + equalTo(21)); + } + + @Test + void minJumps5() { + assertThat(new Solution().minJumps(new int[] {4}), equalTo(0)); + } } From 4e477b36db45cd88d447255222a78b1b9450e325 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Thu, 31 Jul 2025 11:39:46 +0300 Subject: [PATCH 3/3] Updated tag --- .../Solution.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java b/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java index 58b174fd0..029518085 100644 --- a/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java +++ b/src/main/java/g3601_3700/s3630_partition_array_for_maximum_xor_and_and/Solution.java @@ -1,6 +1,7 @@ package g3601_3700.s3630_partition_array_for_maximum_xor_and_and; -// #Hard #Weekly_Contest_460 #2025_07_27_Time_77_ms_(100.00%)_Space_51.20_MB_(30.86%) +// #Hard #Array #Math #Greedy #Enumeration #Weekly_Contest_460 +// #2025_07_31_Time_82_ms_(96.35%)_Space_50.76_MB_(39.58%) public class Solution { public long maximizeXorAndXor(int[] nums) {