Using trie tree and z-algorithm to find prefix and suffix.
To solve the problem, we can use a combination of BFS and backtracking.
To merge k sorted linked lists efficiently, we can use a Min Heap data structure.
To find the maximum path sum in a binary tree, we can use a recursive approach. The idea is to traverse the tree in a bottom-up manner and calculate the maximum path sum for each node.
Because all the words are the same length, we can use hash map to check for substring from index i to index i +word length * words number.
We can calculate the water amount by columns. For position i, the water it can contains is based on the left max height column and the right max height columns.
This problem can be see as finding peak and valley. And we need to start checking the peak in order to remove the redundant count.
We can get the n pairs of parentheses by combining the x pairs with n-1-x pairs then combine with one pair "()".
Solve using three ways.
Use two pointers, let them always have a distance of n, so when right pointer reach the end, the left pointer is the last nth node.
Using DFS method to check each possible remove.
Every natural number can be represented as a sum of four non-negative integer squares. That is, the squares form an additive basis of order four