tom helped fix the algo for all test cases to validate correctly