Problem Description
A company intends to give its employees a pay rise. Write a solution to modify the salary
column by multiplying each salary by 2.
Key Insights
- The task requires modifying a specific column in a DataFrame.
- The operation is a straightforward multiplication of each salary by a constant factor (2).
- The problem can be solved using vectorized operations in DataFrame libraries like pandas.
Space and Time Complexity
Time Complexity: O(n) - where n is the number of employees (rows in the DataFrame). Space Complexity: O(1) - as we are modifying the existing DataFrame in place.
Solution
To solve this problem, we will use a DataFrame, which is a suitable data structure for storing tabular data. The algorithm involves iterating through the salary
column and applying the multiplication operation. In Python, this can be efficiently handled using libraries like pandas, which allow for vectorized operations, meaning we can apply the operation to the entire column at once without explicitly iterating through each row.