SECPASS - Editorial

Maybe…

  1. unordered_map
  2. use s.substr instead of pushing every element…

We have exactly same solution XD

I replaced my function of KMP algorithm for pattern searching with yours and it got accepted!

https://www.codechef.com/viewsolution/23141256

Boy I want to get my hands dirty with your resources XD.

XDD how !! I thought we both copied it from gfg…

I have size of LPS=M and you have NN

shouldn’t it be O(|s| * log(|s|)) ?

Yes it should be… Typo… Thanks…

Try to search it on google

O(|S|*log(|S|)) * T must be tight for the time limit.

I think, I had to just break the loop in case of a mismatch, rather just removing those occurances

True @shoom

Sad, I got TLE for Hashing+Binary Search :frowning:

Seems true wow.

Basically there is no point to consider prefixes where the first letter appears more than once. Such prefix occurs fewer times that a single-letter prefix, so it can’t be a candidate for the answer.
For example the prefix ‘abca’ appears fewer times than the prefix ‘a’.

In Z algo you create a Z array where each index stores the largest substring starting at i and is also a prefix
Now cosider the string “abcabcabc”
Here the z array looks like this : 0 0 0 6 0 0 3 0 0
In the above array 6 denotes the substring “abcabc” which is also the prefix and 3 denotes the substring “abc” which is also the prefix
Now if you look carefully, in the substring you “abcabc” you are getting one time occurence of the prefixes : “a”, “ab”, “abc”,“abca”,“abcab”,“abcabc”. Similarly in the case of “abc”.

So you can keep an array where each index i denotes the occurence of the prefix of length i. So for each non-zero element(say z[i]) in the z-array you update all the elements between the range 1 to z[i] of the frequency array index by adding 1 to them. This will give you an array containing the frequency of all the prefixes. Then you check for the element with largest frequency and for a tie, check for the largest element

This is my solution in pypy3 : CodeChef: Practical coding for everyone

let our string be abcdeabcf. On first scan, our k is a as our answer is currently a. Then on 2nd scan, k becomes 2 as answer becomes 2 and later on k becomes 3 when answer is 3. So K is length of our answer at any instance.

Here it is…
https://www.codechef.com/viewsolution/23190005

here is the link of my python solution
getting tle again and again please somebody help me out