Closing Triplets Hackerrank Solution