Special binary strings are binary strings with the following two properties:
The number of 0’s is equal to the number of 1’s.
Every prefix of the binary string has at least as many 1’s as 0’s.
Given a special string
S, a move consists of choosing two consecutive, non-empty, special substrings of
S, and swapping them. (Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.)
At the end of any number of moves, what is the lexicographically largest resulting string possible?
Shas length at most
Sis guaranteed to be a special binary string as defined above.
We are given a list
schedule of employees, which represents the working time for each employee.
Each employee has a list of non-overlapping
Intervals, and these intervals are in sorted order.
Return the list of finite intervals representing common, positive-length free time for all employees, also in sorted order.
(Even though we are representing
Intervals in the form
[x, y], the objects inside are
Intervals, not lists or arrays. For example,
schedule.start = 1, schedule.end = 2, and
schedule is not defined.)
Also, we wouldn’t include intervals like [5, 5] in our answer, as they have zero length.
schedule[i]are lists with lengths in range
0 <= schedule[i].start < schedule[i].end <= 10^8.
Given a set of keywords
words and a string
S, make all appearances of all keywords in
S bold. Any letters between
</b> tags become bold.
The returned string should use the least number of tags possible, and of course the tags should form a valid combination.
For example, given that
words = ["ab", "bc"] and
S = "aabcd", we should return
"a<b>abc</b>d". Note that returning
"a<b>a<b>b</b>c</b>d" would use more tags, so it is incorrect.
wordshas length in range
words[i]has length in range
Shas length in range
Sare lowercase letters.
Given two lists
B is an anagram of
B is an anagram of
B is made by randomizing the order of the elements in
We want to find an index mapping
B. A mapping
P[i] = j means the
ith element in
A appears in
B at index
B may contain duplicates. If there are multiple answers, output any of them.
For example, given
We should return
P = 1 because the
0th element of
A appears at
P = 4 because the
1st element of
A appears at
B, and so on.
A, Bhave equal lengths in range
A[i], B[i]are integers in range
MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.
Your class will have the method,
book(int start, int end). Formally, this represents a booking on the half open interval
[start, end), the range of real numbers
x such that
start <= x < end.
A double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)
For each call to the method
true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return
false and do not add the event to the calendar.
Your class will be called like this:
The number of calls to
MyCalendar.book per test case will be at most
In calls to
end are integers in the range
N network nodes, labelled
times, a list of travel times as directed edges
times[i] = (u, v, w), where
u is the source node,
v is the target node, and
w is the time it takes for a signal to travel from source to target.
Now, we send a signal from a certain node
K. How long will it take for all nodes to receive the signal? If it is impossible, return
Nwill be in the range
Kwill be in the range
timeswill be in the range
times[i] = (u, v, w)will have
1 <= u, v <= Nand
1 <= w <= 100.
On a staircase, the
i-th step has some non-negative cost
cost[i] assigned (0 indexed).
Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
costwill have a length in the range
cost[i]will be an integer in the range
Given an array
nums of integers, you can perform operations on the array.
In each operation, you pick any
nums[i] and delete it to earn
nums[i] points. After, you must delete every element equal to
nums[i] - 1 or
nums[i] + 1.
You start with 0 points. Return the maximum number of points you can earn by applying such operations.
The length of
nums is at most
nums[i] is an integer in the range