3

Both answers basically try all k-length paths and count the number of paths that remain on the board compared to all possible paths. A major difference between your answer and the recursive solution you link to is what is cached (i.e., memoized). You code caches the possible moves from a square. The linked code caches partial solutions. That is, the cache ...


2

Your code does not consider the case when your query string is among the set. You can add that in the search method: public List<String> search(String word) { List<String> results = new ArrayList<>(); TrieNode node = findNode(word, root, 0); if (node == null) { return results; } if(node.isWord) { results....


1

Applied few minor optimisations to the code from the OP's answer. Also fixed naming issues (locals name starts from a lower-cased letter). class Program { static void Main(string[] args) { int t = int.Parse(Console.ReadLine()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t; i++) { int n = ...


1

There is a much faster solution to this problem. If the ending character is Y, two strings can be created. But if the ending character is X, only one valid string can be created: XY. This results in the following equation, complexity O(n): def king_kohima(number: int) -> int: x = [0, 1, 1] y = [0, 1, 2] for i in range(3, number + 1): # Start ...


Only top voted, non community-wiki answers of a minimum length are eligible