All Tracks Data Structures Advanced Data Structures Suffix Trees Problem

Power of String
Tag(s):

Hard

Problem
Editorial
Analytics

For a given integer K and a string S of length N, we denote power of S, as the length of a longest substring occurring in S at least K times.

Given K and S, find the power of S.

Constraints:

1 <= N <= 106
1 <= K <= N
S consists of latin lowercase letters only

Input format:

In the first line there are two integers K and N separated by a single space. The second line constains string S itself.

Output format:

In one line, output the power of string S for a given K.

SAMPLE INPUT
2 11
abrakadabra
SAMPLE OUTPUT
4
Explanation

Substring "abra" occurs in S two times and it is the longest substring of all substrings of S occurring at least two times.

Time Limit: 10.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

Code Monk (Tries/Suffix Tree)

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?