We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c3d114 commit 7bc97d8Copy full SHA for 7bc97d8
src/hackerrank/interview_preparation_kit/miscellaneous/maximum_xor.py
@@ -3,12 +3,18 @@
3
# pylint: enable=line-too-long
4
5
def maxXor(arr: list[int], queries: list[int]) -> list[int]:
6
+ max_dict: dict[int, int] = {}
7
result = []
8
9
for j in queries:
- maximum = 0
10
- for x in arr:
11
- maximum = max(maximum, j ^ x)
12
- result.append(maximum)
+
+ if j in max_dict:
+ result.append(max_dict[j])
13
+ else:
14
+ maximum: int = 0
15
+ for x in arr:
16
+ maximum = max(maximum, j ^ x)
17
+ max_dict[j] = maximum
18
+ result.append(maximum)
19
20
return result
0 commit comments