easyArrays 0 views
Square Every Element In Place
Practice raw array basics: fixed-size indexing, iteration, and in-place mutation.
Given an array of integers nums, replace each element with its square, modifying the array in place, and return it.
This is a basics exercise for raw arrays specifically (not a dynamic list): the point is index-based access and mutation, nums[i] = ..., which is the one operation a fixed-size array gives you that a dynamic list's higher-level API can obscure.
Example 1
Input: nums = [1,-2,3]
Output: [1,4,9]
Example 2
Input: nums = [0,5]
Output: [0,25]
Example 3
Input: nums = []
Output: []
Constraints
- 0 <= nums.length <= 1000
- -100 <= nums[i] <= 100
Follow-up
Could you do this without an explicit index variable? What would you lose by doing so?
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.