I spent 20 mins non-stop to code it and really loose interests in debugging. Despite being labeled as hard, the solution is quite straight forward if you can figure out how test cases are solved. However, the sheer amounts of codes need to be done is really outrageous.
@ben.meng.7 agreed. Unless there is some elegant solution that I missed.