bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 524. Longest Word in Dictionary through Deleting

524. Longest Word in Dictionary through Deleting

Leetcode Solutions

Approach: Sorting and Checking Subsequence

  1. Sort the dictionary by the length of the words in descending order. If two words have the same length, sort them lexicographically in ascending order.
  2. Iterate through the sorted dictionary.
  3. For each word in the dictionary, check if it is a subsequence of the given string s.
  4. If a word is a subsequence of s, return it immediately as it is the longest word with the smallest lexicographical order that can be formed.
  5. If no word in the dictionary is a subsequence of s, return an empty string.
UML Thumbnail

Approach: Without Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...