Interview Question

Software Engineer Interview

-Singapore

Meta

Find if a word can be constructed from the dictionary

AnswerAdd Tags

Interview Answers

3 Answers

1

Non optimally, but laid out all possible solutions + complexities.

Anonymous on

0

public boolean wordBreak(String s, List wordDict) { Set dict = new HashSet(wordDict); boolean[] f = new boolean[s.length() + 1]; f[0] = true; for(int i=1; i <= s.length(); i++){ for(int j=0; j < i; j++){ if(f[j] && dict.contains(s.substring(j, i))){ f[i] = true; break; } } } return f[s.length()]; }

Anonymous on

0

LeetCode Problem 139. Word Break

Anonymous on

Add Answers or Comments

To comment on this, Sign In or Sign Up.