Skip to main content
Back to problems
Codeforces
Easy
Arrays
Strings
Snow Footprints

Find the two endpoints of the occupied segment on a snowy path by analyzing footprints.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Snow Footprints

A snowy path contains a sequence of positions. Some positions have footprints, and some do not. The footprints belong to a single person who walked across a continuous segment of the path, leaving footprints on the cells they stepped on.

Your task is to determine the two ends of that occupied segment: the first and last positions that contain footprints. In other words, identify the leftmost and rightmost footprint positions.

This is a straightforward observation and scanning problem: inspect the path, locate the first footprint, then locate the last footprint.

Input Format

  • The first line contains an integer nn — the length of the path.
  • The second line contains a string of length nn consisting of characters representing snowy cells and footprint cells.

Output Format

  • Output two integers: the indices of the first and last footprint positions.
  • Indices should be reported using the problem's indexing convention.

Constraints

  • 1n1051 \le n \le 10^5
  • The string contains at least one footprint cell.

Hints

  • A single pass from left to right can find the first footprint.
  • A single pass from right to left can find the last footprint.

Input Format

  • Read nn.
  • Read a string of length nn describing the path.
  • Footprint cells are the only cells that matter for the answer.

Output Format

  • Print the indices of the first and last footprint cells, separated by a space.

Constraints

  • 1n1051 \le n \le 10^5
  • The input string has length nn.
  • At least one cell is marked as a footprint.
Examples
Sample cases returned by the problem API.

Example 1

Input

8
..##....

Output

3 4

Explanation

The footprint segment starts at position 3 and ends at position 4.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.