Enhanced Hashmap - Add a number to all keys/values
I would suggest you create your own OffsetIntegerMap that can map between integers and handle an offset on the keys and values.
You don't necessarily have to implement the HashMap from scratch, define your own limited interface and implement it with an existing Map&lt;Integer, Integer&gt; through composition.
By handling the offsets separately from the keys and values the complexity of the offset operations end up O(1) instead of O(n) when doing recalculations and the Map&lt;&gt; put and get operations stay at their original O(1).
An example an &quot;OffsetIntegerMap&quot;:
import java.util.HashMap;
import java.util.Map;

public class OffsetIntegerMap {
    private final Map&lt;Integer, Integer&gt; actualMap;
    private int keyOffset = 0;
    private int valueOffset = 0;

    public OffsetIntegerMap() {
        actualMap = new HashMap&lt;&gt;();
    }

    public int size() {
        return actualMap.size();
    }

    public boolean isEmpty() {
        return actualMap.isEmpty();
    }

    public boolean containsKey(int key) {
        var keyWithoutOffset = key - keyOffset;
        return actualMap.containsKey(keyWithoutOffset);
    }

    public boolean containsValue(int value) {
        var valueWithoutOffset = value - valueOffset;
        return actualMap.containsValue(valueWithoutOffset);
    }

    public Integer get(int key) {
        var keyWithoutOffset = key - keyOffset;
        var value = actualMap.get(keyWithoutOffset);
        if (value == null) return null;
        return value + valueOffset;
    }

    public Integer put(int key, int value) {
        var keyWithoutOffset = key - keyOffset;
        var valueWithoutOffset = value - valueOffset;
        var oldValue = actualMap.put(keyWithoutOffset, valueWithoutOffset);
        if (oldValue == null) return null;
        return oldValue + valueOffset;
    }

    public Integer remove(int key) {
        var keyWithoutOffset = key - keyOffset;
        var oldValue = actualMap.remove(keyWithoutOffset);
        if (oldValue == null) return null;
        return oldValue + valueOffset;
    }

    public void clear() {
        actualMap.clear();
        keyOffset = 0;
        valueOffset = 0;
    }

    public int getKeyOffset() {
        return keyOffset;
    }

    public void setKeyOffset(int keyOffset) {
        this.keyOffset = keyOffset;
    }

    public int getValueOffset() {
        return valueOffset;
    }

    public void setValueOffset(int valueOffset) {
        this.valueOffset = valueOffset;
    }

    public void addToValues(int toAdd) {
        this.valueOffset += toAdd;
    }

    public void addToKeys(int toAdd) {
        this.keyOffset += toAdd;
    }
}

By encapsulating the offset logic the processing loop also becomes much simpler without refactoring much of anything:
static long hashMap(String[] queryType, int[][] query) {
    long sum = 0;
    var map = new OffsetIntegerMap();
    for (int i = 0; i &lt; queryType.length; i++) {
        String currQuery = queryType[i];
        switch (currQuery) {
            case &quot;insert&quot;:
                map.put(query[i][0], query[i][1]);
                break;
            case &quot;addToValue&quot;:
                map.addToValues(query[i][0]);
                break;
            case &quot;addToKey&quot;:
                map.addToKeys(query[i][0]);
                break;
            case &quot;get&quot;:
                sum += map.get(query[i][0]);
        }
    }
    return sum;
}