Hackerrank – Kangaroo

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution There are two checks: I checked if     is less then     and immediatelly print “NO”. That means, kangaroo 1 would be never able to reach kangaroo 2. I calculated differences between kangaroo positions     and their […]

Hackerrank – Beautiful Triplets

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I checked each consequent combination of (i, j, k), if it is valid according to condition. There is a catch. I had to stop an iteration if array[j] – array[i]

Hackerrank – Strange Counter

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I calculated time in the cycle when counter value is 1: last_time_next_cycle = actual_cycle_time + 2 * (last_time_actual_cycle – last_time_previous_cycle). The difference in seconds between cycle 0 and cycle 1 is 3, which is always like that. For a given […]

Hackerrank – Divisible Sum Pairs

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution Create index pairs variations for all indexes that pair is unique – it means when (i, j) exists (j, i) is the same. For each pair calculate the sum of values at corresponding index. If is divisible, count them and […]

Hackerrank – CamelCase

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution There are 2 options To split the string by regular expression”[A-Z]” and then print the length of an array returned from splitting. To iterate over all characters, count the uppercase and print their count + 1 I created solution in: […]

Hackerrank – Compare The Triplets

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution Read all ratings and compare it according to the defined conditions: If ai > bi, then Alice is awarded 1 point If ai < bi, then Bob is awarded 1 point If ai = bi, then neither person receives a […]

Hackerrank – The Maximum Subarray

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution Contiguous sum – using Kadane’s algorithm Non-contiguous sum – filter all positive elements from given array and sum them. If this array is empty. Take the greatest element. I created solution in: Scala Java JavaScript Ruby All solutions are also […]

Hackerrank – Functions Or Not?

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution Check if for a given value x is always only one function output value y. See function definition. I created solution in: Scala All solutions are also available on my GitHub. Scala

Hackerrank – String-o-Permute

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution For every input line: divide into character pairs reverse order of characters concat the pairs it into the one string I created solution in: Scala All solutions are also available on my GitHub. Scala

Hackerrank – String Mingling

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution Iterate through one of the strings and concatenate each actual character. I created solution in: Scala All solutions are also available on my GitHub. Scala