← DiffPush

Check for odd even

Baseline Bit Manipulation · Learn Bit Manipulation O(1) · O(1)

Reading the Turnstile's Parity Wire

A stadium turnstile reports crowd counts as integers, and the gate controller only needs to know whether the count is odd or even before opening lanes. The fastest probe reads the count's least significant wire: voltage present means an odd count, absent means even. No division, no modulo — one wire answers instantly.

Input: A positive integer N.

Output: The string "odd" when the least significant bit of N is set, "even" otherwise.

Constraints

Examples

Example 1

Input: {"n":1}
Output: "odd"
The least significant wire of 1 carries voltage.

Example 2

Input: {"n":42}
Output: "even"
42 ends in a 0 bit, so the turnstile reports an even count.

Solve this in your browser →

Also on LeetCode ↗