solved hackerrank triplets problem