Bending Spoons interview question

Coding task with apples and pears