diff --git a/Daily Questions/2965 - Find Missing and Repeated Values - Easy/Explanation.md b/Daily Questions/2965 - Find Missing and Repeated Values - Easy/Explanation.md new file mode 100644 index 0000000..14d6c64 --- /dev/null +++ b/Daily Questions/2965 - Find Missing and Repeated Values - Easy/Explanation.md @@ -0,0 +1,19 @@ +This Java code defines a method findMissingAndRepeatedValues that takes a 2D integer array grid as input and returns an array of two integers: one representing a missing value and the other representing a repeated value in the grid. + +A HashMap is used to keep track of the frequency of each element in the grid. + +An array res of size 2 is initialized to store the result. + +Iterate through each element of the grid. + +If the element already exists in the map, increment its count. + +If the element is not in the map, add it with a count of 1. + +Iterate through all possible values from 1 to grid.length * grid.length. + +If a value is not found in the map, it is the missing value and stored in res[1]. + +If a value appears twice in the map, it is the repeated value and stored in res[0]. + +This method efficiently finds one missing value and one repeated value in the provided grid by leveraging a HashMap to keep track of element frequencies and iterating through all possible values. \ No newline at end of file diff --git a/Daily Questions/2965 - Find Missing and Repeated Values - Easy/Solution.java b/Daily Questions/2965 - Find Missing and Repeated Values - Easy/Solution.java new file mode 100644 index 0000000..00c97ad --- /dev/null +++ b/Daily Questions/2965 - Find Missing and Repeated Values - Easy/Solution.java @@ -0,0 +1,27 @@ +class Solution { + public int[] findMissingAndRepeatedValues(int[][] grid) { + Map map=new HashMap<>(); + int[] res=new int[2]; + for(int i=0;i