package leetcode;

import java.util.List;

/**
 * https://leetcode.com/problems/search-suggestions-system/
 */
public class Problem1268 {
    public List<List<String>> suggestedProducts(String[] products, String searchWord) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1268 prob = new Problem1268();
        // [["mobile","moneypot","monitor"],
        //  ["mobile","moneypot","monitor"],
        //  ["mouse","mousepad"],
        //  ["mouse","mousepad"],
        //  ["mouse","mousepad"]]
        System.out.println(prob.suggestedProducts(
            new String[]{"mobile","mouse","moneypot","monitor","mousepad"}, "mouse"));
        System.out.println(prob.suggestedProducts(
            new String[]{"havana"}, "havana")); // [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]
        System.out.println(prob.suggestedProducts(
            new String[]{"bags","baggage","banner","box","cloths"}, "bags")); // [["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]
        System.out.println(prob.suggestedProducts(
            new String[]{"havana"}, "tatiana")); // [[],[],[],[],[],[],[]]
    }
}

@@ -231,35 +231,965 @@
     
-// TODO%0A        return null
+Node root = new Node(' ');%0A        for (String product : products) %7B%0A            root = build(root, product, 0);%0A        %7D%0A        return null;%0A    %7D%0A%0A    private static class Node %7B%0A        private final char c;%0A        private final Node%5B%5D children = new Node%5B26%5D;%0A        private boolean isWord;%0A%0A        private Node(char c) %7B%0A            this.c = c;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return %22%22 + c;%0A        %7D%0A    %7D%0A%0A    private static Node build(Node node, String product, int index) %7B%0A        if (index == product.length()) %7B%0A            return node;%0A        %7D%0A        char c = product.charAt(index);%0A        Node child = node.children%5Bc - 'a'%5D;%0A        if (child == null) %7B%0A            child = new Node(c);%0A        %7D%0A        node.children%5Bc - 'a'%5D = build(child, product, index + 1);%0A        if (index == product.length() - 1) %7B%0A            node.children%5Bc - 'a'%5D.isWord = true;%0A        %7D%0A        return node
 ;%0A  
@@ -1614,16 +1614,18 @@
 use%22));%0A
+//
         
@@ -1659,32 +1659,34 @@
 gestedProducts(%0A
+//
             new 
@@ -1784,24 +1784,26 @@
 %5B%22havana%22%5D%5D%0A
+//
         Syst
@@ -1833,32 +1833,34 @@
 gestedProducts(%0A
+//
             new 
@@ -2006,24 +2006,26 @@
 %5D,%5B%22bags%22%5D%5D%0A
+//
         Syst
@@ -2055,32 +2055,34 @@
 gestedProducts(%0A
+//
             new 

Update problem 1268