Hackerrank – Jumping on the Clouds

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I created a pointer for an actual position which starts at index 0. I always tried to jump at position i + 2. If it is not possible because of thundercloud I step at i + 1 position. I do […]

Hackerrank – Beautiful Binary String

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I replaced all occurences of “010” with an arbitrary placeholder. Then I counted the placeholders. I created solution in: Scala Java JavaScript Ruby All solutions are also available on my GitHub. Java

JavaScript

Scala

Ruby

Hackerrank – Circular Array Rotation

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution We rotate the array in circles. That why it is enough to calculate a position after all rotations using modulo. We split the array into two halves at position array_length – calculated_position. We change halves and concat them – the […]

Hackerrank – Jumping on the Clouds: Revisited

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I jumped for k positions and lowered the energy. If I reached position 0 I printed the remaining enenergy. I created solution in: Scala Java JavaScript Ruby All solutions are also available on my GitHub. Java

JavaScript

Scala […]

Hackerrank – Mars Exploration

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I divided the whole string into to 3-character parts. Then I checked for each triplet if first character is equal to S, second to O and third to S. And counted the changed letters. I created solution in: Scala Java […]

Hackerrank – Minimum Distances

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution Create index pairs variations for all indexes that pair are unique – it means when (i, j) exists (j, i) is the same. Filter only this pairs of indexes, which have the same value. Make an absolute difference of them […]

Hackerrank – String Construction

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution The answer is the count of distinct characters. If the string does not contain a specific character, only then it costs 1 dollar. Because one character is a substring. When we are able to find it in a partially created […]

Hackerrank – Save the Prisoner

Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution (((sweets % prisoners) + startId) % prisoners) – 1 Modulo finds the id of prisoner who gets the last poisoned candy after all circles distribution. Since the starting id S is not from first prisoner we make an offset. Do […]