Sort by squares and find k-th smallest
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates array manipulation, ordering by derived keys (squares/absolute values), order-statistics reasoning, and algorithmic complexity analysis within the Coding & Algorithms domain.
Sort Values by Increasing Square
Constraints
- nums is sorted non-decreasing
Examples
Input: ([-3, -2, 0, 1, 2, 5],)
Expected Output: [0, 1, -2, 2, -3, 5]
Explanation: Prompt example up to tie order.
Input: ([-4, -1, 0, 3, 10],)
Expected Output: [0, -1, 3, -4, 10]
Explanation: Mixed signs.
Input: ([-2, -1],)
Expected Output: [-1, -2]
Explanation: All negative.
Hints
- Compare absolute values from both ends and fill from the back/front.
k-th Value by Increasing Square
Constraints
- k is 1-indexed
Examples
Input: ([-3, -2, 0, 1, 2, 5], 1)
Expected Output: 0
Explanation: Smallest square.
Input: ([-3, -2, 0, 1, 2, 5], 4)
Expected Output: 2
Explanation: Tie order follows the deterministic two-pointer order.
Input: ((-5, -4, -1), 2)
Expected Output: -4
Explanation: All negative input as tuple.
Hints
- This exact-match version uses the same deterministic two-pointer order as the full ordering problem.