Skip to content

[BUG] - Time limit too low for Python - 3599. Partition Array to Minimize XOR #30243

@hexawhale

Description

@hexawhale

LeetCode Username

killer-whale

Problem Number, Title, and Link

  1. 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 r

Expected 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions