Determine minimal substitutions and removals
Company: Salesforce
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Take-home Project
Quick Answer: This question evaluates string manipulation and adjacency-constraint handling in the first task and sequence analysis with minimal-removal and subsequence reasoning in the second, targeting competencies such as local transformation logic, subsequence recognition, and optimization under input constraints.
Constraints
- 0 <= n <= 200000
- All nums[i] are pairwise distinct
- -10^9 <= nums[i] <= 10^9
- Aim for O(n log n) time and O(n) extra space
Hints
- Let L be the length of the longest strictly increasing subsequence (LIS).
- Any almost-sorted subsequence can become strictly increasing by removing one element, so its strictly increasing remainder cannot exceed length L.
- You can achieve length L+1 by taking any LIS and adding one extra element; compute L with patience sorting (binary search) in O(n log n).