HackerRank Çözümleri – Bit Manipulation: Lonely Integer

HackerRank içerisinde bulunan “Bit Manipulation: Lonely Integer” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir tam sayı dizisi içerisinde, sadece bir elemanın tek adet, diğer tüm sayıların iki adet olduğu belirtilip, bu tek olan sayıyı bulmanız isteniyor.

► HackerRank – Bit Manipulation: Lonely Integer: https://www.hackerrank.com/challenges/ctci-lonely-integer/problem

► Problem açıklaması:

Consider an array of integers where all but one of the integers occur in pairs. In other words, every element occurs exactly twice except for one unique element. Find the unique element.

For example, given the array arr = [1, 1, 2, 3, 2], you would return 3.

Sample Input 0

1

1

Sample Output 0

1

Explanation 0

The array only contains a single 1, so we print 1 as our answer.

Sample Input 1

3

1 1 2

Sample Output 1

2

Explanation 1

We have two 1’s and one 2. We print 2, because that’s the only unique element in the array.

Sample Input 2

5

0 0 1 2 1

Sample Output 2

2

Explanation 2 We have two 0’s, two 1’s, and one 2. We print 2, because that’s the only unique element in the array.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.