I have used 2 approaches. Both aren’t passing all test cases.
KIndly find error in code
The approach you have followed in your first code is correct…just use = as well in line no 10 along with the less than sign…and then try to suit the code…