From 30cf7c6170f23226bd3fe9173711e5e76c1cfadd Mon Sep 17 00:00:00 2001 From: Anirudh Venkateshwaran Date: Sat, 16 May 2026 11:55:53 -0700 Subject: [PATCH 1/2] Solved Find All Numbers Disappeared in an Array and Game of Life --- Problem1.cs | 30 ++++++++++++++++++ Problem2.cs | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 Problem1.cs create mode 100644 Problem2.cs diff --git a/Problem1.cs b/Problem1.cs new file mode 100644 index 00000000..629c562c --- /dev/null +++ b/Problem1.cs @@ -0,0 +1,30 @@ +// Time Complexity : O(n) where n is the total length of nums array +// Space Complexity : O(1) +// Did this code successfully run on Leetcode : Yes +// Any problem you faced while coding this : No + +public class Solution { + public IList FindDisappearedNumbers(int[] nums) { + List result = new(); + + for(int i = 0; i < nums.Length; i++) + { + int index = Math.Abs(nums[i]) - 1; + + if(nums[index] > 0) + { + nums[index] *= -1; + } + } + + for(int i = 0; i < nums.Length; i++) + { + if(nums[i] > 0) + { + result.Add(i+1); + } + } + + return result; + } +} \ No newline at end of file diff --git a/Problem2.cs b/Problem2.cs new file mode 100644 index 00000000..ef75f3cf --- /dev/null +++ b/Problem2.cs @@ -0,0 +1,88 @@ +// Time Complexity : O(m*n) where m & n are the dimensions of board +// Space Complexity : O(1) +// Did this code successfully run on Leetcode : Yes +// Any problem you faced while coding this : No +public class Solution { + private int rows; + private int columns; + private int[][] dirs; + public void GameOfLife(int[][] board) { + rows = board.Length; + columns = board[0].Length; + dirs = new int[][] + { + new int[] {0,1}, + new int[] {0,-1}, + new int[] {1,0}, + new int[] {-1,0}, + new int[] {-1,-1}, + new int[] {1,1}, + new int[] {-1,1}, + new int[] {1,-1}, + }; + + Helper(board); + + for(int i = 0; i < rows; i++) + { + for(int j = 0; j < columns; j++) + { + // 1 -> 0 : 2 + if(board[i][j] == 2) + { + board[i][j] = 0; + } + + // 0 -> 1 : 3 + else if(board[i][j] == 3) + { + board[i][j] = 1; + } + } + } + } + + public void Helper(int[][] board) + { + for(int i = 0; i < rows; i++) + { + for(int j = 0; j < columns; j++) + { + int neighbours = GetNeighbours(board, i , j); + + if(board[i][j] == 1) + { + if(neighbours < 2 || neighbours > 3) + { + board[i][j] = 2; + } + } + + else if(board[i][j] == 0) + { + if(neighbours == 3) + { + board[i][j] = 3; + } + } + } + } + } + + public int GetNeighbours(int[][] board, int i, int j) + { + int neighbours = 0; + + foreach(int[] dir in dirs) + { + int nr = i + dir[0]; + int nc = j + dir[1]; + if(nr>=0 && nr=0 && nc Date: Sat, 16 May 2026 13:29:14 -0700 Subject: [PATCH 2/2] Solved Find All Numbers Disappeared in an Array, Min and Max in Array and Game of Life --- Problem2.cs | 109 +++++++++++++++++----------------------------------- Problem3.cs | 88 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 74 deletions(-) create mode 100644 Problem3.cs diff --git a/Problem2.cs b/Problem2.cs index ef75f3cf..1d4c2744 100644 --- a/Problem2.cs +++ b/Problem2.cs @@ -1,88 +1,49 @@ -// Time Complexity : O(m*n) where m & n are the dimensions of board +// Time Complexity : O(n) where n is the length of arr // Space Complexity : O(1) // Did this code successfully run on Leetcode : Yes // Any problem you faced while coding this : No + public class Solution { - private int rows; - private int columns; - private int[][] dirs; - public void GameOfLife(int[][] board) { - rows = board.Length; - columns = board[0].Length; - dirs = new int[][] + public List getMinMax(int[] arr) { + // code here + List result = new(); + int min = 0, max = 0; + int i; + + if(arr.Length % 2 != 0) { - new int[] {0,1}, - new int[] {0,-1}, - new int[] {1,0}, - new int[] {-1,0}, - new int[] {-1,-1}, - new int[] {1,1}, - new int[] {-1,1}, - new int[] {1,-1}, - }; - - Helper(board); - - for(int i = 0; i < rows; i++) + min = arr[0]; + max = arr[0]; + i=1; + } + + else { - for(int j = 0; j < columns; j++) - { - // 1 -> 0 : 2 - if(board[i][j] == 2) - { - board[i][j] = 0; - } - - // 0 -> 1 : 3 - else if(board[i][j] == 3) - { - board[i][j] = 1; - } - } + min = Math.Min(arr[0], arr[1]); + max = Math.Max(arr[0], arr[1]); + i=2; } - } - - public void Helper(int[][] board) - { - for(int i = 0; i < rows; i++) + + + while(i 3) - { - board[i][j] = 2; - } - } - - else if(board[i][j] == 0) - { - if(neighbours == 3) - { - board[i][j] = 3; - } - } + min = Math.Min(arr[i], min); + max = Math.Max(arr[i+1], max); } - } - } - - public int GetNeighbours(int[][] board, int i, int j) - { - int neighbours = 0; - - foreach(int[] dir in dirs) - { - int nr = i + dir[0]; - int nc = j + dir[1]; - if(nr>=0 && nr=0 && nc 0 : 2 + if(board[i][j] == 2) + { + board[i][j] = 0; + } + + // 0 -> 1 : 3 + else if(board[i][j] == 3) + { + board[i][j] = 1; + } + } + } + } + + public void Helper(int[][] board) + { + for(int i = 0; i < rows; i++) + { + for(int j = 0; j < columns; j++) + { + int neighbours = GetNeighbours(board, i , j); + + if(board[i][j] == 1) + { + if(neighbours < 2 || neighbours > 3) + { + board[i][j] = 2; + } + } + + else if(board[i][j] == 0) + { + if(neighbours == 3) + { + board[i][j] = 3; + } + } + } + } + } + + public int GetNeighbours(int[][] board, int i, int j) + { + int neighbours = 0; + + foreach(int[] dir in dirs) + { + int nr = i + dir[0]; + int nc = j + dir[1]; + if(nr>=0 && nr=0 && nc