Beautiful Triplets Hackerrank Solution