From 79006f74ce8dfaf3aa8f78f317258d46ab80d9ad Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Wed, 5 Jan 2022 12:47:13 -0500 Subject: [PATCH 1/9] Create find_disappeared_numbers.py --- find_disappeared_numbers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 find_disappeared_numbers.py diff --git a/find_disappeared_numbers.py b/find_disappeared_numbers.py new file mode 100644 index 00000000..d1ff7f4c --- /dev/null +++ b/find_disappeared_numbers.py @@ -0,0 +1,16 @@ +# Time Complexity - O(n) +# Space Complexity - O(1) + +class Solution: + + def findDisappearedNumbers(self, nums: List[int]) -> List[int]: + for i in range(len(nums)): + index = abs(nums[i])-1 + if nums[index]>0: + nums[index] = -1*nums[index] + print(nums) + result = [] + for i in range(len(nums)): + if nums[i]>0: + result.append(i+1) + return result From b1b3b10d1ffeef4b932b34824fdde1af0fd0fcd9 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Wed, 5 Jan 2022 13:13:36 -0500 Subject: [PATCH 2/9] Create game_of_life.py --- game_of_life.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 game_of_life.py diff --git a/game_of_life.py b/game_of_life.py new file mode 100644 index 00000000..55374d02 --- /dev/null +++ b/game_of_life.py @@ -0,0 +1,36 @@ +# Time Complexity - O(mn) +# Space Complexity - O(1) + +class Solution: + + def gameOfLife(self, board: List[List[int]]) -> None: + if len(board)==0 and len(board[0])==0: + return -1 + for i in range(len(board)): + for j in range(len(board[0])): + # 1 -- 0 --> 2 + # 0 -- 1 -->3 + # rule 1 & 3 + if board[i][j]==1 and (self.countneighbours(board,i,j)<2 or self.countneighbours(board,i,j)>3): + board[i][j]=2 + # rule 2 + if board[i][j]==0 and self.countneighbours(board,i,j)==3: + board[i][j]=3 + + for i in range(len(board)): + for j in range(len(board[0])): + if board[i][j] == 2: + board[i][j]=0 + if board[i][j] == 3: + board[i][j]=1 + return board + + def countneighbours(self,board,i,j): + dirs = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]] + result = 0 + for val in dirs: + r = i + val[0] + c = j + val[1] + if r>=0 and r=0 and c Date: Wed, 5 Jan 2022 13:26:58 -0500 Subject: [PATCH 3/9] Create max_min_lesser_comparisons.py --- max_min_lesser_comparisons.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 max_min_lesser_comparisons.py diff --git a/max_min_lesser_comparisons.py b/max_min_lesser_comparisons.py new file mode 100644 index 00000000..955f46c1 --- /dev/null +++ b/max_min_lesser_comparisons.py @@ -0,0 +1,16 @@ +# Number of comparisons - 3n/2 + +def max_min_less_comparisons(arr): + maxi = arr[0] + mini = arr[0] + for i in range(1,len(arr)-1): + if arr[i]>arr[i+1]: + maxi = max(maxi,arr[i]) + mini = min(mini,arr[i+1]) + else: + maxi = max(maxi,arr[i+1]) + mini = min(mini,arr[i]) + return maxi,mini + +arr = [10,8,4,7,2,6,1,5] +print(max_min_less_comparisons(arr)) From 32fc03d5afbee1f916cd9cd28c96f51acd1a94c3 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Sat, 25 Apr 2026 21:15:09 -0700 Subject: [PATCH 4/9] Delete find_disappeared_numbers.py --- find_disappeared_numbers.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 find_disappeared_numbers.py diff --git a/find_disappeared_numbers.py b/find_disappeared_numbers.py deleted file mode 100644 index d1ff7f4c..00000000 --- a/find_disappeared_numbers.py +++ /dev/null @@ -1,16 +0,0 @@ -# Time Complexity - O(n) -# Space Complexity - O(1) - -class Solution: - - def findDisappearedNumbers(self, nums: List[int]) -> List[int]: - for i in range(len(nums)): - index = abs(nums[i])-1 - if nums[index]>0: - nums[index] = -1*nums[index] - print(nums) - result = [] - for i in range(len(nums)): - if nums[i]>0: - result.append(i+1) - return result From 2665df3f24cf67bc67a4cd15658ae64276929870 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Sat, 25 Apr 2026 21:15:19 -0700 Subject: [PATCH 5/9] Delete game_of_life.py --- game_of_life.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 game_of_life.py diff --git a/game_of_life.py b/game_of_life.py deleted file mode 100644 index 55374d02..00000000 --- a/game_of_life.py +++ /dev/null @@ -1,36 +0,0 @@ -# Time Complexity - O(mn) -# Space Complexity - O(1) - -class Solution: - - def gameOfLife(self, board: List[List[int]]) -> None: - if len(board)==0 and len(board[0])==0: - return -1 - for i in range(len(board)): - for j in range(len(board[0])): - # 1 -- 0 --> 2 - # 0 -- 1 -->3 - # rule 1 & 3 - if board[i][j]==1 and (self.countneighbours(board,i,j)<2 or self.countneighbours(board,i,j)>3): - board[i][j]=2 - # rule 2 - if board[i][j]==0 and self.countneighbours(board,i,j)==3: - board[i][j]=3 - - for i in range(len(board)): - for j in range(len(board[0])): - if board[i][j] == 2: - board[i][j]=0 - if board[i][j] == 3: - board[i][j]=1 - return board - - def countneighbours(self,board,i,j): - dirs = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]] - result = 0 - for val in dirs: - r = i + val[0] - c = j + val[1] - if r>=0 and r=0 and c Date: Sat, 25 Apr 2026 21:15:28 -0700 Subject: [PATCH 6/9] Delete max_min_lesser_comparisons.py --- max_min_lesser_comparisons.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 max_min_lesser_comparisons.py diff --git a/max_min_lesser_comparisons.py b/max_min_lesser_comparisons.py deleted file mode 100644 index 955f46c1..00000000 --- a/max_min_lesser_comparisons.py +++ /dev/null @@ -1,16 +0,0 @@ -# Number of comparisons - 3n/2 - -def max_min_less_comparisons(arr): - maxi = arr[0] - mini = arr[0] - for i in range(1,len(arr)-1): - if arr[i]>arr[i+1]: - maxi = max(maxi,arr[i]) - mini = min(mini,arr[i+1]) - else: - maxi = max(maxi,arr[i+1]) - mini = min(mini,arr[i]) - return maxi,mini - -arr = [10,8,4,7,2,6,1,5] -print(max_min_less_comparisons(arr)) From 0748e99b857a59fc757447ca0ba6c3d9360f76df Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Sat, 25 Apr 2026 21:51:59 -0700 Subject: [PATCH 7/9] Create Find Disappeared Number.py --- Find Disappeared Number.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Find Disappeared Number.py diff --git a/Find Disappeared Number.py b/Find Disappeared Number.py new file mode 100644 index 00000000..b5cf1247 --- /dev/null +++ b/Find Disappeared Number.py @@ -0,0 +1,18 @@ +# Time Complexity --> O(n) +# Space Complxity --> O(1) +class Solution: + def findDisappearedNumbers(self, nums: List[int]) -> List[int]: + n = len(nums) + re = [] + + for i in range(n): + index = abs(nums[i])-1 + if nums[index]>0: + nums[index] = -1*nums[index] + + for i in range(n): + if nums[i]>0: + re.append(i+1) + nums[i] = abs(nums[i]) + return re + From 426de6af9bcbe2bc0a4b23041c2fd3ada5ce44d2 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Sat, 25 Apr 2026 22:15:56 -0700 Subject: [PATCH 8/9] Create GameOfLife.py --- GameOfLife.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 GameOfLife.py diff --git a/GameOfLife.py b/GameOfLife.py new file mode 100644 index 00000000..22811cb2 --- /dev/null +++ b/GameOfLife.py @@ -0,0 +1,44 @@ +# Time Complexity --> O(m*n) +# Space Complexity --> O(1) +class Solution: + def gameOfLife(self, board: List[List[int]]) -> None: + """ + Do not return anything, modify board in-place instead. + """ + # 1 --> 0 then 2 + # 0 --> 1 then 3 + m = len(board) + n = len(board[0]) + + def helper(r, c): + dim = [[0,1],[1,0],[-1,0],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]] + + re = 0 + for i in dim: + row = r+i[0] + col = c+i[1] + if 0<= row 3: + board[i][j]=2 + else: + pass + + for i in range(m): + for j in range(n): + if board[i][j]==2: + board[i][j]=0 + elif board[i][j]==3: + board[i][j]=1 + + + From 2cd37bf9feeab780c71f45c3fd2dd2045a81ac80 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Sat, 25 Apr 2026 22:30:45 -0700 Subject: [PATCH 9/9] Create Problem2.py --- Problem2.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Problem2.py diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 00000000..3e984d25 --- /dev/null +++ b/Problem2.py @@ -0,0 +1,26 @@ +# Time Comkplexity --> O(n) +# Space Complexity --> O(1) +# Total Comparisons --> 1.5*n. We are comparing a pair of numbers at a time and then comparing the minimum of them with existing min value and maximum of them with existing max value +def findMinAndMax(self, nums): + n = len(nums) + i = 0 + + ## Different initializations depending on whether the length of array is even or odd + if n % 2 == 0: + min_val = min(nums[0], nums[1]) + max_val = max(nums[0], nums[1]) + i = 2 + else: + min_val = max_val = nums[0] + i = 1 + + while i < n - 1: + if nums[i] < nums[i + 1]: + min_val = min(min_val, nums[i]) + max_val = max(max_val, nums[i + 1]) + else: + min_val = min(min_val, nums[i + 1]) + max_val = max(max_val, nums[i]) + i += 2 + + return [min_val, max_val]