#K48952. Vinyl Records Genre Analysis

    ID: 28534 Type: Default 1000ms 256MiB

Vinyl Records Genre Analysis

Vinyl Records Genre Analysis

You are given a collection of vinyl records arranged on a shelf. Each record is associated with a genre represented by a lowercase English letter. Your task is to identify the genre that appears most frequently on the shelf and output its first and last positions (1-indexed). If more than one genre has the same highest frequency, output the lexicographically smallest genre.

Problem Details:

  • Let \( n \) be the number of records on the shelf.
  • Let \( s \) be a string of length \( n \), where each character represents the genre of a record.
  • You must determine the genre with the maximum frequency and then find its first and last occurrence positions.
  • If multiple genres share the same maximum frequency, choose the one that comes first in lexicographical order.

For example, if \( n=7 \) and \( s=\texttt{abbacca} \), the output should be "a 1 7" since genre 'a' occurs 3 times with first position 1 and last position 7.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  1. The first line contains an integer \( n \), the number of vinyl records.
  2. The second line contains a string \( s \) of length \( n \) consisting of lowercase English letters, where each letter represents the genre of a record.

outputFormat

Output a single line to standard output (stdout) containing three values separated by spaces:

  • The most frequent genre.
  • The 1-indexed position of its first occurrence.
  • The 1-indexed position of its last occurrence.
## sample
7
abbacca
a 1 7