1 solutions
-
1thakuremon LV 4 @ 2024-04-01 20:50:20
Lets see the first 6 operations in "RGB" string.
RGB -> GRB -> GBR -> BGR -> BRG -> RBG -> RGB
so we can see the string repeats itself in every 6 operations. Applying 6 operations is equivalent to 6%6=0 operations. applying 7 operations is equivalent to 7%6=1 operations and so on.
That means we dont need to do all K operations. Instead we can find the answer in just K%6 operations.
time complexity: O(1)
- 1
Information
- ID
- 1010
- Difficulty
- 5
- Category
- (None)
- Tags
- (None)
- # Submissions
- 97
- Accepted
- 34
- Accepted Ratio
- 35%
- Uploaded By