Skip to content

Commit 13f539a

Browse files
committed
Oct 28
1 parent 54ef9fa commit 13f539a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def longestSquareStreak(self, nums: List[int]) -> int:
6+
nums = list(set(nums))
7+
nums.sort(reverse=True)
8+
max_num = nums[0]
9+
dp = [0] * (max_num+1)
10+
for num in nums:
11+
dp[num] = 1
12+
if num*num <= max_num:
13+
dp[num] += dp[num*num]
14+
return res if (res := max(dp)) >= 2 else -1
15+
16+
17+
def main():
18+
nums = [4, 3, 6, 16, 8, 2]
19+
assert Solution().longestSquareStreak(nums) == 3
20+
21+
nums = [2, 3, 5, 6, 7]
22+
assert Solution().longestSquareStreak(nums) == -1
23+
24+
25+
if __name__ == '__main__':
26+
main()

2024-10-October-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
| October 25 | [1233. Remove Sub-Folders from the Filesystem](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem/) | Medium | Solved |
3131
| October 26 | [2458. Height of Binary Tree After Subtree Removal Queries](https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/) | Hard | Solved |
3232
| October 27 | [1277. Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones/) | Medium | Solved |
33-
| October 28 | []() | | |
33+
| October 28 | [2501. Longest Square Streak in an Array](https://leetcode.com/problems/longest-square-streak-in-an-array/) | Medium | Unsolved |
3434
| October 29 | []() | | |
3535
| October 30 | []() | | |
3636
| October 31 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 2 | 2 | 0 |
43-
| Medium | 22 | 13 | 9 |
43+
| Medium | 23 | 13 | 10 |
4444
| Hard | 3 | 2 | 1 |

0 commit comments

Comments
 (0)