DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Squares of a Sorted Array

**Problem Statement:** Given an integer array `nums` sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. **Hint / Expected Approach:** Two-pointer from both ends **Edge Cases to Consider:** - (1) All negative input - (2) All positive - (3) Array with only zeros

Examples

Example 1
Input: [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Example 2
Input: [-7,-3,2,3,11]
Output: [4,9,9,49,121]
Example 3
Input: [0]
Output: [0]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪All negative input
  • ▪All positive
  • ▪Array with only zeros
Frequently Asked At
GoogleAmazonMicrosoftTCS