[LeetCode] Maximize Fixed Points After Deletions

3920. Maximize Fixed Points After Deletions

You are given an integer array nums.

A position i is called a fixed point if nums[i] == i.

You are allowed to delete any number of elements (including zero) from the array. After each deletion, the remaining elements shift left, and indices are reassigned starting from 0.

Return an integer denoting the maximum number of fixed points that can be achieved after performing any number of deletions.

Read more
[LeetCode] Minimum Cost to Move Between Indices

3919. Minimum Cost to Move Between Indices

You are given an integer array nums where nums is strictly increasing.

For each index x, let closest(x) be the adjacent index y such that abs(nums[x] - nums[y]) is minimized. If both adjacent indices exist and give the same difference, choose the smaller index.

From any index x, you can move in two ways:

  • To any index y with cost abs(nums[x] - nums[y]), or
  • To closest(x) with cost 1.

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

For each query, calculate the minimum total cost to move from index l_i to index r_i.

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

The absolute difference between two values x and y is defined as abs(x - y).

Read more
[LeetCode] Score Validator

3921. Score Validator

You are given a string array events.

Initially, score = 0 and counter = 0. Each element in events is one of the following:

  • "0", "1", "2", "3", "4", "6": Add that value to the total score.
  • "W": Increase the counter by 1. No score is added.
  • "WD": Add 1 to the total score.
  • "NB": Add 1 to the total score.

Process the array from left to right. Stop processing when either:

  • All elements in events have been processed, or
  • The counter becomes 10.

Return an integer array [score, counter], where:

  • score is the final total score.
  • counter is the final counter value.
Read more
[LeetCode] Sum of Primes Between Number and Its Reverse

3918. Sum of Primes Between Number and Its Reverse

You are given an integer n.

Let r be the integer formed by reversing the digits of n.

Return the sum of all prime numbers between min(n, r) and max(n, r), inclusive.

Read more
[LeetCode] Concatenate Array With Reverse

3925. Concatenate Array With Reverse

You are given an integer array nums of length n.

Construct a new array ans of length 2 * n such that the first n elements are the same as nums, and the next n elements are the elements of nums in reverse order.

Formally, for 0 <= i <= n - 1:

  • ans[i] = nums[i]
  • ans[i + n] = nums[n - i - 1]

Return an integer array ans.

Read more
[LeetCode] Minimum Flips to Make Binary String Coherent

3922. Minimum Flips to Make Binary String Coherent

You are given a binary string s.

A string is considered coherent if it does not contain "011" or "110" as subsequences.

In one operation, you can flip any character in s ('0' to '1' or '1' to '0').

Return an integer denoting the minimum number of operations required to make s coherent.

Read more
[LeetCode] Minimum Generations to Target Point

3923. Minimum Generations to Target Point

You are given a 2D integer array points where points[i] = [x_i, y_i, z_i] represents a point in 3D space, and an integer array target representing a target point.

Define generation 0 as the initial list of points. For each integer k >= 1, form generation k as follows:

  • Consider every pair of two distinct points a = [x_1, y_1, z_1] and b = [x_2, y_2, z_2] taken from all points produced in generations 0 through k - 1.
  • For each such pair, compute c = [floor((x_1 + x_2) / 2), floor((y_1 + y_2) / 2), floor((z_1 + z_2) / 2)] and collect every such c into a generation k.
  • All points in the generation k are produced simultaneously from points in generations 0 through​​​​​​​ k - 1.
  • After generation k is formed, the points in the generation k are considered available for forming later generations.

Return the smallest integer k such that the target appears in one of the generations 0 through k. If the target is already in the initial points, return 0. If it is impossible to obtain the target, return -1.

Notes:

  • floor denotes rounding down to the nearest integer.
  • “Two distinct points” means the two chosen points must have different (x, y, z) coordinates. A point cannot be paired with itself, and pairing two points with identical coordinates is not possible.
Read more
[LeetCode] Minimum Threshold Path With Limited Heavy Edges

3924. Minimum Threshold Path With Limited Heavy Edges

There is an undirected weighted graph with n nodes labeled from 0 to n - 1.

The graph is represented by a 2D integer array edges, where each edge edges[i] = [u_i, v_i, w_​​​​​​​i] indicates that there is an undirected edge between nodes u_i and v_i with weight w_​​​​​​​i.

You are also given integers source, target and k.

A threshold value determines whether an edge is considered light or heavy:

  • An edge is light if its weight is less than or equal to threshold.
  • An edge is heavy if its weight is greater than threshold.

A path from source to target is valid if it contains at most k heavy edges.

Return the minimum integerthreshold such that at least one valid path exists from source to target. If no such path exists, return -1.

Read more
[LeetCode] Check Adjacent Digit Differences

3931. Check Adjacent Digit Differences

You are given a string s consisting of digits.

Return true if the absolute difference between every pair of adjacent digits is at most 2, otherwise return false.

The absolute difference between a and b is defined as abs(a - b).

Read more
[LeetCode] Count Valid Word Occurrences

3926. Count Valid Word Occurrences

You are given an array of strings chunks. Concatenate all strings in chunks in order to form a string s.

You are also given an array of strings queries.

A joiner hyphen is a hyphen character '-' in s whose previous and next characters both exist and are lowercase English letters.

A word is a maximal substring of s consisting only of lowercase English letters and joiner hyphens.

All other characters, including spaces and hyphens that are not joiner hyphens, are treated as separators.

Return an integer array ans, where ans[i] is the number of times queries[i] appears as a word in s.

Read more