Codeforces Round 926 (Div. 2) D. Sasha and a Walk in the City
The complement of an integer is the integer you get when you flip all the
0
‘s to1
‘s and all the1
‘s to0
‘s in its binary representation.
- For example, The integer
5
is"101"
in binary and its complement is"010"
which is the integer2
.Given an integer
num
, return its complement.
3261. Count Substrings That Satisfy K-Constraint II
You are given a binary string
s
and an integerk
.You are also given a 2D integer array
queries
, wherequeries[i] = [li, ri]
.A binary string satisfies the k-constraint if either of the following conditions holds:
- The number of
0
‘s in the string is at mostk
.- The number of
1
‘s in the string is at mostk
.Return an integer array
answer
, whereanswer[i]
is the number of substrings ofs[li..ri]
that satisfy the k-constraint.
3260. Find the Largest Palindrome Divisible by K
You are given two positive integers
n
andk
.An integer
x
is called k-palindromic if:
x
is a palindrome.
x
is divisible byk
.Return the largest integer having
n
digits (as a string) that is k-palindromic.Note that the integer must not have leading zeros.
3259. Maximum Energy Boost From Two Drinks
You are given two integer arrays
energyDrinkA
andenergyDrinkB
of the same lengthn
by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.You want to maximize your total energy boost by drinking one energy drink per hour. However, if you want to switch from consuming one energy drink to the other, you need to wait for one hour to cleanse your system (meaning you won’t get any energy boost in that hour).
Return the maximum total energy boost you can gain in the next
n
hours.Note that you can start consuming either of the two energy drinks.