Longest Word in Dictionary Through Deleting Problem

Longest Word in Dictionary Through Deleting Problem — ExecCode Easy DSA Practice

Solve the Longest Word in Dictionary Through Deleting problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. Your task is to if there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.

Examples

Input {"s": "", "dictionary": ["a", "b", "c"]}; Output . Input {"s": "a", "dictionary": ["b", "c", "d"]}; Output . Input {"s": "zcfzdb", "dictionary": ["a", "b", "c"]}; Output b

Constraints

1 <= s.length <= 1000 1 <= dictionary.length <= 1000 1 <= dictionary[i].length <= 1000 s and dictionary[i] consist of lowercase English letters.

Practice Longest Word in Dictionary Through Deleting free on ExecCode. Browse DSA problems, topic map, and placement guides.