438. Find All Anagrams in a String

438. Find All Anagrams in a String Given two strings s and p, return an array of all the start indices of p’s anagrams in s. You may return the answer in any order. Example 1: Input: s = "cbaebabacd", p = "abc" Output: [0,6] Explanation: The substring with start index = 0 is "cba", which is an anagram of "abc". The substring with start index = 6 is "bac", which is an anagram of "abc". Example 2: Input: s = "abab", p = "ab" Output: [0,1,2] Explanation: The substring with start index = 0 is "ab", which is an anagram of "ab". The substring with start index = 1 is "ba", which is an anagram of "ab". The substring with start index = 2 is "ab", which is an anagram of "ab". Constraints: ...

May 11, 2021 · 2 min · volyx

1208. Get Equal Substrings Within Budget

1208. Get Equal Substrings Within Budget You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of twith a cost less than or equal to maxCost. ...

May 10, 2021 · 2 min · volyx

443. String Compression

1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold Given an array of integers arr and two integers k and threshold. Return the number of sub-arrays of size k and average greater than or equal to threshold. Example 1: Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4 Output: 3 Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold). Example 2: Input: arr = [1,1,1,1,1], k = 1, threshold = 0 Output: 5 Example 3: Input: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5 Output: 6 Explanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers. Example 4: Input: arr = [7,7,7,7,7,7,7], k = 7, threshold = 7 Output: 1 Example 5: Input: arr = [4,4,4,4], k = 4, threshold = 1 Output: 1 Constraints: ...

May 10, 2021 · 2 min · volyx

443. String Compression

443. String Compression Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: If the group’s length is 1, append the character to s. Otherwise, append the character followed by the group’s length. The compressed string s should not be returned separately, but instead be stored in the input character array chars. Note that group lengths that are 10 or longer will be split into multiple characters in chars. ...

May 10, 2021 · 2 min · volyx