StreetParking
SRM 159 · 2003-08-12 · by dimkadimon
Problem Statement
You are looking for a place to park your car on a suburban street. You can park at any position that meets the following requirements:
1. It is not directly in front of a private driveway. 2. It is not directly in front of a bus stop. 3. It is not 5 meters before a bus stop. 4. It is not 10 meters before a bus stop. 5. It is not directly in front of a side-street. 6. It is not 5 meters before a side-street. 7. It is not 5 meters after a side-street.
The street will be represented as a
Given the street return the total number of possible parking spaces on that street.
Constraints
- street will have between 1 and 50 characters inclusive.
- street will only contain characters 'D', 'B', 'S' and '-'.
"---B--S-D--S--" Returns: 4
The street looks like this: ---B--S-D--S-- ^ ^ ^ ^ | | | | The arrows indicate where you are allowed to park on this street. Thus the method should return 4.
"DDBDDBDDBDD" Returns: 0
This street is full of private driveways and bus stops. You cannot park anywhere on this street. The method should return 0.
"--S--S--S--S--" Returns: 2
You can only park at the first and last positions on this street. The method should return 2.
"SSD-B---BD-DDSB-----S-S--------S-B----BSB-S--B-S-D" Returns: 14
"-SB---S----DD-D-DS---B--BD-S-SD---D----D-B---B-SDD" Returns: 15
Submissions are judged against all 47 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class StreetParking with a public method int freeParks(string street) · 47 test cases · 2 s / 256 MB per case