passed all tests on hackerrank