{"id":"2438122a-c623-4153-baa5-a368eb41b692","name":"Shortest Uncommon Subsequence","description":"1. You are given two strings S1 and S2.\r\n2. You have to find length of the shortest subsequence in S1 which is not a subsequence in S2. \r\n3. If no such subsequence exists, then print '-1'.","inputFormat":"Two Strings S1 and S2","outputFormat":"A number representing the length of shortest uncommon subsequence.","constraints":"1 <= length of strings S1 and S2 <= 1000","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 s1, String s2) {\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 s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(solution(s1, s2));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"sea\r\naessa","sampleOutput":"2\r\n","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"60dc2753-727b-498d-8ff6-8fa1d2c7f4f8","name":"Shortest Uncommon Subsequence","slug":"shortest-uncommon-subsequence","type":1}],"next":{"id":"b4299fd7-c23e-4326-bdae-18a972fedc52","name":"Kadane's Algorithm","type":1,"slug":"kadane-s-algorithm"},"prev":{"id":"10913b45-92c0-4a99-a5c2-770122f4db29","name":"Minimum Cost To Make Two Strings Identical","type":3,"slug":"minimum-cost-to-make-two-strings-identical"}}}

Shortest Uncommon Subsequence

1. You are given two strings S1 and S2. 2. You have to find length of the shortest subsequence in S1 which is not a subsequence in S2. 3. If no such subsequence exists, then print '-1'.

{"id":"2438122a-c623-4153-baa5-a368eb41b692","name":"Shortest Uncommon Subsequence","description":"1. You are given two strings S1 and S2.\r\n2. You have to find length of the shortest subsequence in S1 which is not a subsequence in S2. \r\n3. If no such subsequence exists, then print '-1'.","inputFormat":"Two Strings S1 and S2","outputFormat":"A number representing the length of shortest uncommon subsequence.","constraints":"1 <= length of strings S1 and S2 <= 1000","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 s1, String s2) {\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 s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(solution(s1, s2));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"sea\r\naessa","sampleOutput":"2\r\n","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"60dc2753-727b-498d-8ff6-8fa1d2c7f4f8","name":"Shortest Uncommon Subsequence","slug":"shortest-uncommon-subsequence","type":1}],"next":{"id":"b4299fd7-c23e-4326-bdae-18a972fedc52","name":"Kadane's Algorithm","type":1,"slug":"kadane-s-algorithm"},"prev":{"id":"10913b45-92c0-4a99-a5c2-770122f4db29","name":"Minimum Cost To Make Two Strings Identical","type":3,"slug":"minimum-cost-to-make-two-strings-identical"}}}
plane

Editor


Loading...

Shortest Uncommon Subsequence

medium

1. You are given two strings S1 and S2. 2. You have to find length of the shortest subsequence in S1 which is not a subsequence in S2. 3. If no such subsequence exists, then print '-1'.

Constraints

1 <= length of strings S1 and S2 <= 1000

Format

Input

Two Strings S1 and S2

Output

A number representing the length of shortest uncommon subsequence.

Example

Sample Input

sea aessa

Sample Output

2

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode