First

GFG
mail@pastecode.io avatar
unknown
java
a year ago
428 B
1
Indexable
Never
class Solution {
    public int antiqueItems(int n, int items[], int price[]){
        Map<Integer, Integer> hm = new HashMap<>();
        for(int i = 0; i < n; i++){
            int cur = hm.getOrDefault(items[i], Integer.MAX_VALUE);
            if(price[i] < cur)
                hm.put(items[i], price[i]);
        }
        int ans = 0;
        for(int x : hm.values())
                ans += x;
        return ans;
    }
}