Logo
Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Word Break (medium)

Problem Statement

Given a non-empty string and a dictionary containing a list of non-empty words, determine if the string can be segmented into a space-separated sequence of one or more dictionary words. Each word in the dictionary can be reused multiple times.

Examples

Example 1:

  • Input:
    • String: "ilovecoding"
    • Dictionary: ["i", "love", "coding"]
  • Expected Output: True
  • Justification: The string can be segmented as "i love coding".

Example 2:

  • Input:
    • String: "helloworld"
    • Dictionary: ["hello", "world", "hell", "low"]
  • Expected Output: True

.....

.....

.....

Like the course? Get enrolled and start learning!