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 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.
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.
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.
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.
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?
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):
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.
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 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.