Resource Library

Below you can find all of the different resources in the Guide: practice problems, former Google interview questions, online courses, videos, and more.

Back to all resources
  • Former interview question: find longest word

    Hone your problem-solving skills with this former Google interview question where you'll need to find the longest word in a dictionary that is a subsequence of a given string.

    Mark as complete Save for later
  • Given a string S and a set of words D, find the longest word in D that is a subsequence of S.

    Word W is a subsequence of S if some number of characters, possibly zero, can be deleted from S to form W, without reordering the remaining characters.

    Note: D can appear in any format (list, hash table, prefix tree, etc.

    For example, given the input of S = "abppplee" and D = {"able", "ale", "apple", "bale", "kangaroo"} the correct output would be "apple"

  • The words "able" and "ale" are both subsequences of S, but they are shorter than "apple".
  • The word "bale" is not a subsequence of S because even though S has all the right letters, they are not in the right order.
  • The word "kangaroo" is the longest word in D, but it isn't a subsequence of S.
  • Learning objectives

    This question gives you the chance to practice with algorithms and data structures. It’s also a good example of why careful analysis for Big-O performance is often worthwhile, as is careful exploration of common and worst-case input conditions.