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
tof a stringsis called self-contained ift != sand for every character int, it doesn’t exist in the rest ofs.Return the length of the longest self-contained substring of
sif it exists, otherwise, return -1.
3094. Guess the Number Using Bitwise Questions II
There is a number
nbetween0and230 - 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,nchanges in some way. But keep in mind, that you have to find the initial value ofn.
commonBits(int num)acts as follows:
- Calculate
countwhich is the number of bits where bothnandnumhave 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
0and230 - 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
sof even lengthnan anti-palindrome if for each index0 <= i < n,s[i] != s[n - i - 1].Given a string
s, your task is to makesan anti-palindrome by doing any number of operations (including zero).In one operation, you can select two characters from
sand 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
boardand a 2D character matrixpattern. Where0 <= board[r][c] <= 9and each element ofpatternis either a digit or a lowercase English letter.Your task is to find a submatrix of
boardthat matchespattern.An integer matrix
partmatchespatternif we can replace cells containing letters inpatternwith 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
2containing the row number and column number of the upper-left corner of a submatrix ofboardwhich 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 < kandnums[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
patternand an objectstreamof classInfiniteStreamrepresenting a 0-indexed infinite stream of bits.The class
InfiniteStreamcontains the following function:
int next(): Reads a single bit (which is either0or1) 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
npeople in a line queuing to buy tickets, where the0thperson is at the front of the line and the(n - 1)thperson is at the back of the line.You are given a 0-indexed integer array
ticketsof lengthnwhere the number of tickets that theithperson 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
nvertices labeled from0ton - 1.You are given the integer
nand an arrayedges, whereedges[i] = [ui, vi, wi]indicates that there is an edge between verticesuiandviwith 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
uand ending at nodevis defined as the bitwiseANDof 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 bitwiseANDoperator.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 vertexsiand 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
numsand 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
numsequal 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.