Statistics

Problem Statement for "FriendFinder"

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?

Definition

Class:
FriendFinder
Method:
distance
Parameters:
String
Returns:
int
Method signature:
int distance(String line)
(be sure your method is public)

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

  1. "....SF..."

    Returns: 1

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

  2. "S........F"

    Returns: 9

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

  3. "..F...S.."

    Returns: 4

    You and your friend may appear in either order.

  4. "S........................................F"

    Returns: 41

  5. ".................................FS"

    Returns: 1

  6. "...S.....F"

    Returns: 6

  7. "F..S................."

    Returns: 3

  8. "..S.....F..."

    Returns: 6

  9. "SF"

    Returns: 1

  10. ".S........F"

    Returns: 9

  11. "SF....."

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: