Connection Status:
Competition Arena > FriendFinder
Beginner SRM 2 · 2021-01-13 · by erinn · Geometry
Class Name: FriendFinder
Return Type: int
Method Name: distance
Arg Types: (string)
Problem Statement

Problem Statement

You and your friend are waiting in a line. A description of the line is given in the String line. The character 'S' represents yourself, the character 'F' represents your friend, and '.' indicates anyone else in the line.

How far apart are you and your friend in this line?

Constraints

  • line will have between 2 and 50 characters, inclusive.
  • Each character of line will be '.', 'S', or 'F'.
  • 'S' and 'F' will each appear exactly once in line.
Examples
0)
"....SF..."
Returns: 1

You and your friend are adjacent in this line, thus you are one position away from each other.

1)
"S........F"
Returns: 9

You and your friend are at completely opposite ends of this line.

2)
"..F...S.."
Returns: 4

You and your friend may appear in either order.

3)
"S........................................F"
Returns: 41
4)
".................................FS"
Returns: 1

Submissions are judged against all 11 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FriendFinder with a public method int distance(string line) · 11 test cases · 2 s / 256 MB per case

Submitting as anonymous