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..1d4c2744 --- /dev/null +++ b/Problem2.cs @@ -0,0 +1,49 @@ +// 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 { + public List getMinMax(int[] arr) { + // code here + List result = new(); + int min = 0, max = 0; + int i; + + if(arr.Length % 2 != 0) + { + min = arr[0]; + max = arr[0]; + i=1; + } + + else + { + min = Math.Min(arr[0], arr[1]); + max = Math.Max(arr[0], arr[1]); + i=2; + } + + + while(i 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