Wednesday, 1 Dec 2021
Category: Bitwise-XOR

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

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

Split an array into subarrays with maximum Bitwise XOR of their respective Bitwise OR valuesGiven an array arr[] consisting of N integers, the task is to find the maximum Bitwise XOR of Bitwise OR of every subarray after splitting the array into subarrays(possible zero subarrays).Examples:Input: arr[] = {1, 5, 7}, N = 3Output: 7Explanation:The given […]