Here, I am providing my solution to the problem "**BitMasking**" with the intention to help you learn and understand Python 3 in a better way.

Please make use of my blog posts for learning purposes only and feel free to ask your questions in the comment box below in case of any doubt.

Click Here to check out all other HackerRank solutions.

Recommended Python Courses:

1. Udemy: Top Python Courses

2. Udemy: 2021 Complete Python Bootcamp From Zero to Hero in Python

3. Udemy: Learn Python Programming Masterclass

4. Coursera: Python for Everybody

5. LinkedIn: Become a Python Developer

6. edX: Programming for Everybody (Getting Started with Python)

7. edureka: Python Programming Certification Training

8. Eduonix: Mighty Python Bundle

## Python Problem Description:

Anubhav and Charul are 2 friends travelling to a far away place for ICPC, the biggest competitive coding competition. They decide to play a game.

Anubhav gives Charul a bitmask. He tells Charul that bitmasks are very cool. According to him, A bitmask is a string of binary bits (0s and 1s).

**For example**

- "0111000" is a bitmask. Anubhav is a naughty but brilliant computer scientist. He has given Charul the following task:
- Given a number N, write a bitmask of length N containing all 0s. Now, he gives Q operations. Each operation contains two numbers (l, r) as input.

**An operation can be one of the following**

- Update operation: Take the XOR of all the bits in the bitmask from index l to r (both inclusive) with 1.
- Query operation: Count the number of set bits in the bitmask between index l to r (both inclusive).
- He asks Charul to find the sum of all the queries.

**Note**

1. In case there are no queries, output 0.

2. As the answer can be large, output the answer mod 1000000007

3. Consider 0 based indexing

## Input Format:

- The first line contains the input N (the no. of bits)
- The second line contains Q (the no. of operations)
- The next Q lines contain three inputs each 'type','l' and 'r'.
- If type is 0, it's an update operation, else a query operation.

## Sample Input:

## Sample Output:

## Constraints:

- 1 <= N <= 100000
- 1 <= Q <= 100000
- 0 <= l, r < N

## Task Weightage:

## Note: You can choose any language for coding Java, c++, python, go.

## Python 3 Solution:

## Output:

### [Case-0] Output:

### [Case-1] Output:

**Click here**to see solutions for all

**Machine Learning**Coursera Assignments.

**Click here**to see more codes for

**Raspberry Pi 3**and similar Family.

**Click here**to see more codes for

**NodeMCU ESP8266**and similar Family.

**Click here**to see more codes for

**Arduino Mega (ATMega 2560)**and similar Family.

**-Akshay P Daga**