shing | Maps | Time Complexity | Collisions | Division Rule of Hashing-> for each loop we can use this also print using key set value Hashing: Let’s first try to understand the importance of hashing using an example: Given an array of integers: [1, 2, 1, 3, 2] and we are given some queries: [1, 3, 4, 2, 10]. For each query, we need to find out how many times the number appears in the array. For example, if the query is 1 our answer would be 2, and if the query is 4 the answer will be 0. Similarly, the following will be the answers to the given queries: Brute Force approach: As we have learned the ‘for loop’, the first approach that should come to our mind is to use it to solve this problem. For each query, we will iterate over the array using a loop. We will count the number of times the query number appears in that array i.e. increment the counter variable if the array element at that index equals the query number. In terms of function, it will look like the...
Q Approach- note-> 1) we can use the outer loop for take the lenngth of indices 2) we use the [i][0] in first loop to increment the cols by making constant row 3)[i][1] use to change the row by making constant cols 2nd way-> create two boolean array for row and col with row col size row[indices[i][0]] ^=true; same with col using [1] then count r and c values ; use following formulae; Q sol-> first run loop till length after that take the sum from primary and secondary side if length is odd then we have to - the middle element because it comes twice Q approch 1->while(0<nums[i]) - count++ nums[i]/=10; approch2-> Math.log10(nums[i])+1; it produce odd value for even and even for odd so we have to add 1 to it; approch3-> we set the limit like >9 && < =99 || like wise; Q ans-> Use the new 2D ans for [col][row] because if matrix size is 2*4 the after transpose it becomes 4*2 thats why we g...
Comments
Post a Comment