Codeforces Round 659 (Div. 2) B1. Koa and the Beach (Easy Version)
2781. Length of the Longest Valid Substring
You are given a string
wordand an array of stringsforbidden.A string is called valid if none of its substrings are present in
forbidden.Return the length of the longest valid substring of the string
word.A substring is a contiguous sequence of characters in a string, possibly empty.
2780. Minimum Index of a Valid Split
An element
xof an integer arrayarrof lengthmis dominant iffreq(x) * 2 > m, wherefreq(x)is the number of occurrences ofxinarr. Note that this definition implies thatarrcan have at most one dominant element.You are given a 0-indexed integer array
numsof lengthnwith one dominant element.You can split
numsat an indexiinto two arraysnums[0, ..., i]andnums[i + 1, ..., n - 1], but the split is only valid if:
0 <= i < n - 1nums[0, ..., i], andnums[i + 1, ..., n - 1]have the same dominant element.Here,
nums[i, ..., j]denotes the subarray ofnumsstarting at indexiand ending at indexj, both ends being inclusive. Particularly, ifj < ithennums[i, ..., j]denotes an empty subarray.Return the minimum index of a valid split. If no valid split exists, return
-1.
2779. Maximum Beauty of an Array After Applying Operation
You are given a 0-indexed array
numsand a non-negative integerk.In one operation, you can do the following:
- Choose an index
ithat hasn’t been chosen before from the range[0, nums.length - 1].- Replace
nums[i]with any integer from the range[nums[i] - k, nums[i] + k].The beauty of the array is the length of the longest subsequence consisting of equal elements.
Return the maximum possible beauty of the array
numsafter applying the operation any number of times.Note that you can apply the operation to each index only once.
A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.
2778. Sum of Squares of Special Elements
You are given a 1-indexed integer array
numsof lengthn.An element
nums[i]ofnumsis called special ifidividesn, i.e.n % i == 0.Return the sum of the squares of all special elements of
nums.