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 ReadingGiven three numbers N, S and X the task is to find if it is possible to construct a sequence A of length N, where each A[i] >= 0 for 1 X + ( S – X)/2 + (S – X)/2 = X + (S-X) => X + ( S – X)/2 + (S – […]

Continue ReadingGiven 3 integers A, B, C, the task is to find the maximum XOR value of three number selected one from each range [0, A], [0, B], [0, C] respectively.Example: Input: A = 1, B = 2, C = 4Output: 7Explanation: Maximum XOR can be calculated by selecting 1 (from [0, 1]), 2 (from [0, 2]) […]

Continue ReadingCount of integers K in range [0, N] such that (K XOR K+1) equals (K+2 XOR K+3)Given an integer N, the task is to print the count of all the non-negative integers K less than or equal to N, such that bitwise XOR of K and K+1 equals bitwise XOR of K+2 and K+3.Examples:Input: N […]

Continue Reading#include using namespace std; string sub(string s){ int n = s.size(); for (int i = n – 1; i >= 0; i–) { if (s[i] == ‘0’) { s[i] = ‘1’; } else { s[i] = ‘0’; break; } } return s;} string ad(string s){ int n = s.size(); int carry = 0; for (int i = n – 1; i >= 0; i–) { if (s[i] == ‘1’) { carry = 1; s[i] […]

Continue Reading#include using namespace std; int xorSumOfArray(int arr[], int n, int k, int count[]){ int sum = 0; int p = 1; for (int i = 0; i < 31; i++) { int val = 0; if ((k & (1

Continue ReadingFind all possible pairs with given Bitwise OR and Bitwise XOR valuesGiven two positive integers A and B representing Bitwise XOR and Bitwise OR of two positive integers, the task is to find all possible pairs (x, y) such that x ^ y is equal to A and x | y is equal to B.Examples:Input: […]

Continue ReadingPrint all distinct even and odd prefix Bitwise XORs of first N natural numbersGiven a positive integer N, the task is to print all the distinct even and odd values of prefix Bitwise XORs of first N natural numbers.Examples:Input: N = 6Output:Even: 0 4Odd: 1 3 7Explanation:The prefix Bitwise XOR of the first 6 natural […]

Continue Reading