# 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.

# HackerRank Çözümleri – Mark and Toys

HackerRank içerisinde bulunan “Mark and Toys” sorusunun açıklaması ve çözümü. Burada verilen oyuncakların fiyat listesine ve elinizdeki paraya göre, en fazla kaç adet oyuncak satın alabileceğinizin bulunması isteniyor.

► HackerRank – Mark and Toys: https://www.hackerrank.com/challenges/mark-and-toys/problem

► Problem açıklaması:

Mark and Jane are very happy after having their first child. Their son loves toys, so Mark wants to buy some. There are a number of different toys lying in front of him, tagged with their prices. Mark has only a certain amount to spend, and he wants to maximize the number of toys he buys with this money. Given a list of toy prices and an amount to spend, determine the maximum number of gifts he can buy.

Note Each toy can be purchased only once.

Example;

prices = [1, 2, 3, 4]

k = 7

The budget is 7 units of currency. He can buy items that cost [1, 2, 3] for 6, or [3, 4] for 7 units. The maximum is 3 items.

Function Description

Complete the function maximumToys in the editor below.

maximumToys has the following parameter(s):

int prices[n]: the toy prices

int k: Mark’s budget

Returns

int: the maximum number of toys

Sample Input

7 50

1 12 5 111 200 1000 10

Sample Output

4

Explanation

He can buy only 4 toys at most. These toys have the following prices: 1, 12, 5, 10.

# HackerRank Çözümleri – Alternating Characters

HackerRank içerisinde bulunan “Alternating Characters” sorusunun açıklaması ve çözümü. Soruda size verilen string içerisinde, yan yana hiçbir karakterin aynı olmaması için kaç defa karakter silme işlemi yapmanız gerektiği soruluyor.

► HackerRank – Alternating Characters: https://www.hackerrank.com/challenges/alternating-characters/problem

► Problem açıklaması:

You are given a string containing characters A and B only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string.

Example

s = AABAAB

Remove an A at positions 0 and 3 to make s = ABAB in 2 deletions.

Function Description

Complete the alternatingCharacters function in the editor below.

alternatingCharacters has the following parameter(s):

string s: a string

Returns

int: the minimum number of deletions required

Sample Input

5

AAAA

BBBBB

ABABABAB

BABABA

AAABBB

Sample Output

3

4

0

0

4