You are given three independent algorithmic tasks. For each one, explain your approach (no need to run code).
1) Merge two sorted lists (integers instead of nodes)
Given two sorted integer arrays A and B (non-decreasing order), merge them into a single sorted array containing all elements from both inputs.
-
Input:
two arrays
A
,
B
-
Output:
merged sorted array
-
Constraints (typical):
0 <= len(A), len(B) <= 1e5
2) Max profit from one stock transaction
Given an array prices where prices[i] is the stock price on day i, compute the maximum profit you can achieve by choosing at most one day to buy and a later day to sell. If no profit is possible, return 0.
-
Input:
array
prices
-
Output:
integer max profit
-
Constraints (typical):
1 <= n <= 1e5
,
0 <= prices[i] <= 1e9
3) Validate parentheses pairing
Given a string s consisting only of the characters '(', ')', '[', ']', '{', '}', determine whether the parentheses/brackets are valid.
A string is valid if:
-
Every opening bracket has a corresponding closing bracket of the same type.
-
Brackets are closed in the correct order.
-
Input:
string
s
-
Output:
boolean
-
Constraints (typical):
0 <= |s| <= 1e5