File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ # Find the Missing Number
2+ # You are given a list of n-1 integers and these integers are in
3+ # the range of 1 to n. There are no duplicates in list. One of
4+ # the integers is missing in the list. Write an efficient code
5+ # to find the missing integer.
6+
7+
8+ def missing (arr ):
9+ size = len (arr )
10+ a1 = arr [0 ]
11+ a2 = 1
12+ for i in range (1 , size ):
13+ a1 = a1 ^ arr [i ]
14+ for i in range (2 , size + 2 ):
15+ a2 = a2 ^ i
16+
17+ return a1 ^ a2
18+
19+
20+ if __name__ == '__main__' :
21+
22+ a = [1 , 2 , 4 , 5 , 6 ]
23+
24+ miss = missing (a )
25+ print (miss )
Original file line number Diff line number Diff line change 1+ # check given number is odd or even without using modulus operator.
2+
3+
4+ def check_Even_odd (number ):
5+ """This function check whether the given number is odd or even"""
6+ if (number & 1 ) == 1 :
7+ print ("Odd Number" )
8+ else :
9+ print ("Even Number" )
10+
11+
12+ a = 5
13+ b = 6
14+ check_Even_odd (a )
15+ check_Even_odd (b )
Original file line number Diff line number Diff line change 1+ # Program to find whether a no is power of two
2+ # Given a positive integer, write a function to find if it is a power of two or not.
3+
4+ # Input : n = 4
5+ # Output : Yes
6+ # 22 = 4
7+
8+ # Input : n = 7
9+ # Output : No
10+
11+ # Input : n = 32
12+ # Output : Yes
13+ # 25 = 32
14+
15+
16+ def check_Power (number ):
17+ if (number & number - 1 ) == 0 :
18+ print ("yes" )
19+ else :
20+ print ("NO" )
21+
22+
23+ a = 4
24+ b = 7
25+ c = 32
26+ check_Power (a )
27+ check_Power (b )
28+ check_Power (c )
You can’t perform that action at this time.
0 commit comments