You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
5
5
@@ -8,33 +8,45 @@ Merge nums1 and nums2 into a single array sorted in non-decreasing order.
8
8
The final sorted array should not be returned, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.
9
9
10
10
Example 1:
11
+
11
12
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Explanation: The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
12
13
13
14
Example 2:
15
+
14
16
Input: nums1 = [1], m = 1, nums2 = [], n = 0 Output: [1] Explanation: The arrays we are merging are [1] and []. The result of the merge is [1].
15
17
16
18
Example 3:
19
+
17
20
Input: nums1 = [0], m = 0, nums2 = [1], n = 1 Output: [1] Explanation: The arrays we are merging are [] and [1]. The result of the merge is [1]. Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.
18
21
19
22
Input Format:
23
+
20
24
The first line contains two integers m and n - the number of elements of array num1 and num2.
25
+
21
26
The second line contains the elements of the array num1.
27
+
22
28
The third line contains the elements of the array num2.
23
29
24
30
Constraints:
31
+
25
32
nums1.length == m + n
33
+
26
34
nums2.length == n
35
+
27
36
0 <= m, n <= 200
37
+
28
38
1 <= m + n <= 200
39
+
29
40
-109 <= nums1[i], nums2[j] <= 109
30
41
31
42
Output Format:
43
+
32
44
Output in a single line the merged sorted array.
33
45
34
46
35
47
36
48
37
-
**Q2) MINIMUM COINS**
49
+
**Q2) MINIMUM COINS**
38
50
39
51
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
40
52
@@ -43,58 +55,77 @@ Return the fewest number of coins that you need to make up that amount. If that
43
55
You may assume that you have an infinite number of each kind of coin.
44
56
45
57
Input Format:
58
+
46
59
First line contains n, the length of the integer array.
60
+
47
61
Second line contains the elements of the integer array.
62
+
48
63
Third line contains the amount.
49
64
50
65
Constraints:
66
+
51
67
1) 1 <= coins.length <= 12
52
68
2) 1 <= coins[i] <= 231 - 1
53
69
3) 0 <= amount <= 104
54
70
55
71
Output Format:
72
+
56
73
Output the fewest number of coins required to get the amount.
57
74
58
75
59
76
60
77
61
-
**Q3) ISLANDS**
78
+
**Q3) ISLANDS**
62
79
63
80
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
64
81
65
82
An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
66
83
67
84
Input Format:
85
+
68
86
First line contains two integers m,n - rows and columnns of the matrix, respectively.
87
+
69
88
Next, m lines begins. Each line contains n elements in it.
70
89
71
90
Constraints:
91
+
72
92
m == grid.length
93
+
73
94
n == grid[i].length
95
+
74
96
1 <= m, n <= 300
97
+
75
98
grid[i][j] is '0' or '1'.
76
99
77
100
Output Format:
101
+
78
102
Output the number of islands.
79
103
80
104
81
105
82
106
83
-
**Q4) TRAPPING RAIN WATER**
107
+
**Q4) TRAPPING RAIN WATER**
84
108
85
109
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.
86
110
87
111
Example 1:
112
+
88
113
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
89
114
90
115
Input Format:
116
+
91
117
The first line contains one integer n - the size of array
118
+
92
119
The second line contains the elements of the array.
93
120
94
121
Constraints:
122
+
95
123
n == height.length
124
+
96
125
1 <= n <= 2 * 104
126
+
97
127
0 <= height[i] <= 105
98
128
99
129
Output Format:
130
+
100
131
Output in one line - the water it can trap after raining.
0 commit comments