[Codeforces] Round 214 (Div. 2) C. Dima and SaladRead more
[Codeforces] Round 215 (Div. 1) B. Sereja ans AnagramsRead more
[Codeforces] Round 220 (Div. 2) C. Inna and DimaRead more
[LeetCode] Count K-Subsequences of a String With Maximum Beauty

2842. Count K-Subsequences of a String With Maximum Beauty

You are given a string s and an integer k.

A k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.

Let f(c) denote the number of times the character c occurs in s.

The beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.

For example, consider s = "abbbdd" and k = 2:

  • f('a') = 1, f('b') = 3, f('d') = 2

  • Some k-subsequences of

1
s

are:

  • "**ab**bbdd" -> "ab" having a beauty of f('a') + f('b') = 4
  • "**a**bbb**d**d" -> "ad" having a beauty of f('a') + f('d') = 3
  • "a**b**bb**d**d" -> "bd" having a beauty of f('b') + f('d') = 5

Return 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 character c occurs in s, 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.
Read more
[LeetCode] Maximum Sum of Almost Unique Subarray

2841. Maximum Sum of Almost Unique Subarray

You are given an integer array nums and two positive integers m and k.

Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.

A subarray of nums is almost unique if it contains at least m pairwise distinct elements.

A subarray is a contiguous non-empty sequence of elements within an array.

Read more
[LeetCode] Check if Strings Can be Made Equal With Operations II

2840. Check if Strings Can be Made Equal With Operations II

You are given two strings s1 and s2, both of length n, 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 i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.

Return true if you can make the strings s1 and s2 equal, and false otherwise.

Read more
[LeetCode] Check if Strings Can be Made Equal With Operations I

2839. Check if Strings Can be Made Equal With Operations I

You are given two strings s1 and s2, both of length 4, 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 i and j such that j - i = 2, then swap the two characters at those indices in the string.

Return true if you can make the strings s1 and s2 equal, and false otherwise.

Read more
[Codeforces] Round 222 (Div. 1) B. Preparing for the ContestRead more
[Codeforces] Round 228 (Div. 1) B. Fox and Minimal pathRead more
[Codeforces] Round 237 (Div. 2) D. Minesweeper 1DRead more