C++ | Bit Manipulation
Edit : Adding explanation\n\nWe need to check if a string has all the 26 lowercase english alphabets from \'a\' to \'z\'. Also, we do not care about the number 
Edit : Adding explanation\n\nWe need to check if a string has all the 26 lowercase english alphabets from \'a\' to \'z\'. Also, we do not care about the number of occurances, the only thing we need to check is : each character should have atleast 1 occurance. So we can use a set and keep inserting all the characters of the string till the end and finally we can check if the set size is equal to 26. But we can notice that in summary we are only required to store 26 elements at max in the set so we can use bit manipulation instead of a set to do it. \nWe can use an integer\'s 26 least significant bits to store presence of each character , i.e.\n\n\n```\nb26 b25 ... b2 b1\n```\n\nwhere `bi` is the bit at `ith` position. We will set `ith` bit if we have `ith` english lowercase alphabet in the string (starting from \'a\' ). We will iterate over the string, store the presence of each lowercase english alphabet like below : \n\ne.g. If we get \'a\' , we will set the 1st bit using , \n```\nn = n | (1<<(c-\'a\'))\n```\nThis will set the 1st bit ( read [this](https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit) if you are unable to understand the above statement ) , similarly if we get \'z\', we will set the 26th bit and at last, after we are done iterating over the complete string, we just need to check if all the 26bits of the number are set (i.e. all the 26 lowercase english alphabtes are present in the input string). We can do this by 1 simple observation, \n```\n1111 (base 2) = 15 (base 10)\n111111 (base 2) = 63 (base 10)\n```\n\nIn general, if the `n` bit binary number contains only `n` set bits, then its decimal equivalent = `2^(number of bits) - 1` \n\nSo, we can check if all bits are set using above observation and return true only if \n\n```\nn == pow(2,26) -1\n```\n\nC++ CODE : \n\n```    \nbool checkIfPangram(string s) {\n        int n = 0;\n        for(char c:s){\n            n = n | (1<<(c-\'a\')); // set character\'s corresponding bit\n        }\n        return n==pow(2,26)-1; // check if all 26 bits are set\n    }
['Bit Manipulation']