Key Sum Management
A quick note: I changed the input 'operations' to a 2D String array to accommodate the 'Re' and 'Ro' entries. Other than this modification, the question should match the original prompt about 98% 🦉
You are given an initial key tree. A level is the number of parent keys corresponding to a given key of the key tree. Initial values of keys are 0.
Example:
Key 1 with value X1 would be at level 0.
Key 2, Key 3 at level 1, and so on.
There is a sequence of Rotation and Rekey operations that can happen:
For Example:
Ro 1 9 would give us:
Ro 1 4 would give us:
Given an initial tree with n nodes and q operations sequence of Ro and Re operations, find the sum of values for all the keys.
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.