Continue learning
Practice related DSA questions in the same topic.
Return a reversed copy by exchanging symmetric positions.
Return a reversed copy by exchanging symmetric positions.
def solve(values, target): a = values.copy() left = 0 right = (len(a) - 1) while (left < right): a[left], a[right] = a[right], a[left] left = (left + 1) right = (right - 1) return aExchange symmetric positions 0 and 3.
Exchange symmetric positions 0 and 3.
Two friends rehang a row of photos, swapping the outermost unfinished pair.
Every successful swap finalizes both ends of the remaining interval.
O(n) time · O(n) returned copy, O(1) auxiliary auxiliary space
Worked example · {"values":[3,8,1,5],"target":0} ⇒ [5,1,8,3]
Edge case 1 · {"values":[],"target":0} ⇒ []
Edge case 2 · {"values":[4],"target":0} ⇒ [4]
Swapping across the entire index range undoes earlier exchanges.
How many swaps does a length-n array require?