Skip to content

Commit d176062

Browse files
committed
Added new problem
1 parent 52ae78a commit d176062

File tree

480 files changed

+13454
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

480 files changed

+13454
-150
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Problem 1: Sum Pair Discovery
2+
3+
## Problem Statement
4+
Given an array of integers `nums` and an integer `target`, return the indices of the two numbers such that they add up to `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice.
5+
6+
## Input Format
7+
- An array of integers `nums`.
8+
- An integer `target`.
9+
10+
## Output Format
11+
- A list of two integers representing the indices.
12+
13+
## Constraints
14+
- 2 <= nums.length <= 10^4
15+
- -10^9 <= nums[i] <= 10^9
16+
- -10^9 <= target <= 10^9
17+
18+
## Example
19+
**Input:** nums = [2, 7, 11, 15], target = 9
20+
**Output:** [0, 1]
21+
**Explanation:** nums[0] + nums[1] = 2 + 7 = 9.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Problem 10: Peak Mountaineer
2+
3+
## Problem Statement
4+
A peak element is an element that is strictly greater than its neighbors. Given an integer array `nums`, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that `nums[-1] = nums[n] = -∞`. You must write an algorithm that runs in O(log N) time.
5+
6+
## Input Format
7+
- An array of integers `nums`.
8+
9+
## Output Format
10+
- An integer representing the index of any peak element.
11+
12+
## Constraints
13+
- 1 <= nums.length <= 1000
14+
- -2^31 <= nums[i] <= 2^31 - 1
15+
- `nums[i] != nums[i + 1]` for all valid `i`.
16+
17+
## Example
18+
**Input:** nums = [1, 2, 1, 3, 5, 6, 4]
19+
**Output:** 5
20+
**Explanation:** Your function can return either index 1 where the peak element is 2, or index 5 where the peak element is 6.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Problem 11: Reservoir Capacity
2+
3+
## Problem Statement
4+
Given `n` non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.
5+
6+
## Input Format
7+
- An array of integers `height`.
8+
9+
## Output Format
10+
- An integer representing the total amount of trapped water.
11+
12+
## Constraints
13+
- n == height.length
14+
- 1 <= n <= 2 * 10^4
15+
- 0 <= height[i] <= 10^5
16+
17+
## Example
18+
**Input:** height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
19+
**Output:** 6
20+
**Explanation:** The elevation map [0,1,0,2,1,0,1,3,2,1,2,1] can trap 6 units of water.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Problem 12: Railway Station Congestion
2+
3+
## Problem Statement
4+
Given arrival and departure times of all trains that reach a railway station, find the minimum number of platforms required for the railway station so that no train has to wait.
5+
6+
## Input Format
7+
- Two arrays: `arrival` (sorted) and `departure` (unsorted or sorted).
8+
9+
## Output Format
10+
- An integer representing the minimum number of platforms.
11+
12+
## Constraints
13+
- 1 <= arrival.length <= 10^5
14+
- arrival.length == departure.length
15+
16+
## Example
17+
**Input:** arrival = [900, 940, 950, 1100, 1500, 1800], departure = [910, 1200, 1120, 1130, 1900, 2000]
18+
**Output:** 3
19+
**Explanation:**
20+
- At 9:00: Train 1 arrives (Platform count 1)
21+
- At 9:10: Train 1 departs (Platform count 0)
22+
- At 9:40: Train 2 arrives (Platform count 1)
23+
- At 9:50: Train 3 arrives (Platform count 2)
24+
- At 11:00: Train 4 arrives (Platform count 3)
25+
- ...At peak, 3 trains are in the station.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Problem 13: Triple Sum Discovery
2+
3+
## Problem Statement
4+
Given an integer array `nums`, return all the unique triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`. The solution set must not contain duplicate triplets.
5+
6+
## Input Format
7+
- An array of integers `nums`.
8+
9+
## Output Format
10+
- A list of lists representing the triplets.
11+
12+
## Constraints
13+
- 3 <= nums.length <= 3000
14+
- -10^5 <= nums[i] <= 10^5
15+
16+
## Example
17+
**Input:** nums = [-1, 0, 1, 2, -1, -4]
18+
**Output:** [[-1, -1, 2], [-1, 0, 1]]
19+
**Explanation:**
20+
- nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
21+
- nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
22+
- Result should not contain duplicate triplets like [-1, 0, 1] twice.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Problem 14: Liquid Capture Potential
2+
3+
## Problem Statement
4+
You are given an integer array `height` where `height[i]` represents the height of a vertical line. Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store.
5+
6+
## Input Format
7+
- An array of integers `height`.
8+
9+
## Output Format
10+
- An integer representing the maximum volume.
11+
12+
## Constraints
13+
- 2 <= height.length <= 10^5
14+
- 0 <= height[i] <= 10^4
15+
16+
## Example
17+
**Input:** height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
18+
**Output:** 49
19+
**Explanation:** The lines with heights 8 and 7 are at indices 1 and 8. The distance between them is 7. The volume is min(8, 7) * 7 = 49.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Problem 15: Strategic Leapfrog
2+
3+
## Problem Statement
4+
You are given an integer array `nums` where `nums[i]` is the maximum length of a jump you can make from that position. You are initially positioned at the first index. Return `True` if you can reach the last index, or `False` otherwise.
5+
6+
## Input Format
7+
- An array of integers `nums`.
8+
9+
## Output Format
10+
- Boolean value.
11+
12+
## Constraints
13+
- 1 <= nums.length <= 10^4
14+
- 0 <= nums[i] <= 10^5
15+
16+
## Example
17+
**Input:** nums = [2, 3, 1, 1, 4]
18+
**Output:** True
19+
**Explanation:** Jump 1 step from index 0 to 1, then 3 steps to the last index.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Problem 16: Interleaved Middle Find
2+
3+
## Problem Statement
4+
Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log(m+n)).
5+
6+
## Input Format
7+
- Two sorted arrays of integers `nums1` and `nums2`.
8+
9+
## Output Format
10+
- A float representing the median value.
11+
12+
## Constraints
13+
- nums1.length == m, nums2.length == n
14+
- 0 <= m, n <= 1000
15+
- 1 <= m + n <= 2000
16+
- -10^6 <= nums1[i], nums2[i] <= 10^6
17+
18+
## Example
19+
**Input:** nums1 = [1, 3], nums2 = [2]
20+
**Output:** 2.0
21+
**Explanation:** Merged array = [1, 2, 3], median is 2.0.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Problem 17: Infinite Loop Wealth
2+
3+
## Problem Statement
4+
Given a circular integer array `nums` (the next element of `nums[n-1]` is `nums[0]`), find the maximum possible sum of a non-empty subarray of `nums`.
5+
6+
## Input Format
7+
- An array of integers `nums`.
8+
9+
## Output Format
10+
- An integer representing the maximum circular subarray sum.
11+
12+
## Constraints
13+
- 1 <= nums.length <= 3 * 10^4
14+
- -30,000 <= nums[i] <= 30,000
15+
16+
## Example
17+
**Input:** nums = [5, -3, 5]
18+
**Output:** 10
19+
**Explanation:** [5, 5] (circularly) has the maximum sum = 10.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Problem 18: Shortest Stretch for Target
2+
3+
## Problem Statement
4+
Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a contiguous subarray of which the sum is greater than or equal to `target`. If there is no such subarray, return 0 instead.
5+
6+
## Input Format
7+
- An array of integers `nums`.
8+
- An integer `target`.
9+
10+
## Output Format
11+
- An integer representing the minimal length.
12+
13+
## Constraints
14+
- 1 <= target <= 10^9
15+
- 1 <= nums.length <= 10^5
16+
- 1 <= nums[i] <= 10^4
17+
18+
## Example
19+
**Input:** nums = [2, 3, 1, 2, 4, 3], target = 7
20+
**Output:** 2
21+
**Explanation:** The subarray [4, 3] has the minimal length under the problem constraint.

0 commit comments

Comments
 (0)