2842. Count K-Subsequences of a String With Maximum Beauty
You are given a string
sand an integerk.A k-subsequence is a subsequence of
s, having lengthk, and all its characters are unique, i.e., every character occurs once.Let
f(c)denote the number of times the charactercoccurs ins.The beauty of a k-subsequence is the sum of
f(c)for every charactercin the k-subsequence.For example, consider
s = "abbbdd"andk = 2:
f('a') = 1,f('b') = 3,f('d') = 2Some k-subsequences of
1 sare:
"**ab**bbdd"->"ab"having a beauty off('a') + f('b') = 4"**a**bbb**d**d"->"ad"having a beauty off('a') + f('d') = 3"a**b**bb**d**d"->"bd"having a beauty off('b') + f('d') = 5Return an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo
109 + 7.A subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.
Notes
f(c)is the number of times a charactercoccurs ins, not a k-subsequence.- Two k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.
2841. Maximum Sum of Almost Unique Subarray
You are given an integer array
numsand two positive integersmandk.Return the maximum sum out of all almost unique subarrays of length
kofnums. If no such subarray exists, return0.A subarray of
numsis almost unique if it contains at leastmpairwise distinct elements.A subarray is a contiguous non-empty sequence of elements within an array.
2840. Check if Strings Can be Made Equal With Operations II
You are given two strings
s1ands2, both of lengthn, consisting of lowercase English letters.You can apply the following operation on any of the two strings any number of times:
- Choose any two indices
iandjsuch thati < jand the differencej - iis even, then swap the two characters at those indices in the string.Return
trueif you can make the stringss1ands2equal, andfalseotherwise.
2839. Check if Strings Can be Made Equal With Operations I
You are given two strings
s1ands2, both of length4, consisting of lowercase English letters.You can apply the following operation on any of the two strings any number of times:
- Choose any two indices
iandjsuch thatj - i = 2, then swap the two characters at those indices in the string.Return
trueif you can make the stringss1ands2equal, andfalseotherwise.