Question
Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words.
Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words.
For example, consider the following dictionary: { pear, salmon, foot, prints, footprints, leave, you, sun, girl, enjoy },
Examples:
Given the string youenjoy,
Output: True (The string can be segmented as you enjoy)
Input: youleavefootprints,
Output: True (The string can be segmented as you leave footprints or you leave foot prints)
Input:salmonenjoyapples
Output: False
c++
comment code
optimize code for best running time
write algorithm you used with words
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started