XYZ Interview Question

ballon burst problem from leetcode