3104. Find Longest Self-Contained Substring
Given a string
s
, your task is to find the length of the longest self-contained substring ofs
.A substring
t
of a strings
is called self-contained ift != s
and for every character int
, it doesn’t exist in the rest ofs
.Return the length of the longest self-contained substring of
s
if it exists, otherwise, return -1.
3094. Guess the Number Using Bitwise Questions II
There is a number
n
between0
and230 - 1
(both inclusive) that you have to find.There is a pre-defined API
int commonBits(int num)
that helps you with your mission. But here is the challenge, every time you call this function,n
changes in some way. But keep in mind, that you have to find the initial value ofn
.
commonBits(int num)
acts as follows:
- Calculate
count
which is the number of bits where bothn
andnum
have the same value in that position of their binary representation.n = n XOR num
- Return
count
.Return the number
n
.Note: In this world, all numbers are between
0
and230 - 1
(both inclusive), thus for counting common bits, we see only the first 30 bits of those numbers.
3088. Make String Anti-palindrome
We call a string
s
of even lengthn
an anti-palindrome if for each index0 <= i < n
,s[i] != s[n - i - 1]
.Given a string
s
, your task is to makes
an anti-palindrome by doing any number of operations (including zero).In one operation, you can select two characters from
s
and swap them.Return the resulting string. If multiple strings meet the conditions, return the lexicographically smallest one. If it can’t be made into an anti-palindrome, return
"-1"
.
3078. Match Alphanumerical Pattern in Matrix I
You are given a 2D integer matrix
board
and a 2D character matrixpattern
. Where0 <= board[r][c] <= 9
and each element ofpattern
is either a digit or a lowercase English letter.Your task is to find a submatrix of
board
that matchespattern
.An integer matrix
part
matchespattern
if we can replace cells containing letters inpattern
with some digits (each distinct letter with a unique digit) in such a way that the resulting matrix becomes identical to the integer matrixpart
. In other words,
The matrices have identical dimensions.
If
pattern[r][c]
is a digit, thenpart[r][c]
must be the same digit.If
1 pattern[r][c]is a letter
1 x:
- For every
pattern[i][j] == x
,part[i][j]
must be the same aspart[r][c]
.- For every
pattern[i][j] != x
,part[i][j]
must be different thanpart[r][c]
.Return an array of length
2
containing the row number and column number of the upper-left corner of a submatrix ofboard
which matchespattern
. If there is more than one such submatrix, return the coordinates of the submatrix with the lowest row index, and in case there is still a tie, return the coordinates of the submatrix with the lowest column index. If there are no suitable answers, return[-1, -1]
.
3073. Maximum Increasing Triplet Value
Given an array
nums
, return the maximum value of a triplet(i, j, k)
such thati < j < k
andnums[i] < nums[j] < nums[k]
.The value of a triplet
(i, j, k)
isnums[i] - nums[j] + nums[k]
.
3037. Find Pattern in Infinite Stream II
You are given a binary array
pattern
and an objectstream
of classInfiniteStream
representing a 0-indexed infinite stream of bits.The class
InfiniteStream
contains the following function:
int next()
: Reads a single bit (which is either0
or1
) from the stream and returns it.Return the first starting index where the pattern matches the bits read from the stream. For example, if the pattern is
[1, 0]
, the first match is the highlighted part in the stream[0, **1, 0**, 1, ...]
.
2073. Time Needed to Buy Tickets
There are
n
people in a line queuing to buy tickets, where the0th
person is at the front of the line and the(n - 1)th
person is at the back of the line.You are given a 0-indexed integer array
tickets
of lengthn
where the number of tickets that theith
person would like to buy istickets[i]
.Each person takes exactly 1 second to buy a ticket. A person can only buy 1 ticket at a time and has to go back to the end of the line (which happens instantaneously) in order to buy more tickets. If a person does not have any tickets left to buy, the person will leave the line.
Return the time taken for the person at position
k
(0-indexed)\ to finish buying tickets.
3108. Minimum Cost Walk in Weighted Graph
There is an undirected weighted graph with
n
vertices labeled from0
ton - 1
.You are given the integer
n
and an arrayedges
, whereedges[i] = [ui, vi, wi]
indicates that there is an edge between verticesui
andvi
with a weight ofwi
.A walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that comes before it and the vertex that comes after it. It’s important to note that a walk may visit the same edge or vertex more than once.
The cost of a walk starting at node
u
and ending at nodev
is defined as the bitwiseAND
of the weights of the edges traversed during the walk. In other words, if the sequence of edge weights encountered during the walk isw0, w1, w2, ..., wk
, then the cost is calculated asw0 & w1 & w2 & ... & wk
, where&
denotes the bitwiseAND
operator.You are also given a 2D array
query
, wherequery[i] = [si, ti]
. For each query, you need to find the minimum cost of the walk starting at vertexsi
and ending at vertexti
. If there exists no such walk, the answer is-1
.Return the array
answer
, whereanswer[i]
denotes the minimum cost of a walk for queryi
.
3107. Minimum Operations to Make Median of Array Equal to K
You are given an integer array
nums
and a non-negative integerk
. In one operation, you can increase or decrease any element by 1.Return the minimum number of operations needed to make the median of
nums
equal tok
.The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.