NAJPF - Pattern Find

Your task is so simple given a string and a pattern. You find the pattern on the given string. If found print how many time found the pattern and their index. Otherwise print ‘Not Found’


The input   line consists of a number T (1 ≤ T ≤ 50) test cases.

For each case given two string number  A,B. the string and the pattern  1 ≤|A|, |B| ≤10^6

All character will be lower case Latin character.  And |  | is the length of string.


For each case print the number  (found pattern from the given string) next line there position And Otherwise print 'Not Found' without quota.
There will a blank line between two cases.




ababab ab
aaaaa bbb
aafafaasf aaf

1 3 5

Not Found





Here all index is 1 base.

hide comments
pumpkinduke: 2019-11-14 18:27:48

Guys beware of giving the space between cost me many WA -___-

fardin_abir: 2019-10-31 08:09:37

ac with kmp in .16 s

tpriyanshu: 2019-10-15 03:02:07

If you are doing rabin-karp, and getting TLE, make sure you take care of the case when hash becomes -ve. Simply add mod to it.

magetron: 2019-09-08 14:32:08

test case is rather weak, submiited a wrong solution and got accepted
test case :
aabaaabaaac aabaaac

mostafa_haamed: 2019-08-21 21:43:00

ac from first hit using z algorithm

copperium: 2019-08-12 05:39:32

"Not Found" has both words capitalized, cost me 2 WA

sagar_june97p: 2019-08-08 16:36:44

Handle the case when pattern.length > string.length. Cost me 1 RTE.

toan_truong95: 2019-08-03 04:47:02

using go, KMP and Rabin Karp got TLE

Last edit: 2019-08-03 04:47:46
cyber_ghost002: 2019-06-30 23:17:01

applies kmp algo got ac with time 0.18

aniketsanghi: 2019-05-31 13:18:13

With Z algo in 0.2 secs

Added by:Najmuzzaman
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU