FastPrepSquares of a Sorted Array

Squares of a Sorted Array

Goldman Sachs logoGoldman Sachs● EasyFULLTIMEPHONE SCREEN
Learn

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]

More Goldman Sachs problems

See Goldman Sachs hiring insights
public int[] sortedSquares(int[] nums) {
  // write your code here
}
nums[-4,-1,0,3,10]
expected[0,1,9,16,100]
Checking account…