[LeetCode] Number of Alternating XOR Partitions

3811. Number of Alternating XOR Partitions

You are given an integer array nums and two distinct integers target1 and target2.

A partition of nums splits it into one or more contiguous, non-empty blocks that cover the entire array without overlap.

A partition is valid if the bitwise XOR of elements in its blocks alternates between target1 and target2, starting with target1.

Formally, for blocks b1, b2, …:

  • XOR(b1) = target1
  • XOR(b2) = target2 (if it exists)
  • XOR(b3) = target1, and so on.

Return the number of valid partitions of nums, modulo 10^9 + 7.

Note: A single block is valid if its XOR equals target1.

Read more
[LeetCode] Vowel-Consonant Score

3813. Vowel-Consonant Score

You are given a string s consisting of lowercase English letters, spaces, and digits.

Let v be the number of vowels in s and c be the number of consonants in s.

A vowel is one of the letters 'a', 'e', 'i', 'o', or 'u', while any other letter in the English alphabet is considered a consonant.

The score of the string s is defined as follows:

  • If c > 0, the score = floor(v / c) where floor denotes rounding down to the nearest integer.
  • Otherwise, the score = 0.

Return an integer denoting the score of the string.

Read more
[LeetCode] Design Auction System

3815. Design Auction System

You are asked to design an auction system that manages bids from multiple users in real time.

Each bid is associated with a userId, an itemId, and a bidAmount.

Implement the AuctionSystem class:​​​​​​​

  • AuctionSystem(): Initializes the AuctionSystem object.
  • void addBid(int userId, int itemId, int bidAmount): Adds a new bid for itemId by userId with bidAmount. If the same userId already has a bid on itemId, replace it with the new bidAmount.
  • void updateBid(int userId, int itemId, int newAmount): Updates the existing bid of userId for itemId to newAmount. It is guaranteed that this bid exists.
  • void removeBid(int userId, int itemId): Removes the bid of userId for itemId. It is guaranteed that this bid exists.
  • int getHighestBidder(int itemId): Returns the userId of the highest bidder for itemId. If multiple users have the same highest bidAmount, return the user with the highest userId. If no bids exist for the item, return -1.
Read more
[LeetCode] Lexicographically Smallest String After Deleting Duplicate Characters

3816. Lexicographically Smallest String After Deleting Duplicate Characters

You are given a string s that consists of lowercase English letters.

You can perform the following operation any number of times (possibly zero times):

  • Choose any letter that appears at least twice in the current string s and delete any one occurrence.

Return the lexicographically smallest resulting string that can be formed this way.

Read more
[LeetCode] Maximum Capacity Within Budget

3814. Maximum Capacity Within Budget

You are given two integer arrays costs and capacity, both of length n, where costs[i] represents the purchase cost of the i^th machine and capacity[i] represents its performance capacity.

You are also given an integer budget.

You may select at most two distinct machines such that the total cost of the selected machines is strictly less than budget.

Return the maximum achievable total capacity of the selected machines.

Read more
[LeetCode] Minimum Prefix Removal to Make Array Strictly Increasing

3818. Minimum Prefix Removal to Make Array Strictly Increasing

You are given an integer array nums.

You need to remove exactly one prefix (possibly empty) from nums.

Return an integer denoting the minimum length of the removed prefix such that the remaining array is strictly increasing.

Read more
[LeetCode] Find Nth Smallest Integer With K One Bits

3821. Find Nth Smallest Integer With K One Bits

You are given two positive integers n and k.

Return an integer denoting the n^th smallest positive integer that has exactly k ones in its binary representation. It is guaranteed that the answer is strictly less than 2^50.

Read more
[LeetCode] Pythagorean Distance Nodes in a Tree

3820. Pythagorean Distance Nodes in a Tree

You are given an integer n and an undirected tree with n nodes numbered from 0 to n - 1. The tree is represented by a 2D array edges of length n - 1, where edges[i] = [u_i, v_i] indicates an undirected edge between u_i and v_i.

You are also given three distinct target nodes x, y, and z.

For any node u in the tree:

  • Let dx be the distance from u to node x
  • Let dy be the distance from u to node y
  • Let dz be the distance from u to node z

The node u is called special if the three distances form a Pythagorean Triplet.

Return an integer denoting the number of special nodes in the tree.

A Pythagorean triplet consists of three integers a, b, and c which, when sorted in ascending order, satisfy a^2 + b^2 = c^2.

The distance between two nodes in a tree is the number of edges on the unique path between them.

Read more
[LeetCode] Reverse Letters Then Special Characters in a String

3823. Reverse Letters Then Special Characters in a String

You are given a string s consisting of lowercase English letters and special characters.

Your task is to perform these in order:

  • Reverse the lowercase letters and place them back into the positions originally occupied by letters.
  • Reverse the special characters and place them back into the positions originally occupied by special characters.

Return the resulting string after performing the reversals.

Read more
[LeetCode] Rotate Non Negative Elements

3819. Rotate Non Negative Elements

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

Rotate only the non-negative elements of the array to the left by k positions, in a cyclic manner.

All negative elements must stay in their original positions and must not move.

After rotation, place the non-negative elements back into the array in the new order, filling only the positions that originally contained non-negative values and skipping all negative positions.

Return the resulting array.

Read more