{"id":"eb8338da-d0fe-4d3c-85a5-81df609232b7","name":"Longest Word In Dictionary Through Deleting","description":"1.Given a string and a string dictionary.\r\n 2.Find the longest string in the dictionary that can be formed by deleting some characters of the given string.\r\n 3.You have to complete the function findLongestWord() that should return a string.\r\n 4.If there are more than one possible results, return the longest word with the smallest lexicographical order.\r\n 5.If there is no possible result, return the empty string.","inputFormat":"1.First line contains a string.\r\n 2.Second line contains an Integer 'N'.\r\n 3.Third line contains N separated strings.","outputFormat":"Return a string","constraints":"1.String will contains lowercase characters only.\r\n 2.1&lt;=N&lt;=1000","sampleCode":{"cpp":{"code":"#include<iostream>\r\n #include<vector>\r\n using namespace std;\r\n \r\n string findLongestWord(string &s, vector<string> &d) {\r\n // Write your code here\r\n }\r\n \r\n int main(int argc, char** argv){\r\n vector<string> list;\r\n string str;\r\n cin>>str;\r\n int n;\r\n cin>>n;\r\n \t for (int i = 0; i < n; i++) {\r\n \t \t string s;\r\n cin>>s;\r\n \t \t list.push_back(s);\r\n \t }\r\n \t cout<<findLongestWord(str, list)<<endl;\r\n }"},"java":{"code":"import java.util.ArrayList;\r\n import java.util.Scanner;\r\n \r\n public class Main {\r\n \r\n \t public static String findLongestWord(String s, ArrayList<String> d) {\r\n \t //Write your code here\t \t \r\n \r\n \r\n \t }\r\n \r\n \t \r\n \r\n \t public static void main(String[] args) {\r\n \t \t ArrayList<String> list = new ArrayList<>();\r\n \t \t Scanner s = new Scanner(System.in);\r\n \t \t String str = s.next();\r\n \t \t int n = s.nextInt();\r\n \t \t for (int i = 0; i < n; i++) {\r\n \t \t \t String string=s.next();\r\n \t \t \t list.add(string);\r\n \t \t }\r\n \t \t System.out.println(findLongestWord(str, list));\r\n \r\n \t }\r\n \r\n }"}},"points":10,"difficulty":"easy","sampleInput":"abpcplea\n4\nale\napple\nmonkey\nplea","sampleOutput":"apple","questionVideo":null,"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":"4b4725b5-4896-4b68-aae2-03ea1e2ecbb2","name":"Trie For Intermediate","slug":"trie-for-intermediate-9996","type":0},{"id":"c2079e60-a16a-40bd-8f5e-8d66904d148a","name":"Longest Word In Dictionary MCQ","slug":"longest-word-in-dictionary-mcq","type":0},{"id":"1d449d94-30d0-44a9-9d88-765d5a80af32","name":"Longest Word In Dictionary Through Deleting","slug":"longest-word-in-dictionary-through-deleting","type":1}],"next":null,"prev":{"id":"43ca4b73-ef5f-4857-b1cc-52bb516ff312","name":"Longest Word In Dictionary","type":1,"slug":"longest-word-in-dictionary"}}}

Longest Word In Dictionary Through Deleting

1.Given a string and a string dictionary. 2.Find the longest string in the dictionary that can be formed by deleting some characters of the given string. 3.You have to complete the function findLongestWord() that should return a string. 4.If there are more than one possible results, return the longest word with the smallest lexicographical order. 5.If there is no possible result, return the empty string.

{"id":"eb8338da-d0fe-4d3c-85a5-81df609232b7","name":"Longest Word In Dictionary Through Deleting","description":"1.Given a string and a string dictionary.\r\n 2.Find the longest string in the dictionary that can be formed by deleting some characters of the given string.\r\n 3.You have to complete the function findLongestWord() that should return a string.\r\n 4.If there are more than one possible results, return the longest word with the smallest lexicographical order.\r\n 5.If there is no possible result, return the empty string.","inputFormat":"1.First line contains a string.\r\n 2.Second line contains an Integer 'N'.\r\n 3.Third line contains N separated strings.","outputFormat":"Return a string","constraints":"1.String will contains lowercase characters only.\r\n 2.1&lt;=N&lt;=1000","sampleCode":{"cpp":{"code":"#include<iostream>\r\n #include<vector>\r\n using namespace std;\r\n \r\n string findLongestWord(string &s, vector<string> &d) {\r\n // Write your code here\r\n }\r\n \r\n int main(int argc, char** argv){\r\n vector<string> list;\r\n string str;\r\n cin>>str;\r\n int n;\r\n cin>>n;\r\n \t for (int i = 0; i < n; i++) {\r\n \t \t string s;\r\n cin>>s;\r\n \t \t list.push_back(s);\r\n \t }\r\n \t cout<<findLongestWord(str, list)<<endl;\r\n }"},"java":{"code":"import java.util.ArrayList;\r\n import java.util.Scanner;\r\n \r\n public class Main {\r\n \r\n \t public static String findLongestWord(String s, ArrayList<String> d) {\r\n \t //Write your code here\t \t \r\n \r\n \r\n \t }\r\n \r\n \t \r\n \r\n \t public static void main(String[] args) {\r\n \t \t ArrayList<String> list = new ArrayList<>();\r\n \t \t Scanner s = new Scanner(System.in);\r\n \t \t String str = s.next();\r\n \t \t int n = s.nextInt();\r\n \t \t for (int i = 0; i < n; i++) {\r\n \t \t \t String string=s.next();\r\n \t \t \t list.add(string);\r\n \t \t }\r\n \t \t System.out.println(findLongestWord(str, list));\r\n \r\n \t }\r\n \r\n }"}},"points":10,"difficulty":"easy","sampleInput":"abpcplea\n4\nale\napple\nmonkey\nplea","sampleOutput":"apple","questionVideo":null,"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":"4b4725b5-4896-4b68-aae2-03ea1e2ecbb2","name":"Trie For Intermediate","slug":"trie-for-intermediate-9996","type":0},{"id":"c2079e60-a16a-40bd-8f5e-8d66904d148a","name":"Longest Word In Dictionary MCQ","slug":"longest-word-in-dictionary-mcq","type":0},{"id":"1d449d94-30d0-44a9-9d88-765d5a80af32","name":"Longest Word In Dictionary Through Deleting","slug":"longest-word-in-dictionary-through-deleting","type":1}],"next":null,"prev":{"id":"43ca4b73-ef5f-4857-b1cc-52bb516ff312","name":"Longest Word In Dictionary","type":1,"slug":"longest-word-in-dictionary"}}}
plane

Editor


Loading...

Longest Word In Dictionary Through Deleting

easy

1.Given a string and a string dictionary. 2.Find the longest string in the dictionary that can be formed by deleting some characters of the given string. 3.You have to complete the function findLongestWord() that should return a string. 4.If there are more than one possible results, return the longest word with the smallest lexicographical order. 5.If there is no possible result, return the empty string.

Constraints

1.String will contains lowercase characters only. 2.1<=N<=1000

Format

Input

1.First line contains a string. 2.Second line contains an Integer 'N'. 3.Third line contains N separated strings.

Output

Return a string

Example

Sample Input

abpcplea 4 ale apple monkey plea

Sample Output

apple

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode