`{"id":"a38f484a-42d0-468d-8f6b-9b971c57f685","name":"Z Algorithm For Pattern Searching","description":"1. You are given two strings s1 and s2.\r\n2. s1 represents a text and s2 represents a pattern. \r\n3. You have to print the starting index for all occurrences of the pattern in the given text string.","inputFormat":"Two strings s1 and s2 in two different lines.","outputFormat":"Starting index for all occurrences of the pattern in the given text string.","constraints":"1 &lt;= length of the strings &lt;= 10^4","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void solution(String txt, String pat) {\r\n // write your code here\r\n\r\n }\r\n \r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String s1 = scn.nextLine();\r\n String s2 = scn.nextLine();\r\n solution(s1, s2);\r\n System.out.println();\r\n\t}\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"abab\r\nab","sampleOutput":"0\r\n2\r\n","questionVideo":"https://www.youtube.com/embed/QlwzsWs0oyc","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"a2073e25-96a1-4875-b400-f40bbe2edd95","name":"Text Processing For Experts","slug":"text-processing-for-experts-859","type":0},{"id":"0f1ba7c1-21bb-41ca-bf5f-6868b1670046","name":"Z Algorithm For Pattern Searching","slug":"z-algorithm-for-pattern-searching","type":1}],"next":{"id":"4d156fb0-c2a3-4503-9fee-4c666d62cc6f","name":"Find String Roots","type":1,"slug":"find-string-roots"},"prev":{"id":"3b0de180-8222-4a11-8dca-116ef481da5a","name":"Kmp Pattern Searching","type":1,"slug":"kmp-pattern-searching"}}}`

Z Algorithm For Pattern Searching

1. You are given two strings s1 and s2. 2. s1 represents a text and s2 represents a pattern. 3. You have to print the starting index for all occurrences of the pattern in the given text string.

`{"id":"a38f484a-42d0-468d-8f6b-9b971c57f685","name":"Z Algorithm For Pattern Searching","description":"1. You are given two strings s1 and s2.\r\n2. s1 represents a text and s2 represents a pattern. \r\n3. You have to print the starting index for all occurrences of the pattern in the given text string.","inputFormat":"Two strings s1 and s2 in two different lines.","outputFormat":"Starting index for all occurrences of the pattern in the given text string.","constraints":"1 &lt;= length of the strings &lt;= 10^4","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void solution(String txt, String pat) {\r\n // write your code here\r\n\r\n }\r\n \r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String s1 = scn.nextLine();\r\n String s2 = scn.nextLine();\r\n solution(s1, s2);\r\n System.out.println();\r\n\t}\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"abab\r\nab","sampleOutput":"0\r\n2\r\n","questionVideo":"https://www.youtube.com/embed/QlwzsWs0oyc","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"a2073e25-96a1-4875-b400-f40bbe2edd95","name":"Text Processing For Experts","slug":"text-processing-for-experts-859","type":0},{"id":"0f1ba7c1-21bb-41ca-bf5f-6868b1670046","name":"Z Algorithm For Pattern Searching","slug":"z-algorithm-for-pattern-searching","type":1}],"next":{"id":"4d156fb0-c2a3-4503-9fee-4c666d62cc6f","name":"Find String Roots","type":1,"slug":"find-string-roots"},"prev":{"id":"3b0de180-8222-4a11-8dca-116ef481da5a","name":"Kmp Pattern Searching","type":1,"slug":"kmp-pattern-searching"}}}`

Editor

Z Algorithm For Pattern Searching

hard

1. You are given two strings s1 and s2. 2. s1 represents a text and s2 represents a pattern. 3. You have to print the starting index for all occurrences of the pattern in the given text string.

Constraints

1 <= length of the strings <= 10^4

Format

Input

Two strings s1 and s2 in two different lines.

Output

Starting index for all occurrences of the pattern in the given text string.

Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}abab ab```

Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}0 2 ```

Question Video

Discussions

Show Discussion

Related Resources