Dsa
Dynamic Programming
Hard
String Segmentation
You are given a string and a dictionary of words. Write a program to determine if the string can be segmented into a space-separated sequence of one or more dictionary words using dynamic programming.
Input:
- The first line contains the string 's'.
- The second line contains an integer n, the number of words in the dictionary.
- The next n lines each contain one word from the dictionary.
Output:
- Print 'true' if the string can be segmented; otherwise, print 'false'.
Example:
Input:
leetcodex
3
leet
code
x
Output:
false
Key concepts
dynamic_programmingstrings
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now