# 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

# HackerRank Çözümleri – Caesar Cipher

HackerRank içerisinde bulunan “Caesar Cipher” sorusunun açıklaması ve çözümü. Soruda size verilen string’i sezar şifrelemesi ile, harflerini alfabedeki sıralarını verilen sayı kadar ötelemeniz isteniyor.

► HackerRank – Caesar Cipher: https://www.hackerrank.com/challenges/caesar-cipher-1/problem

► Problem açıklaması:

Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar’s cipher (https://en.wikipedia.org/wiki/Caesar_cipher) shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b and c.

Original alphabet: abcdefghijklmnopqrstuvwxyz

Alphabet rotated +3: defghijklmnopqrstuvwxyzabc

Sample Input

11

middle-Outz

2

Sample Output

okffng-Qwvb

Explanation

Original alphabet: abcdefghijklmnopqrstuvwxyz

Alphabet rotated +2: cdefghijklmnopqrstuvwxyzab

m — o

i — k

d — f

d — f

l — n

e — g

– –

O — Q

u — w

t — v

z — b

# HackerRank Çözümleri – Mini-Max Sum

HackerRank içerisinde bulunan “Mini-Max Sum” sorusunun açıklaması ve çözümü. Verilen 5 adet sayıdan, 4 sayının toplamının alabileceği en küçük ve en büyük değerleri bulmanız isteniyor.

► HackerRank – Mini-Max Sum: https://www.hackerrank.com/challenges/mini-max-sum/problem

► Problem açıklaması:

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.

Example:

arr = [1, 3, 5, 7, 9]

The minimum sum is 1 + 3 + 5 + 7 = 16 and the maximum sum is 3 + 5 + 7 + 9 = 24. The function prints: 16 24.

Function Description

Complete the miniMaxSum function in the editor below.

miniMaxSum has the following parameter(s):

arr: an array of 5 integers.

Print

Print two space-separated integers on one line: the minimum sum and the maximum sum of 4 of 5 elements.

Output Format

Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)

Sample Input

1 2 3 4 5

Sample Output

10 14

# HackerRank Çözümleri – Two Strings

HackerRank içerisinde bulunan “Two Strings” sorusunun açıklaması ve çözümü. Bu soruda size verilen iki adet string‘in ortak bir substring’i olup olmadığı soruluyor. Bu arada substring’ler 1 karakter uzunluğunda da olabilir.

► HackerRank – Two Strings: https://www.hackerrank.com/challenges/two-strings/problem

► Problem açıklaması:

Given two strings, determine if they share a common substring. A substring may be as small as one character.

Example:

s1 = “and”

s2 = “art”

These share the common substring “a”.

s1 = “be”

s2 = “cat”

These do not share a substring.

Function Description

Complete the function

twoStrings in the editor below. twoStrings has the following parameter(s):

string s1: a string

string s2: another string

Returns

string: either YES or NO

# HackerRank Çözümleri – Minimum Absolute Difference in an Array

HackerRank içerisinde bulunan “Minimum Absolute Difference in an Array” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir tam sayı dizisi içerisinde, herhangi iki elemanın arasındaki mutlak değer farkının minimum değerini döndürmeniz isteniyor.

► HackerRank – Minimum Absolute Difference in an Array: https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem

► Problem açıklaması:

The absolute difference is the positive difference between two values a and b, is written |a – b| or |b – a| and they are equal. If a = 3 and b = 2, |3 – 2| = |2 – 3| = 1. Given an array of integers, find the minimum absolute difference between any two elements in the array.

Function Description

Complete the minimumAbsoluteDifference function in the editor below. It should return an integer that represents the minimum absolute difference between any pair of elements.

Sample Input 0

3

3 -7 0

Sample Output 0

3

Sample Input 2

5

1 -3 71 68 17

Sample Output 2

3

# HackerRank Çözümleri – Sales by Match

HackerRank içerisinde bulunan “Sales by Match” sorusunun açıklaması ve çözümü. Bu soruda, size üzerindeki numaraları renklerini belirten çoraplar verildiğinde, kaç adet çorap çifti oluşturabileceğiniz soruluyor.

► HackerRank – Sales by Match: https://www.hackerrank.com/challenges/sock-merchant/problem

► Problem açıklaması:

Alex works at a clothing store. There is a large pile of socks that must be paired by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.

For example, there are n = 7 socks with colors ar = [1, 2, 1, 2, 1, 3, 2] . There is one pair of color 1 and one of color 2. There are three odd socks left, one of each color. The number of pairs is 2.

Sample Input

9

10 20 20 10 10 30 50 10 20

Sample Output

3

# HackerRank Çözümleri – Jumping on the Clouds

HackerRank içerisinde bulunan “Jumping on the Clouds” sorusunun açıklaması ve çözümü. Bu soruda size verilen bulutlar, ve bunların hangilerinin üzerinden zıplayıp zıplayamayacağınız bilgisi veriliyor. Bir seferde 1 veya 2 bulut zıplayabiliyorsunuz. İlk buluttan son buluta kaç zıplamada gidebilirsiniz?

► HackerRank – Jumping on the Clouds: https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem

► Problem açıklaması:

There is a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. The player can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus 1 or 2. The player must avoid the thunderheads. Determine the minimum number of jumps it will take to jump from the starting postion to the last cloud. It is always possible to win the game.

For each game, you will get an array of clouds numbered 0 if they are safe or 1 if they must be avoided.

Example

c = [0, 1, 0, 0, 0, 1, 0]

Index the array from 0…6. The number on each cloud is its index in the list so the player must avoid the clouds at indices 1 and 5. They could follow these two paths: 0-2-4-6 or 0-2-3-4-6. The first path takes 3 jumps while the second takes 4. Return 3.

Function Description

Complete the jumpingOnClouds function in the editor below. jumpingOnClouds has the following parameter(s):

– int c[n]: an array of binary integers

Returns

– int: the minimum number of jumps required

# HackerRank Çözümleri – Balanced Brackets

HackerRank içerisinde bulunan “Balanced Brackets” sorusunun açıklaması ve çözümü. Bu soruda size verilen string’in, parantez, köşeli parantez ve süslü parantezler açısından, dengeli bir string (doğru şekilde açılan parantezin doğru şekilde kapanması) olup olmadığı soruluyor.

► HackerRank – Balanced Brackets: https://www.hackerrank.com/challenges/balanced-brackets/problem

► Problem açıklaması:

A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].

Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and ().

A matching pair of brackets is not balanced if the set of brackets it encloses are not matched. For example, {[(])} is not balanced because the contents in between { and } are not balanced. The pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of parentheses encloses a single, unbalanced closing square bracket, ].

By this logic, we say a sequence of brackets is balanced if the following conditions are met:

► It contains no unmatched brackets.

► The subset of brackets enclosed within the confines of a matched pair of brackets is also a matched pair of brackets.

Given n strings of brackets, determine whether each sequence of brackets is balanced. If a string is balanced, return YES. Otherwise, return NO.

Function Description

Complete the function isBalanced in the editor below. It must return a string: YES if the sequence is balanced or NO if it is not.

isBalanced has the following parameter(s):

s: a string of brackets

Input Format

The first line contains a single integer , the number of strings. Each of the next lines contains a single string , a sequence of brackets.

For each string, return YES or NO.

Sample Input

3

{[()]}

{[(])}

{{[[(())]]}}

Sample Output

YES

NO

YES

Explanation

1. The string {[()]} meets both criteria for being a balanced string, so we print YES on a new line.

2. The string {[(])} is not balanced because the brackets enclosed by the matched pair { and } are not balanced: [(]).

3. The string {{[[(())]]}} meets both criteria for being a balanced string, so we print YES on a new line.

# HackerRank Çözümleri – Diagonal Difference

HackerRank içerisinde bulunan “Diagonal Difference” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir kare matris içerisinde, diyagonallerdeki eleman toplamlarının farklarının mutlak değerini bulmanız isteniyor. Evet biraz karmaşık bir cümle oldu farkındayım.

► HackerRank – Diagonal Difference: https://www.hackerrank.com/challenges/diagonal-difference/problem

► Problem açıklaması:

Given a square matrix, calculate the absolute difference between the sums of its diagonals.

For example, the square matrix arr is shown below:

1 2 3

4 5 6

9 8 9

The left-to-right diagonal = 1 + 5 + 9 = 15. The right to left diagonal = 3 + 5 + 9 = 17. Their absolute difference is |15 – 17| = 2.

Mutlak değer nedir? https://tr.wikipedia.org/wiki/Mutlak_de%C4%9Fer