We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Bear and Steady Gene

Bear and Steady Gene

Problem
Submissions
Leaderboard
Discussions
Editorial

A gene is represented as a string of length (where is divisible by ), composed of the letters , , , and . It is considered to be steady if each of the four letters occurs exactly times. For example, and are both steady genes.

Bear Limak is a famous biotechnology scientist who specializes in modifying bear DNA to make it steady. Right now, he is examining a gene represented as a string . It is not necessarily steady. Fortunately, Limak can choose one (maybe empty) substring of and replace it with any string of the same length.

Modifying a large substring of bear genes can be dangerous. Given a string , can you help Limak find the length of the smallest possible substring that he can replace to make a steady gene?

Note: A substring of a string is a subsequence made up of zero or more contiguous characters of .

As an example, consider . The substring just before or after can be replaced with or . One selection would create .

Function Description

Complete the function in the editor below. It should return an integer that represents the length of the smallest substring to replace.

steadyGene has the following parameter:

  • gene: a string

Input Format

The first line contains an interger divisible by , that denotes the length of a string .
The second line contains a string of length .

Constraints

  • is divisible by

Subtask

  • in tests worth points.

Output Format

Print the length of the minimum length substring that can be replaced to make stable.

Sample Input

8  
GAAATAAA

Sample Output

5

Explanation

One optimal solution is to replace with resulting in .
The replaced substring has length .

Author

Errichto

Difficulty

Medium

Max Score

50

Submitted By

27479

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy