Medium

Quiz

#524 Longest Word in Dictionary through Deleting

APPROACH

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"
1 of 4
1:00

What is the optimal approach for this problem?