FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Squares of a Sorted Array
How-ToProgramming Languages

Squares of a Sorted Array

via Dev.to PythonChristina Sharon S3h ago

Introduction When working with sorted arrays, problems often require maintaining order after performing operations. One such problem is squaring each element and returning the result in sorted order. At first glance, it may seem simple, but handling negative numbers makes it interesting. Problem Statement Given a sorted array nums in non-decreasing order, return a new array containing the squares of each number, also sorted in non-decreasing order. Example 1 Input: nums = [ - 4 , - 1 , 0 , 3 , 10 ] Output: [ 0 , 1 , 9 , 16 , 100 ] Explanation: After squaring → [16, 1, 0, 9, 100] After sorting → [0, 1, 9, 16, 100] Example 2 Input: nums = [ - 7 , - 3 , 2 , 3 , 11 ] Output: [ 4 , 9 , 9 , 49 , 121 ] Two-Pointer Approach We use: left → start of array right → end of array Fill result from the end Steps Compare absolute values of nums[left] and nums[right] Place the larger square at the end Move the corresponding pointer Repeat until done Python Implementation def sorted_squares ( nums ): n =

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
0 views

Related Articles

[Learning notes and hw] getting started with R-cnn: Manually implementing Intersection over Union (IoU)
How-To

[Learning notes and hw] getting started with R-cnn: Manually implementing Intersection over Union (IoU)

Dev.to Beginners • 49m ago

Botanical garden
How-To

Botanical garden

Dev.to Tutorial • 5h ago

Task 3: Delivery Man Task
How-To

Task 3: Delivery Man Task

Dev.to • 5h ago

I Wasted Months Memorizing Design Patterns — This One Trick Changed Everything
How-To

I Wasted Months Memorizing Design Patterns — This One Trick Changed Everything

Medium Programming • 6h ago

Top 5 Games to Improve Your Coding Skills
How-To

Top 5 Games to Improve Your Coding Skills

Medium Programming • 6h ago

Discover More Articles