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

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

Continue Reading#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 = […]

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

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

Continue Reading