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), returnsTrueifwordis in the dictionary andFalseotherwise. - String
Shas a maximum length of 1000 characters. - The dictionary
Dcontains at most 10,000 words.