• + 0 comments

    Considering some python specifics, this is quite easy:

    def cubeSum(n, operations):
        result = []
        memory = {}
    
        for operation in operations:
            match operation.split():
                case ['UPDATE', *coords, value]:
                    x, y, z = map(int, coords)
                    memory[(x, y, z)] = int(value)
                    
                case ['QUERY', *coords]:
                    x1, y1, z1, x2, y2, z2 = map(int, coords)
                    s = 0
                    
                    for key, value in memory.items():
                        if x1 <= key[0] <= x2 and y1 <= key[1] <= y2 and z1 <= key[2] <= z2:
                            s += value
                    result.append(s)
        return result