Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.
If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original.
Given an input string s, reverse the order of the words.
A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.
Return a string of the words in reverse order concatenated by a single space.
Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.
Example 1:
1 2
Input: s = "the sky is blue" Output: "blue is sky the"
The Knuth-Morris-Pratt algorithm is a string searching algorithm. It efficiently finds occurrences of a “pattern” string within a longer “text” string. Unlike some other string search algorithms like the naive or brute-force method, KMP avoids unnecessary comparisons by utilizing information about the pattern itself.