1707. Maximum XOR With an Element From Array Hard
1/**
2 * [1707] Maximum XOR With an Element From Array
3 *
4 * You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].
5 * The answer to the i^th query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi. If all elements in nums are larger than mi, then the answer is -1.
6 * Return an integer array answer where answer.length == queries.length and answer[i] is the answer to the i^th query.
7 *
8 * Example 1:
9 *
10 * Input: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]
11 * Output: [3,3,7]
12 * Explanation:
13 * 1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.
14 * 2) 1 XOR 2 = 3.
15 * 3) 5 XOR 2 = 7.
16 *
17 * Example 2:
18 *
19 * Input: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]
20 * Output: [15,-1,5]
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= nums.length, queries.length <= 10^5
26 * queries[i].length == 2
27 * 0 <= nums[j], xi, mi <= 10^9
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/maximum-xor-with-an-element-from-array/
33// discuss: https://leetcode.com/problems/maximum-xor-with-an-element-from-array/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn maximize_xor(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i32> {
39 vec![]
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_1707() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.