{"id":"0320014d-d669-4bb6-9c3e-bd7c8250aeed","name":"Longest Repeating Subsequence","description":"1. You are given a string str.\r\n2. You have to find the length of longest subsequence which is appearing twice in the string.\r\n3. Every ith character in both the subsequences must have different indices in the original string. ","inputFormat":"A string str","outputFormat":"A number representing the length of longest repeating subsequence.","constraints":"1 < length of strings str <= 2000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str){\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"abcdgh","sampleOutput":"0\r\n","questionVideo":"https://www.youtube.com/embed/oL7GCrcdaJI?end=111","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"8f8ce41a-6baf-4736-83d1-c8b9c9fed804","name":"Longest Repeating Subsequence","slug":"longest-repeating-subsequence","type":1}],"next":{"id":"9eeb6e55-cd5d-4d02-8f91-c0e553014c70","name":"Longest repeating Subsequence MCQ","type":0,"slug":"longest-repeating-subsequence-mcq"},"prev":{"id":"7e637a1d-760d-445e-92a2-663264fbf2e8","name":"LONGEST COMMON SUBSTRING","type":3,"slug":"longest-common-substring"}}}

Longest Repeating Subsequence

1. You are given a string str. 2. You have to find the length of longest subsequence which is appearing twice in the string. 3. Every ith character in both the subsequences must have different indices in the original string.

{"id":"0320014d-d669-4bb6-9c3e-bd7c8250aeed","name":"Longest Repeating Subsequence","description":"1. You are given a string str.\r\n2. You have to find the length of longest subsequence which is appearing twice in the string.\r\n3. Every ith character in both the subsequences must have different indices in the original string. ","inputFormat":"A string str","outputFormat":"A number representing the length of longest repeating subsequence.","constraints":"1 < length of strings str <= 2000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str){\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"abcdgh","sampleOutput":"0\r\n","questionVideo":"https://www.youtube.com/embed/oL7GCrcdaJI?end=111","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"8f8ce41a-6baf-4736-83d1-c8b9c9fed804","name":"Longest Repeating Subsequence","slug":"longest-repeating-subsequence","type":1}],"next":{"id":"9eeb6e55-cd5d-4d02-8f91-c0e553014c70","name":"Longest repeating Subsequence MCQ","type":0,"slug":"longest-repeating-subsequence-mcq"},"prev":{"id":"7e637a1d-760d-445e-92a2-663264fbf2e8","name":"LONGEST COMMON SUBSTRING","type":3,"slug":"longest-common-substring"}}}
plane

Editor


Loading...

Longest Repeating Subsequence

medium

1. You are given a string str. 2. You have to find the length of longest subsequence which is appearing twice in the string. 3. Every ith character in both the subsequences must have different indices in the original string.

Constraints

1 < length of strings str <= 2000

Format

Input

A string str

Output

A number representing the length of longest repeating subsequence.

Example

Sample Input

abcdgh

Sample Output

0

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode