Wednesday, 1 Dec 2021
Category: TrueGeek

#include #define SIZE 100005using namespace std;  void preprocess(string& s, string& t,                int prefix[][SIZE],                int n, int i){        prefix[i][0] = (s[0] != t[0]);      for (int j = 1; j < n; j++) {                                  prefix[i][j]            = prefix[i][j - 1]              + (s[j] != t[j % 3]);    }    return;}  void minChangesNonPalindrome(    string str, int N, int Q,    vector queries){          int prefix[6][SIZE];                  vector sequences        = { "012", "021", "102",            "120", "201", "210" };      for (int i = 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 […]

#include using namespace std;  void traverse(int M, int N,              vector& matrix,              int row, int col){          if (row >= 0 && row < M        && col >= 0 && col < N) {        if (matrix[row][col] == 0) {            return;        }                          matrix[row][col] = 0;                  traverse(M, N, matrix, row, col - 1);                  traverse(M, N, matrix, row, col + 1);                  traverse(M, N, matrix, row - 1, col);                  traverse(M, N, matrix, row + […]

import java.io.*;import java.util.*;  public class index {    static int max = 0;    static String ans1 = “”;          static void calculate(String ans)    {          int dp[] = new int[26];        for (int i = 0; i < ans.length(); ++i) {                                      dp[ans.charAt(i) - 'A']++;        }                  for (int i = 0; i < dp.length; ++i) {            if (dp[i] % 2 == 1) {                return;            }        }        if (max < ans.length()) {                                      max = ans.length();            ans1 = ans;        }    }                  static […]