-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsolution.py
More file actions
44 lines (32 loc) · 927 Bytes
/
solution.py
File metadata and controls
44 lines (32 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
Topic : Algorithms
Subtopic : Flipping bits
Language : Python3
Problem Statement :
You will be given a list of 32 bit unsigned integers. Write a function to Flip all the bits (1 -> 0 and 0 -> 1) and return the result as an unsigned integer.
Url : https://www.hackerrank.com/challenges/flipping-bits/problem
'''
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'flippingBits' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts LONG_INTEGER n as parameter.
#
BITS = pow(2, 32) - 1
def flippingBits(n):
# Write your code here
return BITS ^ n
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input().strip())
for q_itr in range(q):
n = int(input().strip())
result = flippingBits(n)
fptr.write(str(result) + '\n')
fptr.close()