My issue
i am not able to get how it calculated number of different ways.
Make 2 arrays of prefix and suffix sum and check on the arrays index whether they hav equal values or they have abs difference of 1. You may check my code for this. Logic behind is when they are equal from right and left this means on both directions ball will make everyone 0 and in case of difference of 1, leaving ball first to greater sum will destroy all the walls.