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] = (s != t);      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[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 […]

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

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

#include using namespace std;  int DirX[] = { 2, 1, -1, -2, -2, -1, 1, 2 };int DirY[] = { 1, 2, 2, 1, -1, -2, -2, -1 };  bool isSafe(int i, int j, int n,            vector& Board){    return (i >= 0 and j >= 0 and i < n and j < n            and Board[i][j] == 0);}  bool isPossible = […]

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

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