[Codeforces] Educational Round 161 (Rated for Div. 2) D. Berserk MonstersRead more
[LeetCode] Count Substrings That Satisfy K-Constraint II

3261. Count Substrings That Satisfy K-Constraint II

You are given a binary string s and an integer k.

You are also given a 2D integer array queries, where queries[i] = [li, ri].

A binary string satisfies the k-constraint if either of the following conditions holds:

  • The number of 0‘s in the string is at most k.
  • The number of 1‘s in the string is at most k.

Return an integer array answer, where answer[i] is the number of substrings of s[li..ri] that satisfy the k-constraint.

Read more
[LeetCode] Find the Largest Palindrome Divisible by K

3260. Find the Largest Palindrome Divisible by K

You are given two positive integers n and k.

An integer x is called k-palindromic if:

  • x is a palindrome.

  • x is divisible by k.

Return the largest integer having n digits (as a string) that is k-palindromic.

Note that the integer must not have leading zeros.

Read more
[LeetCode] Maximum Energy Boost From Two Drinks

3259. Maximum Energy Boost From Two Drinks

You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.

You want to maximize your total energy boost by drinking one energy drink per hour. However, if you want to switch from consuming one energy drink to the other, you need to wait for one hour to cleanse your system (meaning you won’t get any energy boost in that hour).

Return the maximum total energy boost you can gain in the next n hours.

Note that you can start consuming either of the two energy drinks.

Read more
[LeetCode] Count Substrings That Satisfy K-Constraint I

3258. Count Substrings That Satisfy K-Constraint I

You are given a binary string s and an integer k.

A binary string satisfies the k-constraint if either of the following conditions holds:

  • The number of 0‘s in the string is at most k.
  • The number of 1‘s in the string is at most k.

Return an integer denoting the number of substrings of s that satisfy the k-constraint.

Read more
[Codeforces] Codeforces Round 920 (Div. 3) F. Sum of ProgressionRead more
[Codeforces] Codeforces Round 919 (Div. 2) D. Array RepetitionRead more
[LeetCode] Maximum Value Sum by Placing Three Rooks II

3257. Maximum Value Sum by Placing Three Rooks II

You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).

Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.

Return the maximum sum of the cell values on which the rooks are placed.

Read more
[LeetCode] Maximum Value Sum by Placing Three Rooks I

3256. Maximum Value Sum by Placing Three Rooks I

You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).

Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.

Return the maximum sum of the cell values on which the rooks are placed.

Read more
[LeetCode] Find the Power of K-Size Subarrays II

3255. Find the Power of K-Size Subarrays II

You are given an array of integers nums of length n and a positive integer k.

The power of an array is defined as:

  • Its maximum element if all of its elements are consecutive and sorted in ascending order.
  • -1 otherwise.

You need to find the power of all subarrays of nums of size k.

Return an integer array results of size n - k + 1, where results[i] is the power of nums[i..(i + k - 1)].

Read more