Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Parity of unsigned integer
Basic Accuracy: 63.44% Submissions: 698 Points: 1

Given an integer N, find it's parity. 
Parity of a number refers to the number of 1 bits it contains. The number has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it contains even number of 1-bits.

Example 1:

N = 13
Output: odd
(13)10 = (1101)2  The binary representation
has three 1-bits. So, it's parity is odd.

Example 2:

N = 9
Output: even
(9)10 = (1001)2  The binary representation
has two 1-bits. So, it's parity is even.


Your Task:
You don't need to read input or print anything. Your task is to complete the function computeParity() which takes an Integer N as input parameter and returns string "odd" or "even".


Expected Time Complexity: O(log(N))
Expected Auxiliary Space: O(1)


1 <= N <= 105

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Parity of unsigned integer

Output Window