6 kyu

Crossing the river and its tributaries

24 of 47rPersival

Description:

Description

The travelers decided to take a trip along the river, which has many tributaries. They plan to start their trip somewhere on the left bank and end up on the right bank. Since crossing the river and its tributaries isn't easy, they want to keep the number of crossings as low as possible. Before the trip, they checked the map and wrote down the order of the tributaries flowing into the river along the entire route.

Input

You're given a string containing only the uppercase characters L, R and B, where:

  • L represents a tributary on the left bank,
  • R represents a tributary on the right bank, and
  • B represents tributaries on both banks.

Constraints

0 <= path.length() <= 1000

Example

If the input string is LLBR, the travelers need to cross the river and two right-side tributaries to finish on the right bank. The total number of crossings will be 3.

imgur

Good luck!

Algorithms
Strings
Performance

Similar Kata:

Stats:

CreatedAug 7, 2022
PublishedAug 7, 2022
Warriors Trained336
Total Skips87
Total Code Submissions438
Total Times Completed47
C++ Completions24
Java Completions17
JavaScript Completions16
Total Stars10
% of votes with a positive feedback rating90% of 20
Total "Very Satisfied" Votes16
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes0
Total Rank Assessments13
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • rPersival Avatar
  • dfhwze Avatar
Ad