Problem URL: [Longest String Chain](https://leetcode.com/problems/longest-string-chain/?envType=daily-question&envId=2023-09-23)
Text:
You are given an array of words where each word consists of lowercase English letters.
A word chain is a sequence of words where each word is the predecessor of the next word, obtained by inserting exactly one letter anywhere in the current word. The order of the other characters in the word must remain the same.
Return the length of the longest possible word chain with words chosen from the given list of words.
---
Example 1:
Input:
Output:
Explanation:
One of the longest word chains is ["a","ba","bda","bdca"].
---
Example 2:
Input:
Output:
Explanation:
All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].
---
Example 3:
Input:
Output:
Explanation:
The trivial word chain ["abcd"] is one of the longest word chains. ["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.
---
Constraints:
- 1 <= words.length <= 1000
- 1 <= words[i].length <= 16
- words[i] only consists of lowercase English letters.
Text:
You are given an array of words where each word consists of lowercase English letters.
A word chain is a sequence of words where each word is the predecessor of the next word, obtained by inserting exactly one letter anywhere in the current word. The order of the other characters in the word must remain the same.
Return the length of the longest possible word chain with words chosen from the given list of words.
---
Example 1:
Input:
words = ["a","b","ba","bca","bda","bdca"]
Output:
4
Explanation:
One of the longest word chains is ["a","ba","bda","bdca"].
---
Example 2:
Input:
words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]
Output:
5
Explanation:
All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].
---
Example 3:
Input:
words = ["abcd","dbqca"]
Output:
1
Explanation:
The trivial word chain ["abcd"] is one of the longest word chains. ["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.
---
Constraints:
- 1 <= words.length <= 1000
- 1 <= words[i].length <= 16
- words[i] only consists of lowercase English letters.
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem Description
We have a pyramid of glasses with the following properties:
- The first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.
- Each glass holds one cup of champagne.
When champagne is poured into the topmost glass, any excess liquid poured will fall equally to the glass immediately to the left and right of it. This process continues until the bottom row where excess champagne falls on the floor.
Given the number of cups of champagne poured (
Examples
- Example 1:
- Input:
- Output:
- Explanation: We poured 1 cup of champagne into the top glass of the pyramid (indexed as (0, 0)). There will be no excess liquid, so all the glasses under the top glass will remain empty.
- Example 2:
- Input:
- Output:
- Explanation: We poured 2 cups of champagne into the top glass of the pyramid (indexed as (0, 0)). There is one cup of excess liquid. The glasses indexed as (1, 0) and (1, 1) will share the excess liquid equally, and each will have half a cup of champagne.
- Example 3:
- Input:
- Output:
- Explanation: We poured 100000009 cups of champagne into the top glass of the pyramid (indexed as (0, 0)). The glass at row 33 and index 17 will have a full cup of champagne.
Constraints
- 0 <= poured <= 10^9
- 0 <= query_glass <= query_row < 100
We have a pyramid of glasses with the following properties:
- The first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.
- Each glass holds one cup of champagne.
When champagne is poured into the topmost glass, any excess liquid poured will fall equally to the glass immediately to the left and right of it. This process continues until the bottom row where excess champagne falls on the floor.
Given the number of cups of champagne poured (
poured
), and the index of the glass in the row (query_glass
) and the row number (query_row
) we need to determine how full the specified glass will be.Examples
- Example 1:
- Input:
poured = 1
, query_row = 1
, query_glass = 1
- Output:
0.00000
- Explanation: We poured 1 cup of champagne into the top glass of the pyramid (indexed as (0, 0)). There will be no excess liquid, so all the glasses under the top glass will remain empty.
- Example 2:
- Input:
poured = 2
, query_row = 1
, query_glass = 1
- Output:
0.50000
- Explanation: We poured 2 cups of champagne into the top glass of the pyramid (indexed as (0, 0)). There is one cup of excess liquid. The glasses indexed as (1, 0) and (1, 1) will share the excess liquid equally, and each will have half a cup of champagne.
- Example 3:
- Input:
poured = 100000009
, query_row = 33
, query_glass = 17
- Output:
1.00000
- Explanation: We poured 100000009 cups of champagne into the top glass of the pyramid (indexed as (0, 0)). The glass at row 33 and index 17 will have a full cup of champagne.
Constraints
- 0 <= poured <= 10^9
- 0 <= query_glass <= query_row < 100
Problem URL: [https://leetcode.com/problems/find-the-difference/?envType=daily-question&envId=2023-09-25](https://leetcode.com/problems/find-the-difference/?envType=daily-question&envId=2023-09-25)
Problem Description:
You are given two strings,
String
Your task is to return the letter that was added to
Example 1:
Example 2:
Constraints:
- 0 <=
-
- Both
Problem Description:
You are given two strings,
s
and t
. String
t
is generated by randomly shuffling string s
and then adding one more letter at a random position. Your task is to return the letter that was added to
t
.Example 1:
Input: s = "abcd", t = "abcde"
Output: "e"
Explanation: 'e' is the letter that was added.
Example 2:
Input: s = "", t = "y"
Output: "y"
Constraints:
- 0 <=
s.length
<= 1000-
t.length
== s.length
+ 1- Both
s
and t
consist of lowercase English letters.LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem url: [https://leetcode.com/problems/remove-duplicate-letters/?envType=daily-question&envId=2023-09-26](https://leetcode.com/problems/remove-duplicate-letters/?envType=daily-question&envId=2023-09-26)
Given a string
Example 1:
Input:
Output:
Example 2:
Input:
Output:
Constraints:
- 1 <=
-
Note: This question is the same as 1081: [https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/)
Given a string
s
, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.Example 1:
Input:
s = "bcabc"
Output:
"abc"
Example 2:
Input:
s = "cbacdcbc"
Output:
"acdb"
Constraints:
- 1 <=
s.length
<= 104-
s
consists of lowercase English letters.Note: This question is the same as 1081: [https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/)
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem: [LeetCode - Decoded String at Index](https://leetcode.com/problems/decoded-string-at-index/?envType=daily-question&envId=2023-09-27)
You are given an encoded string
- If a character read is a letter, that letter is written onto the tape.
- If a character read is a digit
Given an integer
Example 1:
Input:
Output:
Explanation: The decoded string is
Example 2:
Input:
Output:
Explanation: The decoded string is
Example 3:
Input:
Output:
Explanation: The decoded string is
Constraints:
- 2 <=
-
-
- 1 <=
- It is guaranteed that
- The decoded string is guaranteed to have less than 2^63 letters.
You are given an encoded string
s
. To decode the string and obtain a tape, the following steps are taken:- If a character read is a letter, that letter is written onto the tape.
- If a character read is a digit
d
, the entire current tape is written d - 1
more times.Given an integer
k
, return the kth
letter (1-indexed) in the decoded string.Example 1:
Input:
s = "leet2code3", k = 10
Output:
"o"
Explanation: The decoded string is
"leetleetcodeleetleetcodeleetleetcode"
. The 10th letter in the string is "o"
.Example 2:
Input:
s = "ha22", k = 5
Output:
"h"
Explanation: The decoded string is
"hahahaha"
. The 5th letter is "h"
.Example 3:
Input:
s = "a2345678999999999999999", k = 1
Output:
"a"
Explanation: The decoded string is
"a"
repeated 8301530446056247680 times. The 1st letter is "a"
.Constraints:
- 2 <=
s.length
<= 100-
s
consists of lowercase English letters and digits 2 through 9.-
s
starts with a letter.- 1 <=
k
<= 10^9- It is guaranteed that
k
is less than or equal to the length of the decoded string.- The decoded string is guaranteed to have less than 2^63 letters.
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem Description:
Move all the even integers at the beginning of the given array
Example 1:
Example 2:
Constraints:
- 1 <= nums.length <= 5000
- 0 <= nums[i] <= 5000
Problem URL: [Sort Array By Parity - LeetCode](https://leetcode.com/problems/sort-array-by-parity/?envType=daily-question&envId=2023-09-28)
Move all the even integers at the beginning of the given array
nums
, followed by all the odd integers. Return any array that satisfies this condition.Example 1:
Input: nums = [3,1,2,4]
Output: [2,4,3,1]
Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
Example 2:
Input: nums = [0]
Output: [0]
Constraints:
- 1 <= nums.length <= 5000
- 0 <= nums[i] <= 5000
Problem URL: [Sort Array By Parity - LeetCode](https://leetcode.com/problems/sort-array-by-parity/?envType=daily-question&envId=2023-09-28)
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem url: [LeetCode Monotonic Array](https://leetcode.com/problems/monotonic-array/?envType=daily-question&envId=2023-09-29)
Text:
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j].
An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].
Given an integer array nums, return true if the given array is monotonic, or false otherwise.
Example 1:
- Input: nums = [1,2,2,3]
- Output: true
Example 2:
- Input: nums = [6,5,4,4]
- Output: true
Example 3:
- Input: nums = [1,3,2]
- Output: false
Constraints:
- 1 <= nums.length <= 105
- -105 <= nums[i] <= 105
Text:
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j].
An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].
Given an integer array nums, return true if the given array is monotonic, or false otherwise.
Example 1:
- Input: nums = [1,2,2,3]
- Output: true
Example 2:
- Input: nums = [6,5,4,4]
- Output: true
Example 3:
- Input: nums = [1,3,2]
- Output: false
Constraints:
- 1 <= nums.length <= 105
- -105 <= nums[i] <= 105
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem url: [https://leetcode.com/problems/132-pattern/?envType=daily-question&envId=2023-09-30](https://leetcode.com/problems/132-pattern/?envType=daily-question&envId=2023-09-30)
Text:
Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
Return true if there is a 132 pattern in nums, otherwise, return false.
Example 1:
Input: nums = [1,2,3,4]
Output: false
Explanation: There is no 132 pattern in the sequence.
Example 2:
Input: nums = [3,1,4,2]
Output: true
Explanation: There is a 132 pattern in the sequence: [1, 4, 2].
Example 3:
Input: nums = [-1,3,2,0]
Output: true
Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
Constraints:
n == nums.length
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
Text:
Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
Return true if there is a 132 pattern in nums, otherwise, return false.
Example 1:
Input: nums = [1,2,3,4]
Output: false
Explanation: There is no 132 pattern in the sequence.
Example 2:
Input: nums = [3,1,4,2]
Output: true
Explanation: There is a 132 pattern in the sequence: [1, 4, 2].
Example 3:
Input: nums = [-1,3,2,0]
Output: true
Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
Constraints:
n == nums.length
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Problem URL: [Reverse Words in a String III - LeetCode](https://leetcode.com/problems/reverse-words-in-a-string-iii/?envType=daily-question&envId=2023-10-01)
Text:
Given a string
Example 1:
Example 2:
Constraints:
- 1 <= s.length <= 5 * 10^4
-
-
- There is at least one word in
- All the words in
Text:
Given a string
s
, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:
Input: s = "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Example 2:
Input: s = "God Ding"
Output: "doG gniD"
Constraints:
- 1 <= s.length <= 5 * 10^4
-
s
contains printable ASCII characters.-
s
does not contain any leading or trailing spaces.- There is at least one word in
s
.- All the words in
s
are separated by a single space.LeetCode
Reverse Words in a String III - LeetCode
Can you solve this real interview question? Reverse Words in a String III - Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: s = "Let's take LeetCode…
Example 1:
Input: s = "Let's take LeetCode…
Problem Statement:
There are
Alice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.
Alice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.
Bob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.
Alice and Bob cannot remove pieces from the edge of the line.
If a player cannot make a move on their turn, that player loses and the other player wins.
Assuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.
Example:
Constraints:
- 1 <= colors.length <= 105
- colors consists of only the letters 'A' and 'B'
There are
n
pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors
of length n
where colors[i]
is the color of the ith
piece. Alice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.
Alice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.
Bob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.
Alice and Bob cannot remove pieces from the edge of the line.
If a player cannot make a move on their turn, that player loses and the other player wins.
Assuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.
Example:
Input: colors = "AAABABB"
Output: true
Explanation:
AAABABB -> AABABB
Alice moves first.
She removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.
Now it's Bob's turn.
Bob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.
Thus, Alice wins, so return true.
Input: colors = "AA"
Output: false
Explanation:
Alice has her turn first.
There are only two 'A's and both are on the edge of the line, so she cannot move on her turn.
Thus, Bob wins, so return false.
Input: colors = "ABBBBBBBAAA"
Output: false
Explanation:
ABBBBBBBAAA -> ABBBBBBBAA
Alice moves first.
Her only option is to remove the second to last 'A' from the right.
ABBBBBBBAA -> ABBBBBBAA
Next is Bob's turn.
He has many options for which 'B' piece to remove. He can pick any.
On Alice's second turn, she has no more pieces that she can remove.
Thus, Bob wins, so return false.
Constraints:
- 1 <= colors.length <= 105
- colors consists of only the letters 'A' and 'B'
[Problem](https://leetcode.com/problems/number-of-good-pairs/?envType=daily-question&envId=2023-10-03): Given an array of integers
A pair
Example 1:
Input:
Example 2:
Input:
Example 3:
Input:
-
nums
, return the number of good pairs.A pair
(i, j)
is called good if nums[i] == nums[j]
and i < j
.Example 1:
Input:
nums = [1,2,3,1,1,3]
Output: 4
Explanation: There are 4 good pairs (0,3)
, (0,4)
, (3,4)
, (2,5)
0-indexed.Example 2:
Input:
nums = [1,1,1,1]
Output: 6
Explanation: Each pair in the array is good.Example 3:
Input:
nums = [1,2,3]
Output: 0
Constraints:-
1 <= nums.length <= 100
- 1 <= nums[i] <= 100
Problem: Design and implement a HashMap data structure without using any built-in hash table libraries. The HashMap should have the following functionalities:
- Initialize the object with an empty map.
- Insert a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.
- Return the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.
- Remove the key and its corresponding value if the map contains the mapping for the key.
Example:
Constraints:
- 0 <= key, value <= 10^6
- At most 10^4 calls will be made to put, get, and remove.
Problem URL: [https://leetcode.com/problems/design-hashmap/?envType=daily-question&envId=2023-10-04](https://leetcode.com/problems/design-hashmap/?envType=daily-question&envId=2023-10-04)
- Initialize the object with an empty map.
- Insert a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.
- Return the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.
- Remove the key and its corresponding value if the map contains the mapping for the key.
Example:
plaintext
Input:
["MyHashMap", "put", "put", "get", "get", "put", "get", "remove", "get"]
[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]
Output:
[null, null, null, 1, -1, null, 1, null, -1]
Explanation:
MyHashMap myHashMap = new MyHashMap();
myHashMap.put(1, 1); // The map is now [[1,1]]
myHashMap.put(2, 2); // The map is now [[1,1], [2,2]]
myHashMap.get(1); // return 1, The map is now [[1,1], [2,2]]
myHashMap.get(3); // return -1 (i.e., not found), The map is now [[1,1], [2,2]]
myHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value)
myHashMap.get(2); // return 1, The map is now [[1,1], [2,1]]
myHashMap.remove(2); // Remove the mapping for 2, The map is now [[1,1]]
myHashMap.get(2); // return -1 (i.e., not found), The map is now [[1,1]]
Constraints:
- 0 <= key, value <= 10^6
- At most 10^4 calls will be made to put, get, and remove.
Problem URL: [https://leetcode.com/problems/design-hashmap/?envType=daily-question&envId=2023-10-04](https://leetcode.com/problems/design-hashmap/?envType=daily-question&envId=2023-10-04)
Problem url: [https://leetcode.com/problems/majority-element-ii/](https://leetcode.com/problems/majority-element-ii/?envType=daily-question&envId=2023-10-05)
Given an integer array
Example 1:
- 1 <= nums.length <= 5 * 10^4
- -10^9 <= nums[i] <= 10^9
Follow up: Could you solve the problem in linear time and in O(1) space?
Given an integer array
nums
of size n
, find all elements that appear more than ⌊ n/3 ⌋ times.Example 1:
Input: nums = [3,2,3]Example 2:
Output: [3]
Input: nums = [1]Example 3:
Output: [1]
Input: nums = [1,2]Constraints:
Output: [1,2]
- 1 <= nums.length <= 5 * 10^4
- -10^9 <= nums[i] <= 10^9
Follow up: Could you solve the problem in linear time and in O(1) space?
Problem: Integer Break
URL: [https://leetcode.com/problems/integer-break/?envType=daily-question&envId=2023-10-06](https://leetcode.com/problems/integer-break/?envType=daily-question&envId=2023-10-06)
Description: Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers. Return the maximum product you can get.
Example 1:
Example 2:
Constraints:
- 2 <= n <= 58
URL: [https://leetcode.com/problems/integer-break/?envType=daily-question&envId=2023-10-06](https://leetcode.com/problems/integer-break/?envType=daily-question&envId=2023-10-06)
Description: Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers. Return the maximum product you can get.
Example 1:
Input: n = 2
Output: 1
Explanation: 2 = 1 + 1, 1 × 1 = 1.
Example 2:
Input: n = 10
Output: 36
Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.
Constraints:
- 2 <= n <= 58
Problem:
Given three integers
-
- Each element in
- After applying a certain algorithm to
Your goal is to return the number of ways to build
Example:
- Input:
Output:
Explanation: The possible arrays meeting the given conditions are: [1, 1], [2, 1], [2, 2], [3, 1], [3, 2], [3, 3].
- Input:
Output:
Explanation: There are no possible arrays that satisfy the given conditions.
- Input:
Output:
Explanation: The only possible array satisfying the conditions is [1, 1, 1, 1, 1, 1, 1, 1, 1].
Constraints:
- 1 <= n <= 50
- 1 <= m <= 100
- 0 <= k <= n
Given three integers
n
, m
, and k
, you are tasked with building an array arr
with the following properties:-
arr
consists of exactly n
integers.- Each element in
arr
is a positive integer between 1 and m
.- After applying a certain algorithm to
arr
, the resulting search_cost
is equal to k
.Your goal is to return the number of ways to build
arr
satisfying the given conditions. Since the answer may be large, it should be computed modulo 10^9 + 7.Example:
- Input:
n = 2, m = 3, k = 1
Output:
6
Explanation: The possible arrays meeting the given conditions are: [1, 1], [2, 1], [2, 2], [3, 1], [3, 2], [3, 3].
- Input:
n = 5, m = 2, k = 3
Output:
0
Explanation: There are no possible arrays that satisfy the given conditions.
- Input:
n = 9, m = 1, k = 1
Output:
1
Explanation: The only possible array satisfying the conditions is [1, 1, 1, 1, 1, 1, 1, 1, 1].
Constraints:
- 1 <= n <= 50
- 1 <= m <= 100
- 0 <= k <= n
## Problem
Given two arrays
A subsequence of an array is a new array formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements.
### Example 1:
Input:
Output:
Explanation: Take subsequence
Their dot product is
### Example 2:
Input:
Output:
Explanation: Take subsequence
Their dot product is
### Example 3:
Input:
Output:
Explanation: Take subsequence
Their dot product is
### Constraints:
-
-
Given two arrays
nums1
and nums2
, return the maximum dot product between non-empty subsequences of nums1
and nums2
with the same length.A subsequence of an array is a new array formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements.
### Example 1:
Input:
nums1 = [2,1,-2,5]
, nums2 = [3,0,-6]
Output:
18
Explanation: Take subsequence
[2,-2]
from nums1
and subsequence [3,-6]
from nums2
. Their dot product is
(2*3 + (-2)*(-6)) = 18
.### Example 2:
Input:
nums1 = [3,-2]
, nums2 = [2,-6,7]
Output:
21
Explanation: Take subsequence
[3]
from nums1
and subsequence [7]
from nums2
. Their dot product is
(3*7) = 21
.### Example 3:
Input:
nums1 = [-1,-1]
, nums2 = [1,1]
Output:
-1
Explanation: Take subsequence
[-1]
from nums1
and subsequence [1]
from nums2
. Their dot product is
-1
.### Constraints:
-
1 <= nums1.length, nums2.length <= 500
-
-1000 <= nums1[i], nums2[i] <= 1000
Problem URL: [https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/?envType=daily-question&envId=2023-10-09](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/?envType=daily-question&envId=2023-10-09)
Text:
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
If target is not found in the array, return [-1, -1].
You must write an algorithm with O(log n) runtime complexity.
Example 1:
Input: nums = [5,7,7,8,8,10], target = 8
Output: [3,4]
Example 2:
Input: nums = [5,7,7,8,8,10], target = 6
Output: [-1,-1]
Example 3:
Input: nums = [], target = 0
Output: [-1,-1]
Constraints:
0 <= nums.length <= 105
-109 <= nums[i] <= 109
nums is a non-decreasing array.
-109 <= target <= 109
Text:
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
If target is not found in the array, return [-1, -1].
You must write an algorithm with O(log n) runtime complexity.
Example 1:
Input: nums = [5,7,7,8,8,10], target = 8
Output: [3,4]
Example 2:
Input: nums = [5,7,7,8,8,10], target = 6
Output: [-1,-1]
Example 3:
Input: nums = [], target = 0
Output: [-1,-1]
Constraints:
0 <= nums.length <= 105
-109 <= nums[i] <= 109
nums is a non-decreasing array.
-109 <= target <= 109
Problem Statement
Given an integer array
- All elements in
- The difference between the maximum element and the minimum element in
For example,
Example 1:
Input:
Output:
Explanation:
Example 2:
Input:
Output:
Explanation: One possible solution is to change the last element to
Example 3:
Input:
Output:
Explanation: One possible solution is to:
- Change the second element to
- Change the third element to
- Change the fourth element to
The resulting array is
Given an integer array
nums
, find the minimum number of operations required to make nums
continuous. A array is considered continuous if the following conditions are fulfilled:- All elements in
nums
are unique.- The difference between the maximum element and the minimum element in
nums
equals nums.length - 1
.For example,
[4, 2, 5, 3]
is continuous, but [1, 2, 3, 5, 6]
is not continuous.Example 1:
Input:
nums = [4, 2, 5, 3]
Output:
0
Explanation:
nums
is already continuous.Example 2:
Input:
nums = [1, 2, 3, 5, 6]
Output:
1
Explanation: One possible solution is to change the last element to
4
. The resulting array is [1, 2, 3, 5, 4]
, which is continuous.Example 3:
Input:
nums = [1, 10, 100, 1000]
Output:
3
Explanation: One possible solution is to:
- Change the second element to
2
.- Change the third element to
3
.- Change the fourth element to
4
. The resulting array is
[1, 2, 3, 4]
, which is continuous.Problem URL: [Number of Flowers in Full Bloom - LeetCode](https://leetcode.com/problems/number-of-flowers-in-full-bloom/?envType=daily-question&envId=2023-10-11)
Problem Description:
You are given a 0-indexed 2D integer array
Return an integer array
Example 1:
Example 2:
Constraints:
- 1 <= flowers.length <= 5 * 10^4
- flowers[i].length == 2
- 1 <= starti <= endi <= 10^9
- 1 <= people.length <= 5 * 10^4
- 1 <= people[i] <= 10^9
Problem Description:
You are given a 0-indexed 2D integer array
flowers
, where flowers[i] = [starti, endi]
means the ith flower will be in full bloom from starti
to endi
(inclusive). You are also given a 0-indexed integer array people
of size n
, where people[i]
is the time that the ith person will arrive to see the flowers.Return an integer array
answer
of size n
, where answer[i]
is the number of flowers that are in full bloom when the ith person arrives.Example 1:
Input: flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11]
Output: [1,2,2,2]
Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
For each person, we return the number of flowers in full bloom during their arrival.
Example 2:
Input: flowers = [[1,10],[3,3]], people = [3,3,2]
Output: [2,2,1]
Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
For each person, we return the number of flowers in full bloom during their arrival.
Constraints:
- 1 <= flowers.length <= 5 * 10^4
- flowers[i].length == 2
- 1 <= starti <= endi <= 10^9
- 1 <= people.length <= 5 * 10^4
- 1 <= people[i] <= 10^9
Problem URL: [https://leetcode.com/problems/find-in-mountain-array/?envType=daily-question&envId=2023-10-12](https://leetcode.com/problems/find-in-mountain-array/?envType=daily-question&envId=2023-10-12)
Problem Description:
- An array
-
-
- You cannot access the mountain array directly. You may only access the array using a MountainArray interface:
-
-
- Submissions making more than 100 calls to
Examples:
- Example 1:
-
- Example 2:
-
Constraints:
- 3 <=
- 0 <=
- 0 <=
Problem Description:
- An array
arr
is a mountain array if and only if:-
arr.length >= 3
- There exists some i
with 0 < i < arr.length - 1
such that:-
arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
- arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
- Given a mountain array mountainArr
, return the minimum index such that mountainArr.get(index) == target
. If such an index does not exist, return -1
.- You cannot access the mountain array directly. You may only access the array using a MountainArray interface:
-
MountainArray.get(k)
returns the element of the array at index k
(0-indexed).-
MountainArray.length()
returns the length of the array.- Submissions making more than 100 calls to
MountainArray.get
will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.Examples:
- Example 1:
-
Input: array = [1,2,3,4,5,3,1], target = 3
- Output: 2
- Explanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.- Example 2:
-
Input: array = [0,1,2,4,2,1], target = 3
- Output: -1
- Explanation: 3 does not exist in the array, so we return -1.Constraints:
- 3 <=
mountain_arr.length()
<= 10^4- 0 <=
target
<= 10^9- 0 <=
mountain_arr.get(index)
<= 10^9Problem URL: [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/?envType=daily-question&envId=2023-10-13)
Problem Description:
- Given an integer array
- Once you pay the cost, you can either climb one or two steps.
- You can either start from the step with index 0 or the step with index 1.
- Return the minimum cost to reach the top of the floor.
Example 1:
Example 2:
Constraints:
- 2 <= cost.length <= 1000
- 0 <= cost[i] <= 999
Problem Description:
- Given an integer array
cost
where cost[i]
is the cost of the ith step on a staircase.- Once you pay the cost, you can either climb one or two steps.
- You can either start from the step with index 0 or the step with index 1.
- Return the minimum cost to reach the top of the floor.
Example 1:
Input: cost = [10,15,20]
Output: 15
Explanation: You will start at index 1.
- Pay 15 and climb two steps to reach the top.
The total cost is 15.
Example 2:
Input: cost = [1,100,1,1,1,100,1,1,100,1]
Output: 6
Explanation: You will start at index 0.
- Pay 1 and climb two steps to reach index 2.
- Pay 1 and climb two steps to reach index 4.
- Pay 1 and climb two steps to reach index 6.
- Pay 1 and climb one step to reach index 7.
- Pay 1 and climb two steps to reach index 9.
- Pay 1 and climb one step to reach the top.
The total cost is 6.
Constraints:
- 2 <= cost.length <= 1000
- 0 <= cost[i] <= 999