Tag Archives: hackerrank türkçe

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