Company: Wipro_9july
Difficulty: medium
Balanced Bracket-like String Scoring Problem Description You are given a string S consisting only of the characters '<' , '>' , and '?' . Treating '<' as an opening bracket and '>' as a closing bracket, compute a score for S using the following process. Scan S from left to right while tracking a counter of currently unmatched opening brackets ( open , starting at 0) and a running total score (starting at 0): '<' — increment open by 1 (one more unmatched opening bracket). '>' — when open > 0 , it pairs with the most recently unmatched opening bracket: decrement open by 1 and add 2 to score . When open == 0 , this '>' has no match and is skipped. '?' — acts as a divider that clears every currently unmatched opening bracket: set open back to 0. A '?' never contributes to the score by itself. Return the final score (always equal to 2 × the number of matched '<' … '>' pairs). Examples S = "<<>>" → 4 S = "<<&