First Scala solution using Map and SortedSet 
IntuitionApproachComplexity

Time complexity:
Initialization:
Dictionary insertion: O(1) per task.
SortedSet insertion: O(logN) per task.
Total for initializati
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
    **Initialization**: 
    Dictionary insertion: O(1) per task.
    SortedSet insertion: O(logN) per task.
    Total for initialization: O(M logM), 
    where M represents the number of tasks, dding M tasks during initialization involves inserting them into both data structures.

    **Add:**
    Dictionary insertion: O(1) per task.
    SortedSet insertion: O(logN) per task.
    Total for initialization: O(log N)

    **Edit:**
    Lookup in the dictionary: O(1).
    Removal from the sorted set: O(logN).
    Update in the dictionary: O(1).
    Insertion into the sorted set: O(logN).
    Total for Edit: O(logN).

    **Rmv:**
    Lookup in the dictionary: O(1).
    Removal from the sorted set: O(logN).
    Removal from the dictionary: O(1).
    Total for Rmv: O(logN).

    **ExecTop:**
    Retrieval of the top element from the sorted set: O(1) for access.
    Removal from the sorted set: O(logN).
    Removal from the dictionary: O(1).
    Total for ExecTop: O(logN).

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```scala []
import scala.collection.mutable.{SortedSet}
import scala.util.control.Breaks._

class TaskManager(_tasks: List[List[Int]]) {
    var map : Map[Int, List[Int]] = Map[Int, List[Int]]()
    //implicit val priorityTaskOrder: Ordering[List[Int]] = Ordering.by(_.apply(0))
    
    implicit val priorityTaskOrder: Ordering[List[Int]] = 
        Ordering.fromLessThan { (p1, p2) =>
            if (p1.apply(0) != p2.apply(0)) p1.apply(0) < p2.apply(0)   // priority
            else p1.apply(1) < p2.apply(1)                              // taskId
        }

    var pq : SortedSet[List[Int]] = SortedSet[List[Int]]()

    _tasks.foreach(e => {
        add(e.apply(0), e.apply(1), e.apply(2))
    })

    def add(userId: Int, taskId: Int, priority: Int): Unit = {
        val v = List(priority, taskId, userId)
        map = map + (taskId -> v)
        pq.add(v)
    }

    def edit(taskId: Int, newPriority: Int): Unit = {
        if (map.contains(taskId)) {
            val v = map.apply(taskId)
            pq.remove(v)
            map = map - taskId
            add(v.apply(2), taskId, newPriority)
        }
    }

    def rmv(taskId: Int): Unit = {
        if (map.contains(taskId)) {
            val v = map.apply(taskId)
            pq.remove(v)
            map = map - taskId
        }       
    }

    def execTop(): Int = {
        var res = -1

        breakable {
            while (pq.size>0) {
                var e = pq.last
                pq.remove(e)

                if (map.contains(e.apply(1))) {
                    val v = map.apply(e.apply(1))
                    if (e.apply(2) == v.apply(2)) {
                        res = e.apply(2)
                        break
                    }
                }
            }
        }
        res
    }

}

/**
 * Your TaskManager object will be instantiated and called as such:
 * val obj = new TaskManager(tasks)
 * obj.add(userId,taskId,priority)
 * obj.edit(taskId,newPriority)
 * obj.rmv(taskId)
 * val param_4 = obj.execTop()
 */
```
['Scala']