Hello, everyone! Today, I have solved three problems on LeetCode: "Find All Anagrams in a String," "Longest Consecutive Sequence," and "Search in Rotated Sorted Array." They are really interesting, and we have different logical approaches to solve them. They are extensions of the classic problems of checking if two strings are anagrams and searching for a target element in an array.
Find All Anagrams in a String We can solve the problem by using sliding window technique. In the given input array, we have to iterate over that while tracking the fixed-length consecutive elements of that array. Then, we check whether this segment is an anagram of the target string or not. If it is an anagram, then we add the index to the result array. Otherwise we didn't keep an eye on that index. That's how we're able to come up with the solution of that problem.
Longest Consecutive Sequence: To solve this problem we first eradicate duplicates in the array using a set. Then we pass the array and check in that whether there exists some sequences in consecutive elements(+1 or -1). If any exists then we keep upgrading that count otherwise we would simply ignore it.
Search in Rotated Sorted Array: We can use a simple technique of binary search to solve this problem. First, we divide the given input array into two subarrays. Then find the half which is sorted in natural order and then begin binary search on that array as well to find a specified element. If the specified number could not be found, it returns -1 from our function. In that manner we can solve a given problem.
Top comments (0)