Problem Description
Given a DataFrame or a collection of employees, each having a name and a salary, your task is to modify the salary column by doubling each employee's salary. This simulates giving all employees a pay rise.
Key Insights
- The problem requires you to update an existing data column.
- Each value in the salary column needs to be multiplied by 2.
- The transformation needs to be applied efficiently to all rows.
Space and Time Complexity
Time Complexity: O(n), where n is the number of employees.
Space Complexity: O(1) if modifying the original structure in-place.
Solution
We approach the problem by iterating over each employee's record and updating the salary field by multiplying it by 2.
For Python, we utilize pandas DataFrame column operations which are vectorized for efficiency.
For JavaScript, we use the map function on an array of employee objects.
In C++ and Java, we iterate over a list or vector of employee structures/objects to update the salary values.
Each of these methods leverages in-place modification when possible, ensuring minimal extra space usage.