Category: cpp-unordered_map

Queries to find the sum of weights of all nodes with vertical width from given range in a Binary Tree

  #include using namespace std;  struct Node {    int data;    Node* left;    Node* right;};  Node* newNode(int d){    Node* n = new Node;    n->data = d;    n->left = NULL;    n->right = NULL;    return n;}  void findwt(Node* root, int wt[],            map& um,            int width = 0){        if (root == NULL) {        return;    }              um[width] += wt[root->data];          findwt(root->left, wt, um,           width – 1);          findwt(root->right, wt, um,           width + 1);}  void solveQueries(int wt[], Node* root,                  vector queries){            map um;          findwt(root, wt, um);              int x = 0;          for […]

Continue Reading

Number of substrings having an equal number of lowercase and uppercase letters

Number of substrings having an equal number of lowercase and uppercase lettersGiven string S consisting of lowercase and uppercase letters, the task is to find the number of substrings having the equal number of lowercase and uppercase letters.Examples:Input: S = “gEEk”Output: 3Explanation:Following are the substrings having the equal number of lowercase and uppercase letters:“gE”“gEEk”“Ek”Therefore, the […]

Continue Reading