The first code allows a closing bracket to be matched to any matching opening bracket that appears before it while the latter code only allows it if it is the last opening bracket it sees.
Case in point for the former code
cout << is_balanced("([)]");
returns true
While for the latter code it returns false.
Course: Competitive Programming in C++: The Keys to Success - Learn Interactively
Lesson: Solved Problem - Balanced Parentheses Sequence - Competitive Programming in C++: The Keys to Success