File tree Expand file tree Collapse file tree 1 file changed +99
-0
lines changed
HackerRank/Interview Preparation Kit/Miscellaneous Expand file tree Collapse file tree 1 file changed +99
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "cells" : [
3+ {
4+ "cell_type" : " markdown" ,
5+ "metadata" : {},
6+ "source" : [
7+ " # Flipping bits\n " ,
8+ " "
9+ ]
10+ },
11+ {
12+ "cell_type" : " code" ,
13+ "execution_count" : null ,
14+ "metadata" : {},
15+ "outputs" : [],
16+ "source" : [
17+ " n=b"
18+ ]
19+ },
20+ {
21+ "cell_type" : " code" ,
22+ "execution_count" : 17 ,
23+ "metadata" : {},
24+ "outputs" : [
25+ {
26+ "name" : " stdin" ,
27+ "output_type" : " stream" ,
28+ "text" : [
29+ " 2\n " ,
30+ " 4\n "
31+ ]
32+ },
33+ {
34+ "name" : " stdout" ,
35+ "output_type" : " stream" ,
36+ "text" : [
37+ " 011\n " ,
38+ " 4294967291\n "
39+ ]
40+ },
41+ {
42+ "name" : " stdin" ,
43+ "output_type" : " stream" ,
44+ "text" : [
45+ " 123456\n "
46+ ]
47+ },
48+ {
49+ "name" : " stdout" ,
50+ "output_type" : " stream" ,
51+ "text" : [
52+ " 00001110110111111\n " ,
53+ " 4294843839\n "
54+ ]
55+ }
56+ ],
57+ "source" : [
58+ " for _ in range(int(input())):\n " ,
59+ " n=int(input())\n " ,
60+ " x=bin(n)[2:]\n " ,
61+ " s=''\n " ,
62+ " for i in x:\n " ,
63+ " if i=='0':\n " ,
64+ " s+='1'\n " ,
65+ " else:\n " ,
66+ " s+='0'\n " ,
67+ " print(int('1'*(32-len(x))+s,2))"
68+ ]
69+ },
70+ {
71+ "cell_type" : " code" ,
72+ "execution_count" : null ,
73+ "metadata" : {},
74+ "outputs" : [],
75+ "source" : []
76+ }
77+ ],
78+ "metadata" : {
79+ "kernelspec" : {
80+ "display_name" : " Python 3" ,
81+ "language" : " python" ,
82+ "name" : " python3"
83+ },
84+ "language_info" : {
85+ "codemirror_mode" : {
86+ "name" : " ipython" ,
87+ "version" : 3
88+ },
89+ "file_extension" : " .py" ,
90+ "mimetype" : " text/x-python" ,
91+ "name" : " python" ,
92+ "nbconvert_exporter" : " python" ,
93+ "pygments_lexer" : " ipython3" ,
94+ "version" : " 3.8.2"
95+ }
96+ },
97+ "nbformat" : 4 ,
98+ "nbformat_minor" : 4
99+ }
You can’t perform that action at this time.
0 commit comments