Skip to content

Commit 1f4ac60

Browse files
authored
2025-03-06 v. 8.8.5: added "1829. Maximum XOR for Each Query"
2 parents bf8ef0e + a3cf0fe commit 1f4ac60

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
718718
| 1797. Design Authentication Manager | [Link](https://leetcode.com/problems/design-authentication-manager/) | [Link](./lib/medium/1797_design_authentication_manager.rb) | [Link](./test/medium/test_1797_design_authentication_manager.rb) |
719719
| 1814. Count Nice Pairs in an Array | [Link](https://leetcode.com/problems/count-nice-pairs-in-an-array/) | [Link](./lib/medium/1814_count_nice_pairs_in_an_array.rb) | [Link](./test/medium/test_1814_count_nice_pairs_in_an_array.rb) |
720720
| 1823. Find the Winner of the Circular Game | [Link](https://leetcode.com/problems/find-the-winner-of-the-circular-game/) | [Link](./lib/medium/1823_find_the_winner_of_the_circular_game.rb) | [Link](./test/medium/test_1823_find_the_winner_of_the_circular_game.rb) |
721+
| 1829. Maximum XOR for Each Query | [Link](https://leetcode.com/problems/maximum-xor-for-each-query/) | [Link](./lib/medium/1829_maximum_xor_for_each_query.rb) | [Link](./test/medium/test_1829_maximum_xor_for_each_query.rb) |
721722
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
722723
| 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) |
723724
| 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) |

leetcode-ruby.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '8.8.4'
8+
s.version = '8.8.5'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/maximum-xor-for-each-query/
4+
# @param {Integer[]} nums
5+
# @param {Integer} maximum_bit
6+
# @return {Integer[]}
7+
def get_maximum_xor(nums, maximum_bit)
8+
result = ::Array.new(nums.size, 0)
9+
xor = (1 << maximum_bit) - 1
10+
11+
(0...nums.size).each do |i|
12+
xor ^= nums[i]
13+
result[nums.size - i - 1] = xor
14+
end
15+
16+
result
17+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/1829_maximum_xor_for_each_query'
5+
require 'minitest/autorun'
6+
7+
class MaximumXORForEachQueryTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
[0, 3, 2, 3],
11+
get_maximum_xor(
12+
[0, 1, 1, 3],
13+
2
14+
)
15+
)
16+
end
17+
18+
def test_default_two
19+
assert_equal(
20+
[5, 2, 6, 5],
21+
get_maximum_xor(
22+
[2, 3, 4, 7],
23+
3
24+
)
25+
)
26+
end
27+
28+
def test_default_three
29+
assert_equal(
30+
[4, 3, 6, 4, 6, 7],
31+
get_maximum_xor(
32+
[0, 1, 2, 2, 5, 7],
33+
3
34+
)
35+
)
36+
end
37+
end

0 commit comments

Comments
 (0)