This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def repeatedNTimes(self, A: List[int]) -> int: | |
for i in range(len(A)): | |
if A.count(A[i]) == len(A)//2: | |
return A[i] | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: | |
if not matrix: | |
return False | |
rows = len(matrix) | |
cols = len(matrix[0]) | |
for i in range(0, rows-1, 1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def merge(self, intervals: List[List[int]]) -> List[List[int]]: | |
if not intervals: | |
return [] | |
n = len(intervals)-1 | |
intervals.sort() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Find and fix bugs in a function that sums all elements in an array." | |
Number of candies Mary can give to her brother. | |
She has an array of candies [3, 4, 5, 5, 7, 7] ans = 3 | |
She has to give 1/2 to her brother. and wants to eat as many unique candies as possible. What is the max number of unique candies she can eat? | |
``` | |
class Solution: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_number_of_islands(binaryMatrix): | |
if not binaryMatrix: | |
return 0 | |
islands = 0 | |
def dfs(grid, i, j): | |
if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[0]) or grid[i][j] == 0: | |
return True | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_array_quadruplet(arr, s): | |
if not arr or len(arr) < 4: | |
return [] | |
n = len(arr) | |
arr.sort() | |
for i in range(0, n-3): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cellCompete(states, days): | |
print("INIT STATES: " + str(len(states))) | |
for day in range(days): | |
nextGen = [] | |
print("DAY: " + str(day)) | |
print("NO STATES: " + str(len(states))) | |
for i in range(0, len(states)): | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverse(x int) int { | |
res := 0 | |
for x!= 0 { | |
res = res*10+x%10 | |
x=x/10 | |
if res != int(int32(res)){ | |
return 0 | |
} | |
} | |
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def moveZeroes(self, nums: List[int]) -> None: | |
""" | |
Do not return anything, modify nums in-place instead. | |
""" | |
count = nums.count(0) | |
nums[:] = list(filter(lambda a: a != 0, nums)) | |
for i in range(count, 0, -1): | |
nums.append(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def firstMissingPositive(self, nums: List[int]) -> int: | |
i = 1 | |
if i not in nums: | |
return i | |
for num in nums: | |
if i in nums: | |
i += 1 |