The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers
xandy, return the Hamming distance between them.
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers
xandy, return the Hamming distance between them.
3154. Find Number of Ways to Reach the K-th Stair
You are given a non-negative integer
k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0.Alice has an integer
jump, with an initial value of 0. She starts on stair 1 and wants to reach stairkusing any number of operations. If she is on stairi, in one operation she can:
- Go down to stair
i - 1. This operation cannot be used consecutively or on stair 0.- Go up to stair
i + 2jump. And then,jumpbecomesjump + 1.Return the total number of ways Alice can reach stair
k.Note that it is possible that Alice reaches the stair
k, and performs some operations to reach the stairkagain.
3153. Sum of Digit Differences of All Pairs
You are given an array
numsconsisting of positive integers where all integers have the same number of digits.The digit difference between two integers is the count of different digits that are in the same position in the two integers.
Return the sum of the digit differences between all pairs of integers in
nums.
An array is considered special if every pair of its adjacent elements contains two numbers with different parity.
You are given an array of integer
numsand a 2D integer matrixqueries, where forqueries[i] = [fromi, toi]your task is to check that subarraynums[fromi..toi]is special or not.Return an array of booleans
answersuch thatanswer[i]istrueifnums[fromi..toi]is special.
An array is considered special if every pair of its adjacent elements contains two numbers with different parity.
You are given an array of integers
nums. Returntrueifnumsis a special array, otherwise, returnfalse.
1742. Maximum Number of Balls in a Box
You are working in a ball factory where you have
nballs numbered fromlowLimitup tohighLimitinclusive (i.e.,n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from1toinfinity.Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball’s number. For example, the ball number
321will be put in the box number3 + 2 + 1 = 6and the ball number10will be put in the box number1 + 0 = 1.Given two integers
lowLimitandhighLimit, return the number of balls in the box with the most balls.
Given an integer array
arr, returntrueif there are three consecutive odd numbers in the array. Otherwise, returnfalse.
2423. Remove Letter To Equalize Frequency
You are given a 0-indexed string
word, consisting of lowercase English letters. You need to select one index and remove the letter at that index fromwordso that the frequency of every letter present inwordis equal.Return
trueif it is possible to remove one letter so that the frequency of all letters inwordare equal, andfalseotherwise.Note:
- The frequency of a letter
xis the number of times it occurs in the string.- You must remove exactly one letter and cannot choose to do nothing.
3151. Maximum Number of Upgradable Servers
You have
ndata centers and need to upgrade their servers.You are given four arrays
count,upgrade,sell, andmoneyof lengthn, which show:
- The number of servers
- The cost of upgrading a single server
- The money you get by selling a server
- The money you initially have
for each data center respectively.
Return an array
answer, where for each data center, the corresponding element inanswerrepresents the maximum number of servers that can be upgraded.Note that the money from one data center cannot be used for another data center.
1708. Largest Subarray Length K
An array
Ais larger than some arrayBif for the first indexiwhereA[i] != B[i],A[i] > B[i].For example, consider
0-indexing:
[1,3,2,4] > [1,2,2,4], since at index1,3 > 2.[1,4,4,4] < [2,1,1,1], since at index0,1 < 2.A subarray is a contiguous subsequence of the array.
Given an integer array
numsof distinct integers, return the largest subarray ofnumsof lengthk.