DEV Community

Ganga Sri V
Ganga Sri V

Posted on

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.

My Approach:

1.Square Each Element in the given array then replace each element with its square.
2.Then I Sort the Array by using Arrays.sort() to sort the squared numbers in increasing order.
3.Then I Return the Array that are modified array with sorted squares.

Methods Used:
Squaring
Sorting
In-Place replacement

Top comments (0)