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

Hackerrank – Encryption

Problem Statement A description of the problem can be found on Hackerrank. Solution Calculate a width and height of a required matrix: height = ceil(length(input_string) width = floor(length(input_string) Then create a height x width matrix containing a characters from input_string. Transpose the matrix and print all rows. Node: Instead we can print all columns of […]

Hackerrank – Diagonal Difference

Problem Statement A description of the problem can be found on Hackerrank. Solution Make 2 sums for 2 diagonals – from left to right, from right to left. Substract 2 sums and print its absolute value. I created solution in 4 languages: Scala Java JavaScript Ruby All solutions are also available on my GitHub. Scala […]

Hackerrank – Staircase

Problem Statement A description of the problem can be found on Hackerrank. Solution Create n times a line consting of spaces (‘ ‘) and hashes (‘#’). Each line contains incremented count of hashes and decremented count of spaces form 1 to n, respectively n downto 1. I created solution in 4 languages: Scala Java JavaScript […]