Free walk
Practice
3 (4 votes)
Basic programming
Algorithms
Easy
Greedy algorithms
Grammar Verified
Basics of greedy algorithms
Problem
67% Success 1134 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are on a circular path of infinite radius. From your initial position, you can move either in the clockwise direction or in the anticlockwise direction but only along the circular path. Your movements are represented by a string $$S$$ of length $$L$$. This string can consist of three different types of characters, each denoting a move:

  • A: You move 1 unit in the anticlockwise direction
  • C: You move 1 unit in the clockwise direction
  • ?: You move 1 unit either in the clockwise or the anticlockwise direction

Write a program to find the maximum distance from your initial position in any direction at any point of time.

Input format

  • First line: $$T$$ (number of test cases)
  • Next $$T$$ lines: $$S$$

Output format

For each test case, print the maximum distance from the initial position in any direction at any point of time.

Constraints

\(1 \le T \le 10\)
\(1 \le Length \; of \; string \le 10^5\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
Basic ProgrammingOpenApprovedEasy
Points:30
5 votes
Tags:
AlgorithmsBinary SearchMediumSearching
Points:30
4 votes
Tags:
Easy-Medium