From 2181dcb85a6bbd1de5ec2c7b017b62e023ea814b Mon Sep 17 00:00:00 2001 From: Sreeja-99 <75175169+Sreeja-99@users.noreply.github.com> Date: Wed, 7 Jan 2026 23:18:32 -0600 Subject: [PATCH 1/2] Add Game of Life implementation in Leetcode_289.java Implement the Game of Life algorithm to update the board based on the rules of the game. The solution uses temporary values to retain state during the update process. --- Leetcode_289.java | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Leetcode_289.java diff --git a/Leetcode_289.java b/Leetcode_289.java new file mode 100644 index 00000000..bdfa7864 --- /dev/null +++ b/Leetcode_289.java @@ -0,0 +1,64 @@ +//In this problem, we need to update the given board. If we do so, we might loose old value. To retain it, we will update the values other than 0 or 1[as 0 and 1 are given in input] +//TC: 8*O(m*n); SC:O(1) + + +class Solution { + public void gameOfLife(int[][] board) { + + int n=board.length; + int m=board[0].length; + + for(int i=0;i3 || active<2)){ + board[i][j]=2; + } + + if(board[i][j] == 0 && (active==3)){ + board[i][j]=3; + } + + + } + } + + for(int i=0;i=0 && r=0 && c Date: Wed, 7 Jan 2026 23:19:43 -0600 Subject: [PATCH 2/2] Add solution for finding disappeared numbers in array Implemented two methods to find missing numbers in an array. The first method uses a Set for tracking, while the second mutates the original array for constant space usage. --- Leetcode_448.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Leetcode_448.java diff --git a/Leetcode_448.java b/Leetcode_448.java new file mode 100644 index 00000000..5174ec19 --- /dev/null +++ b/Leetcode_448.java @@ -0,0 +1,58 @@ +//way1 +//Store them in Set. Iterate and identify which element is missed. +//TC: O(2n); SC: O(n) +class Solution { + public List findDisappearedNumbers(int[] nums) { + Set set=new HashSet<>(); + + //first iteration + for(int i:nums){ + set.add(i); + } + + int n=nums.length; + + List ans=new ArrayList<>(); + //second iteration + for(int i=1;i<=n;i++){ + if(!(set.contains(i))){ + ans.add(i); + } + } + + return ans; + + } +} + +//way2 +//Mutate the original array by going to the exact position of element present at index +//nums[0]=5 -- go to index 4[because 5th element's position is at 4] and update it to negative value at 4th index. It means element 5 is present +//After updating the entire array with abive concept, travel array again to identify missing elements +//TC: O(2n); SC: constant +class Solution { + public List findDisappearedNumbers(int[] nums) { + int n=nums.length; + for(int i=0;i0){ + nums[idx]*=-1; + } + + } + + List ans=new ArrayList<>(); + + for(int i=0;i0){ + ans.add(i+1); + }else{ + nums[i]*=-1; + } + } + + return ans; + + } +}