{"id":"83a1f43c-8d05-4f4f-84ea-ddd67978056a","name":"Longest Prefix Suffix","description":"Given a string S, print the longest Prefix which is also a suffix.\r\nTry doing it using constant space.","inputFormat":"A string S","outputFormat":"Print the answer, print \"\" (without quotes) if no answer found.","constraints":"2 <= |S| <= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n // Write Code here\r\n scn.close();\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"abcab","sampleOutput":"ab","questionVideo":"","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":"adf48575-67c0-4be1-a34a-54f80390f0a1","name":"Longest Prefix Suffix","slug":"longest-prefix-suffix","type":1}],"next":{"id":"fa634ac6-6b8c-4c11-a927-ba7b57bdb42b","name":"Lexicographical Suffixes","type":1,"slug":"lexicographical-suffixes"},"prev":{"id":"250721e3-8d64-4136-a15b-de0b2e52bd1f","name":"Longest Duplicate Substring","type":1,"slug":"longest-duplicate-substring"}}}

Longest Prefix Suffix

Given a string S, print the longest Prefix which is also a suffix. Try doing it using constant space.

{"id":"83a1f43c-8d05-4f4f-84ea-ddd67978056a","name":"Longest Prefix Suffix","description":"Given a string S, print the longest Prefix which is also a suffix.\r\nTry doing it using constant space.","inputFormat":"A string S","outputFormat":"Print the answer, print \"\" (without quotes) if no answer found.","constraints":"2 <= |S| <= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n // Write Code here\r\n scn.close();\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"abcab","sampleOutput":"ab","questionVideo":"","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":"adf48575-67c0-4be1-a34a-54f80390f0a1","name":"Longest Prefix Suffix","slug":"longest-prefix-suffix","type":1}],"next":{"id":"fa634ac6-6b8c-4c11-a927-ba7b57bdb42b","name":"Lexicographical Suffixes","type":1,"slug":"lexicographical-suffixes"},"prev":{"id":"250721e3-8d64-4136-a15b-de0b2e52bd1f","name":"Longest Duplicate Substring","type":1,"slug":"longest-duplicate-substring"}}}
plane

Editor


Loading...

Longest Prefix Suffix

medium

Given a string S, print the longest Prefix which is also a suffix. Try doing it using constant space.

Constraints

2 <= |S| <= 10^5

Format

Input

A string S

Output

Print the answer, print "" (without quotes) if no answer found.

Example

Sample Input

abcab

Sample Output

ab

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode