Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Hi @eguneys, thanks for pointing that out. I have modified the logic and thus works for all of your test cases. I have also updated the test cases image. The placing is done correctly, however the shifting results are different.