Instructions
• You may implement your solutions in Python, C/C++, Java, or JavaScript.
• No external libraries are allowed beyond basic language features for reading input, writing output,
and using fundamental data structures or functions.
----------------------------------------------------------------------------------------------------------------------
Problem Statement 1 -
You are given a 0-indexed array of integers nums of length n. You are initially positioned
at nums[0].
Each element nums[i] represents the maximum length of a forward jump from index i. In other
words, if you are at nums[i], you can jump to any nums[i + j] where:
0 <= j <= nums[i] and
i+j<n
Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that
you can reach nums[n - 1].
Expected
Test Case Input (nums array) Explanation
Output
1 [2, 3, 1, 1, 4] 2 Jump from 0 → 1 → 4
2 [2, 3, 0, 1, 4] 2 Jump from 0 → 1 → 4
3 [1, 1, 1, 1] 3 Jump from 0 → 1 → 2 → 3
[ 10, 9, 8, 7, 6, 5, 4,
4 1 Single jump to the last index
3, 2, 1, 1, 0]
[ 1, 3, 5, 8, 2, 6, 7,
5 3 Jump from 0 → 1 → 3 → 9
6, 8, 9]
Constraints:
1 <= nums.length <= 104
0 <= nums[i] <= 1000
It's guaranteed that you can reach nums[n - 1].
----------------------------------------------------------------------------------------------------------------
Problem Statement 2 -
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.
On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of
the stock at any time. However, you can buy it then immediately sell it on the same day.
Find and return the maximum profit you can achieve.
Example 1:
Input: prices = [7,1,5,3,6,4]
Output: 7
Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
Total profit is 4 + 3 = 7.
Example 2:
Input: prices = [1,2,3,4,5]
Output: 4
Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
Total profit is 4.
Example 3:
Input: prices = [7,6,4,3,1]
Output: 0
Explanation: There is no way to make a positive profit, so we never buy the stock to achieve the
maximum profit of 0.
Constraints:
1 <= prices.length <= 3 * 104
0 <= prices[i] <= 104
------------------------------------------------------------------------------------------------------------------------
Problem Statement 3 –
1. A wiggle sequence is a sequence where the differences between successive numbers strictly
alternate between positive and negative. The first difference (if one exists) may be either positive or
negative. A sequence with one element and a sequence with two non-equal elements are trivially
wiggle sequences.
For example, [1, 7, 4, 9, 2, 5] is a wiggle sequence because the differences (6, -3, 5, -7,
3) alternate between positive and negative.
In contrast, [1, 4, 7, 2, 5] and [1, 7, 4, 5, 5] are not wiggle sequences. The first is not
because its first two differences are positive, and the second is not because its last difference is zero.
A subsequence is obtained by deleting some elements (possibly zero) from the original sequence,
leaving the remaining elements in their original order.
Given an integer array nums, return the length of the longest wiggle subsequence of nums.
Example 1:
Input: nums = [1,7,4,9,2,5]
Output: 6
Explanation: The entire sequence is a wiggle sequence with differences (6, -3, 5, -7, 3).
Example 2:
Input: nums = [1,17,5,10,13,15,10,5,16,8]
Output: 7
Explanation: There are several subsequences that achieve this length.
One is [1, 17, 10, 13, 10, 16, 8] with differences (16, -7, 3, -3, 6, -8).
Example 3:
Input: nums = [1,2,3,4,5,6,7,8,9]
Output: 2
Constraints:
1 <= nums.length <= 1000
0 <= nums[i] <= 1000