[LeetCode] Count Subarrays With Cost Less Than or Equal to K

3835. Count Subarrays With Cost Less Than or Equal to K

You are given an integer array nums, and an integer k.

For any subarray nums[l..r], define its cost as:

cost = (max(nums[l..r]) - min(nums[l..r])) * (r - l + 1).

Return an integer denoting the number of subarrays of nums whose cost is less than or equal to k.

Read more
[LeetCode] Maximum Score Using Exactly K Pairs

3836. Maximum Score Using Exactly K Pairs

You are given two integer arrays nums1 and nums2 of lengths n and m respectively, and an integer k.

You must choose exactly k pairs of indices (i_1, j_1), (i_2, j_2), ..., (i_k, j_k) such that:

  • 0 <= i_1 < i_2 < ... < i_k < n
  • 0 <= j_1 < j_2 < ... < j_k < m

For each chosen pair (i, j), you gain a score of nums1[i] * nums2[j].

The total score is the sum of the products of all selected pairs.

Return an integer representing the maximum achievable total score.

Read more
[LeetCode] Merge Adjacent Equal Elements

3834. Merge Adjacent Equal Elements

You are given an integer array nums.

You must repeatedly apply the following merge operation until no more changes can be made:

  • If any two adjacent elements are equal, choose the leftmost such adjacent pair in the current array and replace them with a single element equal to their sum.

After each merge operation, the array size decreases by 1. Repeat the process on the updated array until no more changes can be made.

Return the final array after all possible merge operations.

Read more
[LeetCode] Weighted Word Mapping

3838. Weighted Word Mapping

You are given an array of strings words, where each string represents a word containing lowercase English letters.

You are also given an integer array weights of length 26, where weights[i] represents the weight of the i^th lowercase English letter.

The weight of a word is defined as the sum of the weights of its characters.

For each word, take its weight modulo 26 and map the result to a lowercase English letter using reverse alphabetical order (0 -> 'z', 1 -> 'y', ..., 25 -> 'a').

Return a string formed by concatenating the mapped characters for all words in order.

Read more
[LeetCode] Count Monobit Integers

3827. Count Monobit Integers

You are given an integer n.

An integer is called Monobit if all bits in its binary representation are the same.

Return the count of Monobit integers in the range [0, n] (inclusive).

Read more
[LeetCode] Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND

3825. Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND

You are given an integer array nums.

Return the length of the longest strictly increasing subsequence in nums whose bitwise AND is non-zero. If no such subsequence exists, return 0.

Read more
[LeetCode] Minimum K to Reduce Array Within Limit

3824. Minimum K to Reduce Array Within Limit

You are given a positive integer array nums.

For a positive integer k, define nonPositive(nums, k) as the minimum number of operations needed to make every element of nums non-positive. In one operation, you can choose an index i and reduce nums[i] by k.

Return an integer denoting the minimum value of k such that nonPositive(nums, k) <= k^2.

Read more
[LeetCode] Minimum Partition Score

3826. Minimum Partition Score

You are given an integer array nums and an integer k.

Your task is to partition nums into exactly k subarrays and return an integer denoting the minimum possible score among all valid partitions.

The score of a partition is the sum of the values of all its subarrays.

The value of a subarray is defined as sumArr * (sumArr + 1) / 2, where sumArr is the sum of its elements.

Read more
[LeetCode] House Robber V

3840. House Robber V

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed and is protected by a security system with a color code.

You are given two integer arrays nums and colors, both of length n, where nums[i] is the amount of money in the i^th house and colors[i] is the color code of that house.

You cannot rob two adjacent houses if they share the same color code.

Return the maximum amount of money you can rob.

Read more
[LeetCode] Number of Prefix Connected Groups

3839. Number of Prefix Connected Groups

You are given an array of strings words and an integer k.

Two words a and b at distinct indices are prefix-connected if a[0..k-1] == b[0..k-1].

A connected group is a set of words such that each pair of words is prefix-connected.

Return the number of connected groups that contain at least two words, formed from the given words.

Note:

  • Words with length less than k cannot join any group and are ignored.
  • Duplicate strings are treated as separate words.
Read more