3077. Maximum Strength of K Disjoint Subarrays
You are given a 0-indexed array of integers
nums
of lengthn
, and a positive odd integerk
.The strength of
x
subarrays is defined asstrength = sum[1] * x - sum[2] * (x - 1) + sum[3] * (x - 2) - sum[4] * (x - 3) + ... + sum[x] * 1
wheresum[i]
is the sum of the elements in theith
subarray. Formally, strength is sum of(-1)i+1 * sum[i] * (x - i + 1)
over alli
‘s such that1 <= i <= x
.You need to select
k
disjoint subarrays fromnums
, such that their strength is maximum.Return the maximum possible strength that can be obtained.
Note that the selected subarrays don’t need to cover the entire array.
3076. Shortest Uncommon Substring in an Array
You are given an array
arr
of sizen
consisting of non-empty strings.Find a string array
answer
of sizen
such that:
answer[i]
is the shortest substring ofarr[i]
that does not occur as a substring in any other string inarr
. If multiple such substrings exist,answer[i]
should be the lexicographically smallest. And if no such substring exists,answer[i]
should be an empty string.Return the array
answer
.
3075. Maximize Happiness of Selected Children
You are given an array
happiness
of lengthn
, and a positive integerk
.There are
n
children standing in a queue, where theith
child has happiness valuehappiness[i]
. You want to selectk
children from thesen
children ink
turns.In each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by
1
. Note that the happiness value cannot become negative and gets decremented only if it is positive.Return the maximum sum of the happiness values of the selected children you can achieve by selecting
k
children.
3074. Apple Redistribution into Boxes
You are given an array
apple
of sizen
and an arraycapacity
of sizem
.There are
n
packs where theith
pack containsapple[i]
apples. There arem
boxes as well, and theith
box has a capacity ofcapacity[i]
apples.Return the minimum number of boxes you need to select to redistribute these
n
packs of apples into boxes.Note that, apples from the same pack can be distributed into different boxes.
3064. Guess the Number Using Bitwise Questions I
There is a number
n
that you have to find.There is also a pre-defined API
int commonSetBits(int num)
, which returns the number of bits where bothn
andnum
are1
in that position of their binary representation. In other words, it returns the number of set bits inn & num
, where&
is the bitwiseAND
operator.Return the number
n
.
349. Intersection of Two Arrays
Given two integer arrays
nums1
andnums2
, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.