Double Each Element - aloalgo

Double Each Element

Very Easy

You are given an array of integers nums.

Your task is to return a new array where each element is doubled (multiplied by 2).

You may assume that:

  • The array may be empty.

Return the new array with each element doubled. The order of elements must be preserved.

Example 1

Input
[1, 2, 3]
Output
[2, 4, 6]
Explanation:

Each element is multiplied by 2: 12=2, 22=4, 3*2=6.

Example 2

Input
[-1, 0, 1]
Output
[-2, 0, 2]
Explanation:

Doubling works for negative numbers and zero as well.

Example 3

Input
[]
Output
[]
Explanation:

An empty array returns an empty array.

Loading...
Input
[1, 2, 3]
Output
[2, 4, 6]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!