Category: Bitwise-XOR

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

XOR of very large Binary Numbers in range [L, R]

#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