Hackerrank – Connecting Towns

Problem Statement A description of the problem can be found on Hackerrank. Solution Count of all routes as multiplication of routes between towns. I created solution in: Java JavaScript Scala Ruby All solutions are also available on my GitHub. Java

JavaScript

Scala

Ruby

Hackerrank – Computing the GCD

Problem Statement A description of the problem can be found on Hackerrank. Solution I used Euclid’s algorithm for computing Greatest Common Divisor. I created solution in: Scala All solutions are also available on my GitHub. Scala

Hackerrank – Closest Numbers

Problem Statement A description of the problem can be found on Hackerrank. Solution Sort the input array ascending. For element at index i do difference with element at index i+1. Find the minimum difference. Check all elements and find all pair that have this minimum difference. Print found elements ascending. I created solution in: Java […]

Hackerrank – B’day Gift

Problem Statement A description of the problem can be found on Hackerrank. Solution Sum all elements. The result is sum / 2. I created solution in: Java JavaScript Scala Ruby All solutions are also available on my GitHub. Java

JavaScript

Scala

Ruby

Hackerrank – Anagram

Problem Statement A description of the problem can be found on Hackerrank. Solution Divide the input string into two halves. Count all common character in the halves. A result is difference between length of the one half and count of the common characters. Different solution deletes common characters from the second half. The result is […]

Hackerrank – Alternating Characters

Problem Statement A description of the problem can be found on Hackerrank. Solution Iterate through all string characters. If actual character i is different then character i-1 then use character i for next comparison. If they are not equal increment a deletion counter. Print the value of the counter. I created solution in: Java JavaScript […]

Hackerrank – Alien Username

Problem Statement A description of the problem can be found on Hackerrank. Solution Regular Expression that validates input username: ^[_\.]\d+[a-zA-Z]*_?$ I created solution in: Java JavaScript Scala Ruby All solutions are also available on my GitHub. Java

JavaScript

Scala

Ruby

Hackerrank – Chocolate Feast

Problem Statement A description of the problem can be found on Hackerrank. Solution Calculate count of chocolates: chocolates = money / price . Count of chocolates is count of wrappers, too. Free chocolates are calculated: divide chocolates with count of chocolates needed for discount add solution of the division to chocolates new wrappers count is: […]

Hackerrank – Cavity Map

Problem Statement A description of the problem can be found on Hackerrank. Solution Filter all matrix indexes that are at the periphery. For all the rest choose one index and compare its value with all neighbours (left, right, up, down). If it is greater than all neighbours, replace it with ‘X’. I created solution in […]

Hackerrank – Service Lane

Problem Statement A description of the problem can be found on Hackerrank. Solution Find minimum in given array from index i to j. I created solution in 4 languages: Scala Java JavaScript Ruby All solutions are also available on my GitHub. Scala

Java

JavaScript

Ruby