3093. Longest Common Suffix Queries
You are given two arrays of strings
wordsContainer
andwordsQuery
.For each
wordsQuery[i]
, you need to find a string fromwordsContainer
that has the longest common suffix withwordsQuery[i]
. If there are two or more strings inwordsContainer
that share the longest common suffix, find the string that is the smallest in length. If there are two or more such strings that have the same smallest length, find the one that occurred earlier inwordsContainer
.Return an array of integers
ans
, whereans[i]
is the index of the string inwordsContainer
that has the longest common suffix withwordsQuery[i]
.
The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays,
nums
andfreq
, of equal lengthn
. Each element innums
represents an ID, and the corresponding element infreq
indicates how many times that ID should be added to or removed from the collection at each step.
- Addition of IDs: If
freq[i]
is positive, it meansfreq[i]
IDs with the valuenums[i]
are added to the collection at stepi
.- Removal of IDs: If
freq[i]
is negative, it means-freq[i]
IDs with the valuenums[i]
are removed from the collection at stepi
.Return an array
ans
of lengthn
, whereans[i]
represents the count of the most frequent ID in the collection after theith
step. If the collection is empty at any step,ans[i]
should be 0 for that step.
3091. Apply Operations to Make Sum of Array Greater Than or Equal to k
You are given a positive integer
k
. Initially, you have an arraynums = [1]
.You can perform any of the following operations on the array any number of times (possibly zero):
- Choose any element in the array and increase its value by
1
.- Duplicate any element in the array and add it to the end of the array.
Return the minimum number of operations required to make the sum of elements of the final array greater than or equal to
k
.
3090. Maximum Length Substring With Two Occurrences
Given a string
s
, return the maximum length of a substring such that it contains at most two occurrences of each character.