Interview Question

Software Engineer Interview



Find if a word can be constructed from the dictionary

AnswerAdd Tags

Interview Answers

3 Answers


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

Anonymous on


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


LeetCode Problem 139. Word Break

Anonymous on

Add Answers or Comments

To comment on this, Sign In or Sign Up.