Table of Contents
Monday, June 17, 2019
Daily Coding Problem #332: Relationship between SUM, XOR and AND of Two Numbers
Problem Definition
Given integers $M$ and $N$, write a program that counts how many positive integer pairs $(a, b)$ satisfy the following conditions:
$a + b = M$
$a\ XOR\ b = N$
Solution
$\mathtt{Solution\ REFERENCE}$ @
StackOverflow
Implementation
Complexity
This implementation iterates through all the bits in $XOR$ and $AND$. If $N$ be the number of bits, then the time complexity is $\cal{O(N)}$.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment