Solve three easy algorithm problems
AppleSoftware Engineer · Technical ScreenLast updated
This multi-part prompt evaluates proficiency in fundamental algorithmic concepts including sorted array handling, single-transaction optimization in time-series data, and bracket-sequence validation, measuring understanding of array and string manipulation, common data structures, algorithmic complexity, and edge-case reasoning.
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
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.