optimized hackerrank