Skip to content

Commit 8e0c7a5

Browse files
authored
Added tests 49-74
1 parent 45a632b commit 8e0c7a5

File tree

19 files changed

+172
-1
lines changed

19 files changed

+172
-1
lines changed

src/main/python/g0001_0100/s0049_group_anagrams/Solution0049.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# #2025_07_24_Time_11_ms_(82.75%)_Space_20.85_MB_(56.49%)
55

66
from collections import defaultdict
7+
from typing import List
78

89
class Solution:
910
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
from Solution0049 import Solution
3+
4+
def sort_nested(lists):
5+
return sorted([sorted(x) for x in lists])
6+
7+
class SolutionTest(unittest.TestCase):
8+
def test_groupAnagrams(self):
9+
res = Solution().groupAnagrams(["eat","tea","tan","ate","nat","bat"])
10+
expected = [["bat"],["nat","tan"],["ate","eat","tea"]]
11+
self.assertEqual(sort_nested(res), sort_nested(expected))
12+
13+
def test_groupAnagrams2(self):
14+
res = Solution().groupAnagrams([""])
15+
expected = [[""]]
16+
self.assertEqual(sort_nested(res), sort_nested(expected))
17+
18+
def test_groupAnagrams3(self):
19+
res = Solution().groupAnagrams(["a"])
20+
expected = [["a"]]
21+
self.assertEqual(sort_nested(res), sort_nested(expected))

src/main/python/g0001_0100/s0051_n_queens/Solution0051.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# #Hard #Top_100_Liked_Questions #Array #Backtracking #Big_O_Time_O(N!)_Space_O(N)
22
# #2025_07_24_Time_6_ms_(98.12%)_Space_18.42_MB_(15.31%)
33

4+
from typing import List
5+
46
class Solution:
57
def solveNQueens(self, n: int) -> List[List[str]]:
68
pos = [False] * (n + 2 * n - 1 + 2 * n - 1)
@@ -26,7 +28,7 @@ def helper(self, n: int, row: int, pos: List[bool], pos2: List[int], ans: List[L
2628
pos[n + i + row] = False
2729
pos[index] = False
2830

29-
def construct(self, n: int, pos: list[int], ans: list[list[str]]):
31+
def construct(self, n: int, pos: List[int], ans: List[List[str]]):
3032
sol = []
3133
for r in range(n):
3234
queenRow = ['.'] * n
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
from Solution0051 import Solution
3+
4+
def sort_nested(lists):
5+
return sorted(lists)
6+
7+
class SolutionTest(unittest.TestCase):
8+
def test_solveNQueens(self):
9+
res = Solution().solveNQueens(4)
10+
expected = [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
11+
self.assertEqual(sort_nested(res), sort_nested(expected))
12+
13+
def test_solveNQueens2(self):
14+
res = Solution().solveNQueens(1)
15+
expected = [["Q"]]
16+
self.assertEqual(sort_nested(res), sort_nested(expected))

src/main/python/g0001_0100/s0053_maximum_subarray/Solution0053.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Udemy_Famous_Algorithm #Top_Interview_150_Kadane's_Algorithm #Big_O_Time_O(n)_Space_O(1)
44
# #2025_07_24_Time_50_ms_(77.23%)_Space_32.78_MB_(39.19%)
55

6+
from typing import List
7+
68
class Solution:
79
def maxSubArray(self, nums: List[int]) -> int:
810
maxi = float('-inf')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0053 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_maxSubArray(self):
6+
self.assertEqual(Solution().maxSubArray([-2,1,-3,4,-1,2,1,-5,4]), 6)
7+
8+
def test_maxSubArray2(self):
9+
self.assertEqual(Solution().maxSubArray([1]), 1)
10+
11+
def test_maxSubArray3(self):
12+
self.assertEqual(Solution().maxSubArray([5,4,-1,7,8]), 23)

src/main/python/g0001_0100/s0055_jump_game/Solution0055.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
44
# #2025_07_24_Time_12_ms_(85.38%)_Space_18.61_MB_(41.98%)
55

6+
from typing import List
7+
68
class Solution:
79
def canJump(self, nums: List[int]) -> bool:
810
goal = len(nums) - 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0055 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_canJump(self):
6+
self.assertTrue(Solution().canJump([2,3,1,1,4]))
7+
8+
def test_canJump2(self):
9+
self.assertFalse(Solution().canJump([3,2,1,0,4]))
10+
11+
def test_canJump3(self):
12+
self.assertTrue(Solution().canJump([1]))

src/main/python/g0001_0100/s0056_merge_intervals/Solution0056.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Top_Interview_150_Intervals #Big_O_Time_O(n_log_n)_Space_O(n)
44
# #2025_07_24_Time_7_ms_(72.98%)_Space_20.89_MB_(89.16%)
55

6+
from typing import List
7+
68
class Solution:
79
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
810
intervals.sort(key=lambda x: x[0])
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
from Solution0056 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_merge(self):
6+
res = Solution().merge([[1,3],[2,6],[8,10],[15,18]])
7+
expected = [[1,6],[8,10],[15,18]]
8+
self.assertEqual(res, expected)
9+
10+
def test_merge2(self):
11+
res = Solution().merge([[1,4],[4,5]])
12+
expected = [[1,5]]
13+
self.assertEqual(res, expected)
14+
15+
def test_merge3(self):
16+
res = Solution().merge([[1,4],[0,4]])
17+
expected = [[0,4]]
18+
self.assertEqual(res, expected)

0 commit comments

Comments
 (0)