5
void fun(TreeNode *root, int l, map<int, vector<int>> &m) {6
if (root == NULL) return; // If root is NULL it will return7
m[l].push_back(root->val); // With level as key inserting the value to the vector8
fun(root->left, l + 1, m); // passing the left with level + 19
fun(root->right, l + 1, m); // passing right with level + 111
int deepestLeavesSum(TreeNode *root) {12
map<int, vector<int>> m; // Map with key as level and value of vector for storing the values13
fun(root, 0, m); // A void fun with map and level as 014
auto itr = m.rbegin(); // Hence we need the leaves node the nodes are15
// present in last level16
int sum = 0; // Sum Variable17
for (int i = 0; i < itr->second.size(); i++) {18
sum += itr->second[i];