[LeetCode] Maximum Subarray Sum After Multiplier

3976. Maximum Subarray Sum After Multiplier

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

You must choose exactly one subarray of nums and perform exactly one of the following operations:

  • Multiply each number in the chosen subarray by k.
  • Divide each number in the chosen subarray by k.
    • When dividing a positive number by k, use the floor value of the division result.
    • When dividing a negative number by k, use the ceiling value of the division result.

Return the maximum possible sum of a non-empty subarray in the resulting array.

Note that the subarray chosen for the operation and the subarray chosen for the sum may be different.

Read more
[LeetCode] Minimum Time to Reach Target With Limited Power

3977. Minimum Time to Reach Target With Limited Power

You are given a directed weighted graph with n nodes labeled from 0 to n - 1.

The graph is represented by a 2D integer array edges, where edges[i] = [u_i, v_i, t_i] indicates a directed edge from node u_i to node v_i that takes t_i seconds to traverse.

You are also given an integer power representing the initial available power, and an integer array cost of length n, where cost[u] represents the power required to forward the signal from node u through any one of its outgoing edges.

You are given two integers source and target.

The signal starts at source at time 0 with power units of power and follows these rules:

  • The signal may traverse a directed edge from node u only if the remaining power is at least cost[u].
  • No power is consumed when the signal arrives at a node, unless it later leaves that node by traversing another edge.
  • When the signal is forwarded from node u, the remaining power is decreased by cost[u] units.
  • Traversing an edge edges[i] = [u_i, v_i, t_i] increases the total time by t_i seconds.

Return an integer array answer of size 2, where:

  • answer[0] is the minimum time required for the signal to reach node target.
  • answer[1] is the maximum remaining power among all paths that achieve answer[0].

If the signal cannot reach target, return [-1, -1].

Read more
[LeetCode] Unique Middle Element

3978. Unique Middle Element

You are given an integer array nums of odd length n.

Return true if the middle element of nums appears exactly once in the array. Otherwise return false.

Read more
[LeetCode] Maximum Valid Pair Sum

3979. Maximum Valid Pair Sum

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

A pair of indices (i, j) is called valid if:

  • 0 <= i < j < n
  • j - i >= k

Return the maximum value of nums[i] + nums[j] among all valid pairs.

Read more
[LeetCode] Minimum Operations to Transform Binary String

3980. Minimum Operations to Transform Binary String

You are given two binary strings s1 and s2 of the same length n.

You can perform the following operations on s1 any number of times, in any order:

  • Choose an index i such that s1[i] == '0', and change it to '1'.
  • Choose an index i such that 0 <= i < n - 1, and both s1[i] and s1[i + 1] are '1'. Change both characters to '0'.

Return the minimum number of operations required to make s1 equal to s2. If it is impossible, return -1.

Read more
[LeetCode] Count Distinct Ways to Form Target from Two Strings

3981. Count Distinct Ways to Form Target from Two Strings

You are given three strings word1, word2, and target.

Your task is to count the number of ways to form target by choosing characters from word1 and word2 under the following conditions:

  • For each character of target, choose one matching character from either word1 or word2.
  • The chosen indices from word1 must be strictly increasing.
  • The chosen indices from word2 must be strictly increasing.
  • At least one character must be chosen from both word1 and word2.

Two ways are considered different if, for at least one position in target, the chosen character comes from a different string or a different index.

Return the number of ways. Since the answer may be very large, return it modulo 10^9 + 7.

Read more
[LeetCode] Sum of Integers with Maximum Digit Range

3982. Sum of Integers with Maximum Digit Range

You are given an integer array nums.

The digit range of an integer is defined as the difference between its largest digit and smallest digit.

For example, the digit range of 5724 is 7 - 2 = 5.

Return the sum of all integers in nums whose digit range is equal to the maximum digit range among all integers in the array.

Read more
[LeetCode] Subsequence After One Replacement

3983. Subsequence After One Replacement

You are given two strings s and t consisting of lowercase English letters.

You may choose at most one index in s and replace the character at that index with any lowercase English letter.

Return true if it is possible to make s a subsequence of t; otherwise, return false.

Read more
[LeetCode] Divisible Game

3984. Divisible Game

You are given an integer array nums of length n.

Alice and Bob are playing a game. Alice chooses:

  • An integer k such that k > 1.
  • Two integers l and r such that 0 <= l <= r < n.

Initially, both Alice’s and Bob’s scores are 0.

For each index i in the range [l, r] (inclusive):

  • If nums[i] is divisible by k, Alice’s score increases by nums[i].
  • Otherwise, Bob’s score increases by nums[i].

The score difference is Alice’s score minus Bob’s score.

Alice wants to maximize the score difference. If there are multiple values of k that achieve the maximum score difference, she chooses the smallest such k.

Return the product of the maximum score difference and the chosen value of k. Since the result can be large, return it modulo 10^9 + 7.

Read more
[LeetCode] Palindromic Subarray Sum

3985. Palindromic Subarray Sum

You are given an integer array nums.

Return the maximum possible sum of a subarray of nums that is a palindrome.

Read more