LeetCode — Squares of a sorted array

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Example 1:

Input: nums = [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Explanation: After squaring, the array becomes [16,1,0,9,100].
After sorting, it becomes [0,1,9,16,100].

Example 2:

Input: nums = [-7,-3,2,3,11]
Output: [4,9,9,49,121]


  • 1 <= nums.length <= 104
  • -104 <= nums[i] <= 104
  • nums is sorted in non-decreasing order.


Time complexity: O(n)




Dell Technologies — VxRail Software Engineer 👨‍💻

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Blogger Header Image Amp Code | Template Amp Header Issu Fix ?

Sound Has to Bounce (Reverb)!

Amazon SQS : Use Cases

Saving Data in Unity3D Using BinaryReader and BinaryWriter

[EN] TryHackMe 25 Days of Cyber Security: Day 8 Walkthrough

Low-Tech PC with a Raspberry PI

Trying out Snowflake’s Kafka Connector

Refresh Power BI Dataset via Client Secret #TAIK18 (23–3)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Steven Lu

Steven Lu

Dell Technologies — VxRail Software Engineer 👨‍💻

More from Medium

LeetCode — Merged two sorted linked lists

Cracking the Coding Interview Book Problem Series: Problem 15

[Leetcode] Container With Most Water

A Simple explanation about 312.Burst Balloons