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
// Say you have an array for which the ith element is the price of a given stock on day i.
2
+
3
+
// If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
4
+
5
+
// Example 1:
6
+
// Input: [7, 1, 5, 3, 6, 4]
7
+
// Output: 5
8
+
9
+
// max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)
10
+
// Example 2:
11
+
// Input: [7, 6, 4, 3, 1]
12
+
// Output: 0
13
+
14
+
// In this case, no transaction is done, i.e. max profit = 0.
15
+
// Hide Company Tags Amazon Microsoft Bloomberg Uber Facebook
16
+
// Hide Tags Array Dynamic Programming
17
+
// Hide Similar Problems (M) Maximum Subarray (M) Best Time to Buy and Sell Stock II (H) Best Time to Buy and Sell Stock III (H) Best Time to Buy and Sell Stock IV (M) Best Time to Buy and Sell Stock with Cooldown
Copy file name to clipboardExpand all lines: 15 3Sum.js
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,20 @@
1
+
// Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
2
+
3
+
// Note: The solution set must not contain duplicate triplets.
4
+
5
+
// For example, given array S = [-1, 0, 1, 2, -1, -4],
6
+
7
+
// A solution set is:
8
+
// [
9
+
// [-1, 0, 1],
10
+
// [-1, -1, 2]
11
+
// ]
12
+
// Hide Company Tags Amazon Microsoft Bloomberg Facebook Adobe
13
+
// Hide Tags Array Two Pointers
14
+
// Hide Similar Problems (E) Two Sum (M) 3Sum Closest (M) 4Sum (M) 3Sum Smaller
0 commit comments