#524
Longest Word in Dictionary through Deleting
specialist · 850 · lc medium +31 · verified · 52.6% accepted · 1,863 likes · top 43%
Description
Given a string s and an array dictionary, find the longest word in dictionary that is a subsequence of s (formed by deleting some characters from s without reordering). If multiple words tie for the longest length, return the one that comes first lexicographically. Return an empty string if no match exists.
Example 1:
Input: s = "abpcplea", dictionary = ["ale","apple","monkey","plea"]
Output: "apple"
Example 2:
Input: s = "abpcplea", dictionary = ["a","b","c"]
Output: "a"
Code
1
2
3