[Codeforces] Round 731 (Div. 3) F. Array Stabilization (GCD version)Read more
[LeetCode] Apply Operations to Make All Array Elements Equal to Zero

2772. Apply Operations to Make All Array Elements Equal to Zero

You are given a 0-indexed integer array nums and a positive integer k.

You can apply the following operation on the array any number of times:

  • Choose any subarray of size k from the array and decrease all its elements by 1.

Return true if you can make all the array elements equal to 0, or false otherwise.

A subarray is a contiguous non-empty part of an array.

Read more
[LeetCode] Longest Non-decreasing Subarray From Two Arrays

2771. Longest Non-decreasing Subarray From Two Arrays

You are given two 0-indexed integer arrays nums1 and nums2 of length n.

Let’s define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].

Your task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.

Return an integer representing the length of the longest non-decreasing subarray in nums3.

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

Read more
[LeetCode] Maximum Number of Jumps to Reach the Last Index

2770. Maximum Number of Jumps to Reach the Last Index

You are given a 0-indexed array nums of n integers and an integer target.

You are initially positioned at index 0. In one step, you can jump from index i to any index j such that:

  • 0 <= i < j < n
  • -target <= nums[j] - nums[i] <= target

Return the maximum number of jumps you can make to reach index n - 1.

If there is no way to reach index n - 1, return -1.

Read more
[LeetCode] Find the Maximum Achievable Number

2769. Find the Maximum Achievable Number

You are given two integers, num and t.

An integer x is called achievable if it can become equal to num after applying the following operation no more than t times:

  • Increase or decrease x by 1, and simultaneously increase or decrease num by 1.

Return the maximum possible achievable number. It can be proven that there exists at least one achievable number.

Read more
[Codeforces] Round 740 (Div. 1, based on VK Cup 2021 - Final (Engine)) B. Up the StripRead more
[Codeforces] Round 739 (Div. 3) F2. Nearest Beautiful Number (hard version)Read more
[Codeforces] Round 739 (Div. 3) F1. Nearest Beautiful Number (easy version)Read more
[LeetCode] Number of Black Blocks

2768. Number of Black Blocks

You are given two integers m and n representing the dimensions of a 0-indexed m x n grid.

You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.

A block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].

Return a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i *black cells*.

Read more
[LeetCode] Partition String Into Minimum Beautiful Substrings

2767. Partition String Into Minimum Beautiful Substrings

Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.

A string is beautiful if:

  • It doesn’t contain leading zeros.
  • It’s the binary representation of a number that is a power of 5.

Return the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings, return -1.

A substring is a contiguous sequence of characters in a string.

Read more