Problem · Array

Squares of a Sorted Array

Learn this problem
EasyStrykerPHONE SCREEN

Problem statement

Given an integer array nums sorted in nondecreasing order, square every value and return the resulting values in nondecreasing order.

Function

sortedSquares(nums: int[]) → int[]

Examples

Example 1

nums = [-4,-1,0,3,10]return = [0,1,9,16,100]

Example 2

nums = [-7,-3,2,3,11]return = [4,9,9,49,121]
drafts saved locally
public int[] sortedSquares(int[] nums) {
  // write your code here
}
nums[-4,-1,0,3,10]
expected[0,1,9,16,100]
checking account