Category: Hash

Introduction to Universal Hashing in Data Structure

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 […]

Continue Reading

Count of substrings with the frequency of at most one character as Odd

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 […]

Continue Reading

Find the number of corner rectangles that can be formed from given Matrix

  #include using namespace std;  int countCornerRectangles(    vector& mat){        int count = 0;      int N = mat.size();    int M = mat[0].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 […]

Continue Reading

Sort an array of strings based on the given order | Set-2

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 […]

Continue Reading