[LeetCode] Minimum Absolute Distance Between Mirror Pairs

3761. Minimum Absolute Distance Between Mirror Pairs

You are given an integer array nums.

A mirror pair is a pair of indices (i, j) such that:

  • 0 <= i < j < nums.length, and
  • reverse(nums[i]) == nums[j], where reverse(x) denotes the integer formed by reversing the digits of x. Leading zeros are omitted after reversing, for example reverse(120) = 21.

Return the minimum absolute distance between the indices of any mirror pair. The absolute distance between indices i and j is abs(i - j).

If no mirror pair exists, return -1.

Read more
[LeetCode] Minimum Operations to Equalize Subarrays

3762. Minimum Operations to Equalize Subarrays

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

In one operation, you can increase or decreaseany element of nums by exactly k.

You are also given a 2D integer array queries, where each queries[i] = [l_i, r_i].

For each query, find the minimum number of operations required to make all elements in the subarray nums[l_i..r_i] equal. If it is impossible, the answer for that query is -1.

Return an array ans, where ans[i] is the answer for the i^th query.

Read more
[LeetCode] Maximize Points After Choosing K Tasks

3767. Maximize Points After Choosing K Tasks

You are given two integer arrays, technique1 and technique2, each of length n, where n represents the number of tasks to complete.

  • If the i^th task is completed using technique 1, you earn technique1[i] points.
  • If it is completed using technique 2, you earn technique2[i] points.

You are also given an integer k, representing the minimum number of tasks that must be completed using technique 1.

You must complete at least k tasks using technique 1 (they do not need to be the first k tasks).

The remaining tasks may be completed using either technique.

Return an integer denoting the maximum total points you can earn.

Read more
[LeetCode] Minimum Inversion Count in Subarrays of Fixed Length

3768. Minimum Inversion Count in Subarrays of Fixed Length

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

An inversion is a pair of indices (i, j) from nums such that i < j and nums[i] > nums[j].

The inversion count of a subarray is the number of inversions within it.

Return the minimum inversion count among all subarrays of nums with length k.

Read more
[LeetCode] Minimum Operations to Make Binary Palindrome

3766. Minimum Operations to Make Binary Palindrome

You are given an integer array nums.

For each element nums[i], you may perform the following operations any number of times (including zero):

  • Increase nums[i] by 1, or
  • Decrease nums[i] by 1.

A number is called a binary palindrome if its binary representation without leading zeros reads the same forward and backward.

Your task is to return an integer array ans, where ans[i] represents the minimum number of operations required to convert nums[i] into a binary palindrome.

Read more
[LeetCode] Sort Integers by Binary Reflection

3769. Sort Integers by Binary Reflection

You are given an integer array nums.

The binary reflection of a positive integer is defined as the number obtained by reversing the order of its binary digits (ignoring any leading zeros) and interpreting the resulting binary number as a decimal.

Sort the array in ascending order based on the binary reflection of each element. If two different numbers have the same binary reflection, the smaller original number should appear first.

Return the resulting sorted array.

Read more
[LeetCode] Absolute Difference Between Maximum and Minimum K Elements

3774. Absolute Difference Between Maximum and Minimum K Elements

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

Find the absolute difference between:

  • the sum of the k largest elements in the array; and
  • the sum of the k smallest elements in the array.

Return an integer denoting this difference.

Read more
[LeetCode] Largest Prime from Consecutive Prime Sum

3770. Largest Prime from Consecutive Prime Sum

You are given an integer n.

Return the largest prime number less than or equal to n that can be expressed as the sum of one or more consecutive prime numbers starting from 2. If no such number exists, return 0.

Read more
[LeetCode] Maximum Subgraph Score in a Tree

3772. Maximum Subgraph Score in a Tree

You are given an undirected tree with n nodes, numbered from 0 to n - 1. It is represented by a 2D integer array edges​​​​​​​ of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.

You are also given an integer array good of length n, where good[i] is 1 if the i^th node is good, and 0 if it is bad.

Define the score of a subgraph as the number of good nodes minus the number of bad nodes in that subgraph.

For each node i, find the maximum possible score among all connected subgraphs that contain node i.

Return an array of n integers where the i^th element is the maximum score for node i.

A subgraph is a graph whose vertices and edges are subsets of the original graph.

A connected subgraph is a subgraph in which every pair of its vertices is reachable from one another using only its edges.

Read more
[LeetCode] Total Score of Dungeon Runs

3771. Total Score of Dungeon Runs

You are given a positive integer hp and two positive 1-indexed integer arrays damage and requirement.

There is a dungeon with n trap rooms numbered from 1 to n. Entering room i reduces your health points by damage[i]. After that reduction, if your remaining health points are at least requirement[i], you earn 1 pointfor that room.

Let score(j) be the number of points you get if you start with hp health points and enter the rooms j, j + 1, …, n in this order.

Return the integer score(1) + score(2) + ... + score(n), the sum of scores over all starting rooms.

Note: You cannot skip rooms. You can finish your journey even if your health points become non-positive.

Read more