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] <= d or array[k] - array[j] <= d

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby

Leave a Reply

Your email address will not be published. Required fields are marked *