public static boolean wordBreak(String s, Set<String> dict) {
        boolean[] isWord = new boolean[s.length()+1];


        isWord[0] = true;

        for( int i = 0; i< s.length(); i++) {

            // start from the matching word
            if(!isWord[i]) {
                continue;
            }

            for( String word : dict) {
                int end = i + word.length();

                if(end > s.length()) {
                    continue;
                }

                if(isWord[end]) {
                    continue;
                }

                if(s.substring(i, end).equals(word)) {
                    isWord[end] = true;

                }

            }

        }

        return isWord[s.length()];

    }