Wednesday, 1 Dec 2021
Category: Hash

#include using namespace std;int possibleCombinations(int arr1[], int arr2[], int N){        unordered_map mp;                    for (int i = 0; i < N; i++) {        mp[arr1[i]] = arr2[i];    }            int count = 1;            vector visited(N + 1, 0);    for (int i = 1; i

Given an array arr[] of size N, the task is to find the value of an integer K such that its repeated subtraction from array elements will make all array elements in minimum operations.Example:Input: arr[] = {5, 3, 3, 7}Output: 2Explanation: Minimum 2 operations must be performed:1st operation: subtract 2 from elements at indices {0, […]

Hashing is a great practical tool, with an interesting and subtle theory too. In addition to its use as a dictionary data structure, hashing also comes up in many different areas, including cryptography and complexity theory. This article discusses an important notion: Universal Hashing (also known as universal hash function families).Universal Hashing refers to selecting a […]

Given two arrays A[] and B[] both consisting of N integers, the task is to find the maximum length of subarray [i, j] such that the sum of A[i… j] is equal to B[i… j].Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at […]

Given an array arr[] of N integers, the task is to find the maximum count of K, i.e, consecutive integers from 0 to K, that is present in the set S, where S contains all the possible subset-sum values of the array arr[].Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA […]

Given a string S of size N, the task is to find the maximum sum of values assigned to all the alphabets of the string S. The value assigned to all the characters are over the range [1, 26], and the values assigned to the same lowercase and uppercase character is the same.Examples:Attention reader! Don’t […]

Given a string S of N characters, the task is to calculate the total number of non-empty substrings such that at most one character occurs an odd number of times.Example: Input: S = “aba”Output: 4Explanation: The valid substrings are “a”, “b”, “a”, and “aba”. Therefore, the total number of required substrings are 4.Input: “aabb”Output: 9Explanation: The […]

#include using namespace std;  int countCornerRectangles(    vector& mat){        int count = 0;      int N = mat.size();    int M = mat.size();          map m;          for (int i = 0; i < N; i++) {                  for (int j = 0; j < M; j++) {            if (mat[i][j] == 1) {                                                  for (int k = j + 1;                     k < M; k++) {                    if (mat[i][k] == 1) {                        m[{ j, k }]++;                    }                }            }        }    }                  for […]

Given an array of strings words[] and the sequential order of alphabets, the task is to sort the array according to the given order. Assume that the dictionary and the words only contain lowercase English alphabets.Examples: Input: words[] = {“hello”, “geeksforgeeks”}, order[] = “hlabcdefgijkmnopqrstuvwxyz”Output: hello geeksforgeeks Explanation: According to the given order ‘h’ occurs before ‘g’ and hence […]

Given two Geometric Progressions (a1, r1) and (a2, r2) where (x, y) represents GP with initial term x and common ratio y and an integer N, the task is to find the count of the distinct integers that belong to the first N terms of at least one of the given geometric progressions.Examples:Input: N = […]