I'm talking about "62. Unique Paths" problem and python3 here, but, I believe, this is true for every problem and every language.
My point is: the Accepted Solutions Runtime Distribution (and Memory too) is not correct because test cases set differs with time (generally, becomes bigger and more complex) and so, slow solutions from the past times are accounted as fast ones, because they were run in the past, when they were accepted with a smaller/less complex test cases set.
An example. My python3 math one-liner for the "62. Unique Paths" (return factorial(m+n-2) // factorial(m-1) // factorial(n-1)) results in "62 / 62 test cases passed. Runtime: 32 ms. Your runtime beats 57.17 % of python3 submissions" now [1].
I check and re-submit 3 faster solutions, at 16, 20 and 28 ms (see the code below). And what I get for them now is:
16 ms: 62 / 62 test cases passed. Runtime: 52 ms. Your runtime beats 7.68 % of python3 submissions. [2]
20 ms: 62 / 62 test cases passed. Runtime: 52 ms. Your runtime beats 7.68 % of python3 submissions. [3]
28 ms: 62 / 62 test cases passed. Runtime: 48 ms. Your runtime beats 10.18 % of python3 submissions. [4]
These two are DP solutions, it is impossible they beat 3 factorial calls (which implementation is coded in C) and 2 int-divisions. I suppose, for the Accepted Solutions Runtime Distribution to be fair all submitted solutions should be re-run and the distribution recalculated every time a test cases set is altered. Some of the solutions can even become invalid and should be dropped from the distribution.
On one hand I understand, a test set re-run is a costly operation. On the other hand, I bevlieve, a test set is not changing often.
[1] https://leetcode.com/submissions/detail/359987470/
[2] https://leetcode.com/submissions/detail/359983403/
[3] https://leetcode.com/submissions/detail/359994907/
[4] https://leetcode.com/submissions/detail/359983926/
# sample 16 ms submission
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
# method 2: DP
R = n
C = m
memo = [ [0]*(C+1) for _ in range(R+1)]
memo[1][1] = 1
for r in range(1,R+1):
for c in range(1, C+1):
if (r,c) == (1,1):
continue
memo[r][c] = memo[r-1][c] + memo[r][c-1]
return memo[R][C]# sample 28 ms submission
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [0] * n
dp[0] = 1
for i in range(m):
for j in range(1, n):
dp[j] = dp[j - 1] + dp[j]
return dp[n-1]