'When writing pop_back in backtracking is necessary?

enter image description here[![ GFG Qtn Link:- https://practice.geeksforgeeks.org/problems/paths-from-root-with-a-specified-sum/1/

Why here without writing the ans.pop_back(); the code works perfectly and how to know when to pop and when not to pop

]2]2



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source