Based on a LinkedIn post originally published on 7 January 2026 During a technical interview, I was asked to solve a deceptively simple C++ problem: Given a sorted array of integers in ascending order, produce a new array containing the square of each value. The output must also be sorted in ascending order and contain only unique values. At first glance, the solution appears obvious: Iterate through the input. Square every value. Sort the resulting array. Remove duplicates. That approach would produce the correct result. However, it would also ignore the most useful information provided by the problem: the input is already sorted. The interesting part of the exercise is recognising that this is not really a sorting problem. It is a two-pointer problem. Why squaring destroys the original order Consider this input: -7, -4, -1, 0, 3, 5 It is already sorted in ascending order. Squaring the values in their existing sequence produces: 49, 16, 1, 0, 9, 25 The result is no longer sorted. This...