Pseudocode Challenge
Challenge: Challenge: Word Segmentation with Minimum Dictionary Lookups

Problem Statement:

You are given a string S of length n, consisting of only lowercase English letters, and a dictionary D of valid English words. The task is to segment the string S into a sequence of words that minimizes the number of dictionary lookups.

For each lookup in the dictionary, you incur a "cost" of 1, regardless of whether the word exists in the dictionary or not.

Objective: Write a pseudocode algorithm to split the string S into a sequence of words from the dictionary such that the number of dictionary lookups is minimized. If the string cannot be segmented into valid words, return -1.

Constraints:

  • The dictionary lookup function, isWord(word), returns True if word is in the dictionary and False otherwise.
  • String S has a maximum length of 1000 characters.
  • The dictionary D contains at most 10,000 words.
Write your pseudocode below