-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Description
LeetCode Username
killer-whale
Problem Number, Title, and Link
- Partition Array to Minimize XOR https://leetcode.com/problems/partition-array-to-minimize-xor/description/
Bug Category
Problem constraints
Bug Description
It is possible to submit an O(N^2 * K) solution in Python and receive Time Limit Exceeded, even though the solution should be Accepted given the constraints, where N and K can be at most 250. The time limit is too strict.
Language Used for Code
Python/Python3
Code used for Submit/Run operation
class Solution:
def minXor(self, nums: List[int], k: int) -> int:
n = len(nums)
@cache
def best(i, k):
if i == n:
return 0 if k == 0 else inf
if k == 0:
return inf
res = inf
xor = 0
for j in range(i, n):
xor ^= nums[j]
res = min(res, max(xor, best(j + 1, k - 1)))
return res
r = best(0, k)
best.cache_clear()
return rExpected behavior
The above solution should be Accepted and the Weekly Contest 456 should be rejudged to correct the rankings for those who solved this problem with an acceptable time complexity.
Screenshots
No response
Additional context
No response