1777. Product's Price for Each Store
Explanation:
To solve this problem, we can iterate over the given products
list and calculate the price for each store by multiplying the base price with the corresponding multiplier for that store. We can store the prices for each store in a new list and return it as the result.
- Time complexity: O(N) where N is the number of products in the input list.
- Space complexity: O(N) to store the prices for each store.
:
import java.util.ArrayList;
import java.util.List;
class Solution {
public List<Double> prices(List<Integer> products, List<Integer> multiplier, int n) {
List<Double> result = new ArrayList<>();
for (int i = 0; i < n; i++) {
double price = products.get(i) * multiplier.get(i) / 100.0;
result.add(price);
}
return result;
}
}
Code Editor (Testing phase)
Improve Your Solution
Use the editor below to refine the provided solution. Select a programming language and try the following:
- Add import statement if required.
- Optimize the code for better time or space complexity.
- Add test cases to validate edge cases and common scenarios.
- Handle error conditions or invalid inputs gracefully.
- Experiment with alternative approaches to deepen your understanding.
Click "Run Code" to execute your solution and view the output. If errors occur, check the line numbers and debug accordingly. Resize the editor by dragging its bottom edge.