Sliding window is one common trick used in coding, which may not be counted as one "algorithm" by itself. Nevertheless, this trick is popular in tech code interviews, perhaps due to its relative "short" length (?).
The size of the window could be either fixed or non-fixed, depends on the questions.
When the size is non-fixed, two pointers are usually used to maintain the size of the window. Thus, the "two-pointer" method may be considered as a variant of the sliding window trick. The first point stands for the starting side of the "window" and the second one represents the ending side of the "window".
When does the sliding window trick work?
Usually string matching, or sub-array / sub-sequences may be considered to use the sliding window trick. The key point is that the question can be gradually solved by the evolution of the sliding window from the beginning of a string/array to the end.
To sum up, sliding window
1. is a common trick in coding interviews;
2. usually maintains two pointers: one for the left side of the window, the other is the right side of the "window";
Comments
Post a Comment