[
  {
    "path": "DSA Essentials Solutions/2d Arrays/PascalsTriangle.cpp",
    "content": "//Expected Time Complexity: O(n^3)\n\n//Hint: Use Binomial Coeffiecients\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nint binomialCoeff(int n, int k);\n \n// Function to print first\n// n lines of Pascal's\n// Triangle\nvector<vector<int>> printPascal(int n)\n{\n    // Iterate through every line and\n    // print entries in it\n     vector<vector<int>> res;\n    for (int line = 0; line < n; line++)\n    {\n        // Every line has number of\n        // integers equal to line\n        // number\nvector<int> v;\n        for (int i = 0; i <= line; i++)\n         {v.push_back(binomialCoeff(line, i));}\n\n         res.push_back(v);\n    }\nreturn res;\n}\n \nint binomialCoeff(int n, int k)\n{\n    int res = 1;\n    if (k > n - k)\n    k = n - k;\n    for (int i = 0; i < k; ++i)\n    {\n        res *= (n - i);\n        res /= (i + 1);\n    }\n     \n    return res;\n}\n\n\n\n"
  },
  {
    "path": "DSA Essentials Solutions/2d Arrays/SubmatrixSum.cpp",
    "content": "//Hint: Pre Compute Cumilative Sums of every index i,j.\n\n//Expected Time Complexity:\n// Pre Computing : O(N^2)\n// Queries: O(1)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nint sum(vector<vector<int>> v, int sr, int sc, int er, int ec){\n    int m=v.size();\n    int n=v[0].size();\n    // // int aux[m][n];\n    int M=m;\n    int N=n;\n    vector<vector<int>> aux = v;\n    vector<vector<int>> mat = v;\n    int tli=sr, tlj=sc, rbi=er, rbj=ec;\n      for (int i=0; i<N; i++)\n      aux[0][i] = mat[0][i];\n  \n  // Do column wise sum\n  for (int i=1; i<M; i++)\n      for (int j=0; j<N; j++)\n         aux[i][j] = mat[i][j] + aux[i-1][j];\n  \n  // Do row wise sum\n  for (int i=0; i<M; i++)\n      for (int j=1; j<N; j++)\n         aux[i][j] += aux[i][j-1];\n \n \n    int res = aux[rbi][rbj];\n  \n    // Remove elements between (0, 0) and (tli-1, rbj)\n    if (tli > 0)\n       res = res - aux[tli-1][rbj];\n  \n    // Remove elements between (0, 0) and (rbi, tlj-1)\n    if (tlj > 0)\n       res = res - aux[rbi][tlj-1];\n  \n    // Add aux[tli-1][tlj-1] as elements between (0, 0)\n    // and (tli-1, tlj-1) are subtracted twice\n    if (tli > 0 && tlj > 0)\n       res = res + aux[tli-1][tlj-1];\n  \n    return res;\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/2d Arrays/WavePrint.cpp",
    "content": "//Expected Time Complexity: O(n^2)\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n \n vector<int> WavePrint(int m, int n, vector<vector<int>> arr)\n{\n    vector<int> res;\n    int i, j = n - 1, wave = 1;\n \n    /* m \t- Ending row index\n        n \t- Ending column index\n        i, j \t- Iterator\n        wave \t- for Direction\n        wave = 1 - Wave direction down\n        wave = 0 - Wave direction up   */\n    while (j >= 0) {\n         \n        // Check whether to go in\n        // upward or downward\n        if (wave == 1) {\n             \n            // Print the element of the matrix\n            // downward since the value of wave = 1\n            for (i = 0; i < m; i++)\n                res.push_back(arr[i][j]);           \n            wave = 0;\n            j--;\n        }\n        else {\n             \n            // Print the elements of the\n            // matrix upward since the value\n            // of wave = 0\n            for (i = m - 1; i >= 0; i--)\n               res.push_back(arr[i][j]) ;            \n            wave = 1;\n            j--;\n        }\n    }\nreturn res;\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Arrays/K-rotate.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> kRotate(vector<int> a, int k)\n{\n    vector<int> v;\n    int n = a.size();\n    k = k % n;\n \n    for(int i = 0; i < n; i++)\n    {\n       if(i < k)\n       {\n           v.push_back(a[n + i - k]);\n       }\n       else\n       {\n           v.push_back(a[i - k]);\n       }\n    }\n    return v;\n}\n\n\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Arrays/LargestElement.cpp",
    "content": "//Expected Time Complexity: O(N)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nint largestElement(vector<int> A) {\n    \n     int largestEle = INT_MIN;\n     \n     for (auto element : A ) {\n         largestEle = max(largestEle, element);\n     }\n     \n     return largestEle;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Arrays/LowerBound.cpp",
    "content": "//Expected Time Complexity: O(logN)\n//Hint: Binary Search\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nint lowerBound(vector<int> A, int Val) {\n    \n    int sz = A.size();\n    \n    int l = 0, r = (sz-1);\n    \n    int answer = -1;\n    \n    while (l <= r) {\n        int mid = (l + r) / 2;\n        if (A[mid] > Val) {\n            r = mid-1;\n        }\n        else {\n            answer = A[mid];\n            l = mid+1;\n        }\n    }\n    \n    return answer;\n    \n}"
  },
  {
    "path": "DSA Essentials Solutions/Arrays/MaximumSumSubarray.cpp",
    "content": "//Time complexity: O(n)\n//Hint: Kadane's Algorithm\n\n#include <bits/stdc++.h>\nusing namespace std ;\n\nint maxSumSubarray(vector<int> A) {\n    int n = A.size(), max_sum = *min_element(A.begin(), A.end()), curr_sum = 0;\n    \n    for(int i = 0 ; i < n ; i++){\n        if(curr_sum + A[i] <= 0){\n            curr_sum = A[i];\n        }else{\n            curr_sum += A[i];\n        }\n        \n        max_sum = max(max_sum, curr_sum);\n    }\n    \n    return max_sum;\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Arrays/SortedPairSum.cpp",
    "content": "//Expected Time Complexity: O(N)\n//Hint: Two Pointer Approach\n\n#include<bits/stdc++.h>\nusing namespace std;\n\npair<int, int> closestSum(vector<int> arr, int x){\n    int res_l, res_r;  \n    int n = arr.size();\n    int l = 0, r = n-1, diff = INT_MAX;\n \n    while (r > l)\n    {\n       if (abs(arr[l] + arr[r] - x) < diff)\n       {\n           res_l = l;\n           res_r = r;\n           diff = abs(arr[l] + arr[r] - x);\n       }\n \n       if (arr[l] + arr[r] > x)\n           r--;\n       else \n           l++;\n    }\n    \n    return {arr[res_l], arr[res_r]};\n}"
  },
  {
    "path": "DSA Essentials Solutions/Backtracking/N-QueenWays.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n\n\nint cnt;\n\nint isSafe(int N, int mat[][20], int r, int c)\n{\n    // return 0 if two queens share the same column\n    for (int i = 0; i < r; i++)\n    {\n        if (mat[i][c] == 1) {\n            return 0;\n        }\n    }\n \n    // return 0 if two queens share the same `` diagonal\n    for (int i = r, j = c; i >= 0 && j >= 0; i--, j--)\n    {\n        if (mat[i][j] == 1) {\n            return 0;\n        }\n    }\n \n    // return 0 if two queens share the same `/` diagonal\n    for (int i = r, j = c; i >= 0 && j < N; i--, j++)\n    {\n        if (mat[i][j] == 1) {\n            return 0;\n        }\n    }\n \n    return 1;\n}\n\nvoid solve(int N,int mat[][20], int r)\n{\n    // if `N` queens are placed successfully, print the solution\n    if (r == N)\n    {\n        cnt++;\n        return;\n    }\n \n    // place queen at every square in the current row `r`\n    // and recur for each valid movement\n    for (int i = 0; i < N; i++)\n    {\n        // if no two queens threaten each other\n        if (isSafe(N, mat, r, i))\n        {\n            // place queen on the current square\n            mat[r][i] = 1;\n \n            // recur for the next row\n            solve(N,mat, r + 1);\n \n            // backtrack and remove the queen from the current square\n            mat[r][i] = 0;\n        }\n    }\n}\n \n\nint nQueen(int n){\n    cnt =0;\n    int arr[20][20]={0};\n\n    solve(n,arr,0);\n    return cnt;\n\n}"
  },
  {
    "path": "DSA Essentials Solutions/Backtracking/RatAndMice.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nvoid ratchase(vector<string> a,vector<vector<int>> &b,vector<vector<int>> &v,int i,int j,int n,int m){\n\tif(i==n && j==m){\n\t\tfor(int k=0;k<=n;k++){\n\t\t\tfor(int l=0;l<=m;l++){\n\t\t\t\tv[k][l] = b[k][l];\n\t\t\t}cout<<endl;\n\t\t}\n\t\treturn;\n\t}\n\tif(i!=n && a[i+1][j]!='X' && b[i+1][j]!=1){\n\t\tb[i+1][j]=1;\n\t\tratchase(a,b,v,i+1,j,n,m);\n\t\tb[i+1][j]=0;\n\t}\n\tif(i>0 && a[i-1][j]!='X' && b[i-1][j]!=1){\n\t\tb[i-1][j]=1;\n\t\tratchase(a,b,v,i-1,j,n,m);\n\t\tb[i-1][j]=0;\n\t}\n\tif(j!=m && a[i][j+1]!='X' && b[i][j+1]!=1){\n\t\tb[i][j+1]=1;\n\t\tratchase(a,b,v,i,j+1,n,m);\n\t\tb[i][j+1]=0;\n\t}\n\tif(j>0 && a[i][j-1]!='X' && b[i][j-1]!=1){\n\t\tb[i][j-1]=1;\n\t\tratchase(a,b,v,i,j-1,n,m);\n\t\tb[i][j-1]=0;\n\t}\n\treturn;\n}\nvector<vector<int>> ratAndMice(vector<string> a) {\n    int n = a.size();\n    int m = a[0].size();\n    vector<vector<int>> v(n, vector<int>(m, 0));\n    vector<vector<int>> b(n, vector<int>(m, 0));\n    b[0][0] = 1;\n    \n\tratchase(a,b,v,0,0,n-1,m-1);\n\treturn v;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Backtracking/UniqueSubset.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nset<vector<int>> s;\nvoid recur(vector<int> &nums, vector<int> ans, int i)\n{\n    if(i == nums.size()){\n        sort(ans.begin(), ans.end());\n        s.insert(ans);\n        return;\n    }\n    \n    ans.push_back(nums[i]);\n    recur(nums, ans, i+1);\n    ans.pop_back();\n    recur(nums, ans, i+1);\n}\nvector<vector<int>> uniqueSubsets(vector<int> nums){\n    s.clear();\n    vector<int> ans;\n    recur(nums, ans, 0);\n    vector<vector<int>> v;\n    for(auto x : s) \n        v.push_back(x);\n    return v;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Backtracking/WordBreakProblem.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nint cnt = 0;\nvector<string> v;\nvoid help(string s, int n, string res, vector<string> &word)\n{\n\tfor (int i = 1; i <= n; i++)\n\t{\n\t\tstring ss = s.substr(0, i);\n\t\tint l = word.size();\n\t\tbool flag = false;\n\n\t\tfor (int j = 0; j < l; j++)\n\t\t\tif (word[j] == ss)\n\t\t\t\tflag = true;\n\n\t\tif (flag)\n\t\t{\n\t\t\tif (i == n)\n\t\t\t{\n\t\t\t\tres += ss;\n\t\t\t\t// v.push_back(res);\n\t\t\t\tcnt++;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\thelp(s.substr(i, n - i), n - i, res + ss + \" \", word);\n\t\t}\n\t}\n}\n\nint wordBreak(string s, vector<string> &dictionary)\n{\n\tcnt = 0;\n\t// v.clear();\n\thelp(s, s.size(), \"\", dictionary);\n\t// for (auto x : v) cout << x << '\\n';\n\treturn cnt;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Backtracking/WordSearch.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nbool chk;\nvoid recur(vector<vector<char>>& board, string &word, int i, int j, int k)\n{\n    if(k == word.size())\n    {\n        chk = true;\n        return;\n    }\n    if(i < 0 || j < 0 || i == board.size() || j == board[0].size() || board[i][j] == '-1')\n        return;\n    \n    if(board[i][j] == word[k])\n    {\n        char c = board[i][j];\n        board[i][j] = '-1';\n        recur(board, word, i, j+1, k+1);\n        recur(board, word, i+1, j, k+1);\n        recur(board, word, i, j-1, k+1);\n        recur(board, word, i-1, j, k+1);\n        board[i][j] = c;\n    }\n    return;\n}\nbool wordSearch(vector<vector<char>> &board, string word)\n{\n    chk  = false;\n    for(int i=0; i<board.size(); i++)\n    {\n        for(int j=0; j<board[0].size(); j++)\n        {\n            if(board[i][j]==word[0])\n                recur(board, word, i, j, 0);\n        }\n    }\n    \n    return chk;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Basic Sorting Algorithms/Chopsticks.cpp",
    "content": "//Expected Complexity: O(N logN)\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nint pairSticks(vector<int> length, int D)\n{\n    // your code goes here\n    sort(length.begin(), length.end());\n    int res = 0;\n\n    for(int i=0; i<length.size()-1; i++)\n    {\n        if (length[i + 1] - length[i] <= D) { res++; i++;}\n    }\n\n    return res;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Basic Sorting Algorithms/DefenseKingdom.cpp",
    "content": "//Expected Time Complexity= O(N log N)\n//Find the largest distance from both W and H axis and take their product.\n\n\n\n#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define all(v) v.begin(), v.end()\nint defkin(int W, int H, vector<pair<int, int>> position)\n{\n    // your code goes here\n    vector<pair<int, int>> v = position;\n    int w = W, h = H;\n    vector<ll> x, y;\n    x.push_back(0); y.push_back(0);\n    \n    ll maxx = INT_MIN, maxy = INT_MIN;\n\n    for(int i=0; i<v.size(); i++)\n    {\n        x.push_back(v[i].first), y.push_back(v[i].second);\n    }\n    // x.push_back(W); y.push_back(H);\n    sort(all(x));\n    sort(all(y));\n\n    for (ll i = 1; i < x.size(); i++) maxx = max(maxx, x[i] - x[i - 1] - 1);\n    for (ll i = 1; i < y.size(); i++) maxy = max(maxy, y[i] - y[i - 1] - 1);\n    maxx = max(maxx, W - x[x.size() - 1] );\n    maxy = max(maxy, H- y[y.size() - 1]);\n\n    return (maxx * maxy);\n    \n}"
  },
  {
    "path": "DSA Essentials Solutions/Basic Sorting Algorithms/OptimisedBubbleSort.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> optimizedBubbleSort(vector<int> arr){\n    // your code  goes here\n    int i, j, n=arr.size();\n   bool swapped;\n   for (i = 0; i < n-1; i++)\n   {\n     swapped = false;\n     for (j = 0; j < n-i-1; j++)\n     {\n        if (arr[j] > arr[j+1])\n        {\n           swap(arr[j], arr[j+1]);\n           swapped = true;\n        }\n     }\n \n     // IF no two elements were swapped by inner loop, then break\n     if (swapped == false)\n        break;\n   }\n   \n   return arr;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Basic Sorting Algorithms/SortingCartesianProducts.cpp",
    "content": "//Expected Time Complexity :O(N log N)\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nvector<pair<int, int>> sortCartesian(vector<pair<int, int>> v)\n{\n    sort(v.begin(), v.end());\n    return v;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Basic Sorting Algorithms/SortingWithComparator.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\nbool compare(int a, int b){\n    return a > b;\n}\nvector<int> sortingWithComparator(vector<int> v, bool flag){\n    // your code  goes here\n    if(flag) sort(v.begin(), v.end());\n    else sort(v.begin(), v.end(), compare);\n    return v;\n}"
  },
  {
    "path": "DSA Essentials Solutions/BinarySearchTree/DeleteInBST.cpp",
    "content": "#include <iostream>\nusing namespace std;\nclass node{\n    public:\n     int data;\n     node*left;\n     node*right;\n     node(int d){\n       data=d;\n       left=NULL;\n       right=NULL;\n     }\n };\n \n \n node* deleteNode(node* root, int k){\n    // Base case\n    if (root == NULL)\n        return root;\n \n    // Recursive calls for ancestors of\n    // node to be deleted\n    if (root->data > k) {\n        root->left = deleteNode(root->left, k);\n        return root;\n    }\n    else if (root->data < k) {\n        root->right = deleteNode(root->right, k);\n        return root;\n    }\n \n    // We reach here when root is the node\n    // to be deleted.\n \n    // If one of the children is empty\n    if (root->left == NULL) {\n        node* temp = root->right;\n        delete root;\n        return temp;\n    }\n    else if (root->right == NULL) {\n        node* temp = root->left;\n        delete root;\n        return temp;\n    }\n \n    // If both children exist\n    else {\n \n        node* succParent = root;\n \n        // Find successor\n        node* succ = root->right;\n        while (succ->left != NULL) {\n            succParent = succ;\n            succ = succ->left;\n        }\n \n        // Delete successor.  Since successor\n        // is always left child of its parent\n        // we can safely make successor's right\n        // right child as left of its parent.\n        // If there is no succ, then assign\n        // succ->right to succParent->right\n        if (succParent != root)\n            succParent->left = succ->right;\n        else\n            succParent->right = succ->right;\n \n        // Copy Successor Data to root\n        root->data = succ->data;\n \n        // Delete Successor and return root\n        delete succ;\n        return root;\n    }\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/BinarySearchTree/IsBST.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Node\n{\n  public:\n   int key;\n   Node *left;\n   Node *right;\n\n   Node(int key){\n       this->key = key;\n       left = right  = NULL;\n   }\n};\n\nbool isBSTUtil(Node* node, int min, int max)\n{\n    /* an empty tree is BST */\n    if (node==NULL)\n        return true;\n             \n    /* false if this node violates\n    the min/max constraint */\n    if (node->key < min || node->key > max)\n        return false;\n     \n    /* otherwise check the subtrees recursively,\n    tightening the min or max constraint */\n    return\n        isBSTUtil(node->left, min, node->key) &&\n        isBSTUtil(node->right, node->key, max); \n}\n\nbool isBST(Node * root){\n    //complete this method\n    return isBSTUtil(root, INT_MIN,INT_MAX);\n    \n}\n"
  },
  {
    "path": "DSA Essentials Solutions/BinarySearchTree/MirrorABST.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Node\n{\n  public:\n   int key;\n   Node *left;\n   Node *right;\n\n   Node(int key){\n       this->key = key;\n       left = right  = NULL;\n   }\n};\n\nvoid mirror(Node* node)\n{\n    if (node == NULL)\n        return;\n    else\n    {\n        struct Node* temp;\n         \n        /* do the subtrees */\n        mirror(node->left);\n        mirror(node->right);\n     \n        /* swap the pointers in this node */\n        temp     = node->left;\n        node->left = node->right;\n        node->right = temp;\n    }\n}\n\nNode* mirrorBST(Node * root){\n    //complete this method\n    mirror(root);\n    return root;\n    \n}\n"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/ExpressionTree.cpp",
    "content": "//Expected Time Complexity: O(n)\n  \n\n#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    string key;\n    Node* left, *right;\n};\n\nbool isOp(string data)\n{\n    if(data == \"+\" or data == \"-\" or data == \"*\" or data == \"/\")\n        return true;\n    return false;\n}\n\nint evalTree(Node* root){\n    if(root == NULL) return 0;\n    if(!isOp(root->key)) return stoi(root->key);\n    \n    if(root->key == \"+\") return evalTree(root->left)+evalTree(root->right);\n    if(root->key == \"-\") return evalTree(root->left)-evalTree(root->right);\n    if(root->key == \"*\") return evalTree(root->left)*evalTree(root->right);\n    if(root->key == \"/\") return evalTree(root->left)/evalTree(root->right);\n}"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/K-thLevel.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    int key;\n    Node* left, *right;\n};\n\nvector<int> printKthLevel(Node* root, int k){\n    // your code goes here\n    // Create Queue\n    queue<struct Node*> que;\n \n    // Enqueue the root node\n    que.push(root);\n \n    // Create a set\n    vector<int> s;\n \n    // Level to track\n    // the current level\n    int level = 0;\n    int flag = 0;\n \n    // Iterate the queue till its not empty\n    while (!que.empty()) {\n \n        // Calculate the number of nodes\n        // in the current level\n        int size = que.size();\n \n        // Process each node of the current\n        // level and enqueue their left\n        // and right child to the queue\n        while (size--) {\n            struct Node* ptr = que.front();\n            que.pop();\n \n            // If the current level matches the\n            // required level then add into set\n            if (level == k) {\n \n                // Flag initialized to 1\n                flag = 1;\n \n                // Inserting node data in set\n                s.push_back(ptr->key);\n            }\n            else {\n \n                // Traverse to the left child\n                if (ptr->left)\n                    que.push(ptr->left);\n \n                // Traverse to the right child\n                if (ptr->right)\n                    que.push(ptr->right);\n            }\n        }\n \n        // Increment the variable level\n        // by 1 for each level\n        level++;\n \n        // Break out from the loop\n        // if the Kth Level is reached\n        if (flag == 1)\n            break;\n    }\n    return s;\n}"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/MinDepth.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    int key;\n    Node* left, *right;\n};\n\nint minDepth(Node *root) {\n        // Your code here\n        int res = INT_MAX;\n        queue<pair<Node*, int>> q;\n        int d = 1;\n        q.push({root, d});\n        while(!q.empty())\n        {\n            Node* f = q.front().first;\n            d = 1+q.front().second;\n            if(f->left == NULL && f->right == NULL) \n                res = min(res, q.front().second);\n            q.pop();\n            if(f->left) q.push({f->left, d});\n            if(f->right) q.push({f->right, d});\n        }\n        return res;\n    }"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/RemoveHalfNodes.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    int key;\n    Node* left, *right;\n};\n\nvoid inorder(Node* root, vector<int> &v)\n{\n    if(root == NULL) return;\n    if(root->left) inorder(root->left, v);\n    v.push_back(root->key);\n    if(root->right) inorder(root->right, v);\n}\n\nNode *help(Node *root)\n{\n   //add code here.\n   if(root==NULL) return NULL;\n   if(root->right) root->right = help(root->right);\n   if(root->left) root->left = help(root->left);\n   if( (root->left != NULL && root->right == NULL) or (root->left == NULL && root->right !=NULL) )\n   {\n       if(root->left) root = root->left;\n       else root = root->right;\n       root = help(root);\n   }\n   return root;\n   \n}\n\nvector<int> removeHalfNodes(Node *root)\n{\n   //add code here.\n   root = help(root);\n   vector<int> v;\n   inorder(root, v);\n   return v;\n   \n}"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/SumOfNodes.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    int key;\n    Node* left, *right;\n};\n\nint sumBT(Node* root)\n{\n    // Code here\n    int res = 0;\n    queue<Node*> q;\n    q.push(root);\n    while(!q.empty())\n    {\n        Node* f = q.front();\n        q.pop();\n        if(f->left) q.push(f->left);\n        if(f->right) q.push(f->right);\n        res += f->key;\n    }\n    return res;\n}"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/SymmetricTree.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    int key;\n    Node* left, *right;\n};\nbool isSymmetric(Node* root) {\n        queue<Node*> q1;\n        queue<Node*> q2;\n        if(root == NULL || (root->right==NULL && root->left==NULL)) return true;\n        if(root->right == NULL || root->left == NULL) return false;\n        q1.push(root->left);\n        q2.push(root->right);\n        while(!q1.empty() && !q2.empty())\n        {\n            Node* f1 = q1.front();\n            q1.pop();\n            Node* f2 = q2.front();\n            q2.pop();\n            if(q1.empty() && !q2.empty()) return false;\n            if(!q1.empty() && q2.empty()) return false;\n            if(f1->left==NULL && f2->right!=NULL) return false;\n            if(f1->left!=NULL && f2->right==NULL) return false;\n            if(f1->key != f2->key) return false;\n            if(f1->left) q1.push(f1->left);\n            if(f1->right) q1.push(f1->right);\n            if(f2->right) q2.push(f2->right);\n            if(f2->left) q2.push(f2->left);\n        }\n        if(q1.empty() && q2.empty()) return true;\n        return false;\n    }"
  },
  {
    "path": "DSA Essentials Solutions/BinaryTree/TargetPathSum.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n \nstruct Node {\n    int val;\n    Node* left, *right;\n};\n\nvector<vector<int>> vv;\nvoid help(Node* root, int a, vector<int> &v, int b)\n{\n    if(root == NULL) return;\n    if(root->left == NULL && root->right == NULL)\n    {\n        \n        if(a == b+root->val) \n        {\n            v.push_back(root->val);\n            vv.push_back(v);\n            v.pop_back();\n        }\n        return;\n    }\n    if(root->left)\n    {\n        v.push_back(root->val);\n        help(root->left, a, v, b+root->val);\n        v.pop_back();\n    }\n    if(root->right)\n    {\n        v.push_back(root->val);\n        help(root->right, a, v, b+root->val);\n        v.pop_back();\n    }\n}\nvector<vector<int>> pathSum(Node* root, int targetSum) {\n    vv.clear();\n    vector<int> v;\n    help(root, targetSum, v, 0);\n    return vv;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Bit Manipulation/EarthLevels.cpp",
    "content": "// Expected Time Complexity : O(Log n)\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long convertDecimalToBinary(unsigned long long int n)\n{\n    long long binaryNumber = 0;\n    unsigned long long int remainder, i = 1, step = 1;\n\n    while (n!=0)\n    {\n        remainder = n%2;\n        n /= 2;\n        binaryNumber += remainder*i;\n        i *= 10;\n    }\n    return binaryNumber;\n}\n\nint earthLevel(int k)\n{\n    //your code goes here\n    unsigned long long int binaryNumber, sum = 0;\n    binaryNumber = convertDecimalToBinary(k);\n    \n    while (binaryNumber != 0)\n    {\n        unsigned long long int t;\n        t = binaryNumber%2;\n        sum = sum + t;\n        binaryNumber = binaryNumber/10;\n    }\n    \n    return sum;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Bit Manipulation/ModuloExponentiation.cpp",
    "content": "// Expected Time Complexity : O(Log N)\n// Hint: if a is even, than x^a can be written as (x^(a/2))*(x^(a/2))\n\n#include <iostream>\nusing namespace std;\n \n \nint power(int x, int y, int p)\n{\n    int res = 1;     // Initialize result\n \n    x = x % p; // Update x if it is more than or\n                // equal to p\n  \n    if (x == 0) return 0; // In case x is divisible by p;\n \n    while (y > 0)\n    {\n        // If y is odd, multiply x with result\n        if (y & 1)\n            res = (res*x) % p;\n \n        // y must be even now\n        y = y>>1; // y = y/2\n        x = (x*x) % p;\n    }\n    return res;\n}\n "
  },
  {
    "path": "DSA Essentials Solutions/Bit Manipulation/SubsetSumQueries.cpp",
    "content": "// Expected Time Complexity : O(1) for each query\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nvector<bool> subsetSum(vector<int> v, vector<int> q)\n{\n    int n = q.size();\n    vector<bool> b(n);\n    \n    bitset<10000> bit;\n    bit.reset();\n    bit[0] = 1;\n  \n    for (int i = 0; i < v.size(); ++i)\n        bit |= (bit << v[i]);\n        \n    for(int i=0; i<n; i++)\n    {\n        int x = q[i];\n        bit[x]? b[i]=true : b[i]=false;\n    }\n    \n    return b;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Bit Manipulation/Xoring.cpp",
    "content": "// Expected Time Complexity : O(N)\n// xor of two same elements is 0\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nint xoring(vector<int> v)\n{\n    int res=0;\n    for(auto x : v)  res ^= x;\n    return res;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Divide and Conquer/2DArrayMerge.cpp",
    "content": "\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid merge_row(vector<vector<int>> &mat,int i, int cs, int cm, int ce){\n   vector<int> sorted;\n   int x=cs;\n   int y=cm+1;\n   //cout<<x<<\" \"<<cm<<\" \"<<y<<\" \"<<ce<<endl;\n   while(x<=cm && y<=ce){\n       if(mat[i][x]<mat[i][y]){\n           sorted.push_back(mat[i][x]);\n           x++;\n       }\n       else{\n           sorted.push_back(mat[i][y]);\n           y++;\n       }\n   }\n   \n   \n   while(x<=cm){\n       sorted.push_back(mat[i][x]);\n       x++;\n   }\n   while(y<=ce){\n       sorted.push_back(mat[i][y]);\n       y++;\n   }\n   int k=0;\n   for(int j=cs; j<=ce; j++){\n       mat[i][j]=sorted[k];\n       k++;\n   }\n   return;\n}\nvoid merge_col(vector<vector<int>> &mat,int j, int rs, int rm, int re){\n       vector<int> sorted;\n   int x=rs;\n   int y=rm+1;\n   while(x<=rm && y<=re){\n       if(mat[x][j]<mat[y][j]){\n           sorted.push_back(mat[x][j]);\n           x++;\n       }\n       else{\n           sorted.push_back(mat[y][j]);\n           y++;\n       }\n   }\n   while(x<=rm){\n       sorted.push_back(mat[x][j]);\n       x++;\n   }\n   while(y<=re){\n       sorted.push_back(mat[y][j]);\n       y++;\n   }\n   int k=0;\n   for(int i=rs; i<=re; i++){\n       mat[i][j]=sorted[k];\n       k++;\n   }\n   return;\n}\n\n\nvoid merge(int m, int n, vector<vector<int>> &mat, int rs, int rm, int re,int cs, int cm, int ce){\n    \n    \n    \n    //for sorting rows\n    for(int i=rs; i<=re; i++){\n        merge_row(mat,i,cs,cm,ce);\n    }\n    \n    //for sorting columns\n    for(int j=cs; j<=ce; j++){\n        merge_col(mat,j,rs,rm,re);\n    }\n    return;\n\n}\n\nvoid merge_sort(int m, int n, vector<vector<int>> &mat, int rs, int re, int cs, int ce){\n    //cout<<rs<<\" \"<<re<<endl;\n    //cout<<cs<<\" \"<<ce<<endl;\n     if(rs>=re && cs>=ce){\n         return;\n     }\n\n\n     int rm=(rs+re)/2;\n     int cm=(cs+ce)/2;\n      \n    // cout<<rs<<\" \"<<rm<<\" \"<<re<<\" \"<<cs<<\" \"<<cm<<\" \"<<ce<<endl; \n     \n     \n     //for dividing into subarrays\n     merge_sort(m,n,mat,rs,rm,cs,cm);\n     merge_sort(m,n,mat,rm+1,re,cs,cm);\n     merge_sort(m,n,mat,rs,rm,cm+1,ce);\n     merge_sort(m,n,mat,rm+1,re,cm+1,ce);\n\n     \n    //for merging sorted subarrays\n     merge(m,n,mat,rs,rm,re,cs,cm,ce);\n     return;\n}\n\nvector<vector<int>> mergeSort(int m, int n, vector<vector<int>> v){\n    merge_sort(m,n,v,0,m-1,0,n-1);\n    return v;\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Divide and Conquer/BinarySearchUsingRecursion.cpp",
    "content": "//Expected Time Complexity: O(logn)\n\n#include <bits/stdc++.h>\nusing namespace std;\n  \n#include <bits/stdc++.h>\nusing namespace std;\n  \n// A recursive binary search function. It returns\n// location of x in given array arr[l..r] is present,\n// otherwise -1\nint binary(vector<int> arr, int l, int r, int x)\n{\n    if (r >= l) {\n        int mid = l + (r - l) / 2;\n  \n        // If the element is present at the middle\n        // itself\n        if (arr[mid] == x)\n            return mid;\n  \n        // If element is smaller than mid, then\n        // it can only be present in left subarray\n        if (arr[mid] > x)\n            return binary(arr, l, mid - 1, x);\n  \n        // Else the element can only be present\n        // in right subarray\n        return binary(arr, mid + 1, r, x);\n    }\n  \n    // We reach here when element is not\n    // present in array\n    return -1;\n}\n\nint binarySearch(vector<int> v, int x)\n{\n    // your code goes here\n    \n    int n = v.size();\n    int result = binary(v, 0, n - 1, x);\n    return result;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Dynamic Programming/CoinChange.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nlong long coinChange(int s, int n , vector<int> a, long long dp[500][100])\n{\n    if (n < 0 || s < 0) return 0;\n    if (s == 0) return 1;\n\n    if (dp[s][n] != 0) return dp[s][n];\n    \n    long long op1 = coinChange(s, n - 1, a, dp);\n    long long op2 = coinChange(s - a[n], n, a, dp);\n\n    return dp[s][n] = op1 + op2;\n}\n\nlong long findCombinations(int n, vector<int> coins)\n{\n    long long dp[500][100] = {{0}};\n    return coinChange(n, coins.size()-1, coins, dp);\n}"
  },
  {
    "path": "DSA Essentials Solutions/Dynamic Programming/MinimumPartitioning.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n  \nint findMin(vector<int> arr)\n{\n    int n = arr.size();\n    int sum = 0;\n    for (int i = 0; i < n; i++)\n        sum += arr[i];\n  \n    // Create an array to store results of subproblems\n    bool dp[n + 1][sum + 1];\n  \n    // Initialize first column as true. 0 sum is possible\n    // with all elements.\n    for (int i = 0; i <= n; i++)\n        dp[i][0] = true;\n  \n    // Initialize top row, except dp[0][0], as false. With\n    // 0 elements, no other sum except 0 is possible\n    for (int i = 1; i <= sum; i++)\n        dp[0][i] = false;\n  \n    // Fill the partition table in bottom up manner\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= sum; j++) {\n            // If i'th element is excluded\n            dp[i][j] = dp[i - 1][j];\n  \n            // If i'th element is included\n            if (arr[i - 1] <= j)\n                dp[i][j] |= dp[i - 1][j - arr[i - 1]];\n        }\n    }\n  \n    // Initialize difference of two sums.\n    int diff = INT_MAX;\n  \n    // Find the largest j such that dp[n][j]\n    // is true where j loops from sum/2 t0 0\n    for (int j = sum / 2; j >= 0; j--) {\n        // Find the\n        if (dp[n][j] == true) {\n            diff = sum - 2 * j;\n            break;\n        }\n    }\n    return diff;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Dynamic Programming/OptimalGameStrategy.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n\nint game(int n, vector<int> v, int s, int e){\n\n    if(s==e || s==e-1){\n        return max(v[s],v[e]);\n    }\n\n    int op1=v[s] + min(game(n,v,s+2,e),game(n,v,s+1,e-1));\n    int op2=v[e] + min(game(n,v,s+1,e-1),game(n,v,s,e-2));\n    return max(op1,op2); \n}\n\nint MaxValue(int n, vector<int> v){\n    int res=game(n,v,0,n-1);\n    return res;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Dynamic Programming/Vacation.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing vi = vector<int>;\nusing vl = vector<ll>;\nusing vvl = vector<vl>;\nusing vs = vector<string>;\nusing mi = map<int, int>;\nusing ml = map<ll, ll>;\nusing umi = unordered_map<int, int>;\nusing uml = unordered_map<ll, ll>;\nusing pi = pair<int, int>;\nusing pl = pair<ll, ll>;\nusing ti = tuple<int, int, int>;\nusing tl = tuple<ll, ll, ll>;\nusing vii = vector<pi>;\nusing viii = vector<ti>;\nusing vll = vector<pl>;\nusing vlll = vector<tl>;\n#define mem(dp) memset(dp, -1, sizeof(dp))\n#define aut(a, b) for (auto&(a) : (b))\n#define out(x, v) for (auto&(x) : (v)) cout << x << \" \"; cout << '\\n';\n#define rep(i, n) for (ll (i) = 0; (i) < (n); ++(i) )\n#define repp(i, n) for (ll (i) = 1; (i) <= (n); ++(i) )\n#define all(v) v.begin(), v.end()\n#define fi get<0>\n#define se get<1>\n#define th get<2>\n#define F first\n#define S second\n#define mp make_pair\n#define mt make_tuple\n#define pb push_back\nint topDown(viii &v, int n, int i, int dp[][4], int prev)\n{\n    if (i == n) return 0;\n    if (dp[i][prev] != -1) return dp[i][prev];\n\n    int op1 = INT_MIN, op2 = INT_MIN, op3 = INT_MIN;\n\n    if (prev != 1) op1 = fi(v[i]) + topDown(v, n, i + 1, dp, 1);\n    if (prev != 2) op2 = se(v[i]) + topDown(v, n, i + 1, dp, 2);\n    if (prev != 3) op3 = th(v[i]) + topDown(v, n, i + 1, dp, 3);\n\n    return dp[i][prev] = max(op1, max(op2, op3));\n}\nint vacation(vector<int> a, vector<int> b, vector<int> c)\n{\n    viii v;\n    int n = a.size();\n    rep(i, n)\n    {\n        v.pb(mt(a[i], b[i], c[i]));\n    }\n    int dp[n][4];\n    mem(dp);\n    return topDown(v, n, 0, dp, 0);\n}"
  },
  {
    "path": "DSA Essentials Solutions/Graphs/AllPathsFromSourceToTarget.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\nvoid dfs(vector<vector<int>>& graph, vector<vector<int>>& result, vector<int> path, int src, int dst) {\n    path.push_back(src);\n    if(src == dst) {\n        result.push_back(path);\n        return;\n    }\n\n    for(auto node : graph[src])\n        dfs(graph, result, path, node, dst);\n}\nvector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {\n    vector<vector<int>> paths; vector<int> path;\n    int nodes = graph.size();\n    if(nodes == 0) return paths;\n    dfs(graph, paths, path, 0, nodes - 1);\n    return paths;\n}\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Graphs/FindStarInGraph.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nint findCenter(vector<vector<int>>& v) {\n            \n           pair<int, int> f={v[0][0],v[0][1]};\n           pair<int, int> s={v[1][0],v[1][1]};\n        \n        if(f.first==s.first){\n            return f.first;\n        }\n        else if(f. first==s.second){\n            return f.first;\n        }\n        else if(f.second==s.first){\n            return f.second;\n        }\n        else{\n            return f.second;\n        }\n        \n        \n        \n        \n    }\n"
  },
  {
    "path": "DSA Essentials Solutions/Graphs/KeysAndRooms.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nbool canVisitAllRooms(vector<vector<int>>& rooms) {\n        unordered_map<int,bool> map;\n        int n=rooms.size();\n        for(int i=0;i<n;i++){\n            map[i]=false;\n        }\n        queue<int> q;\n        q.push(0);\n        while(!q.empty()){\n            int k=q.size();\n            while(k--){\n                int a=q.front();\n                q.pop();\n                map[a]=true;\n                for(int j=0;j<rooms[a].size() && rooms[a].size()!=0;j++){\n                    if(map[rooms[a][j]]==false){\n                        q.push(rooms[a][j]);    \n                    }     \n                }\n            }\n        }\n        for(auto i:map){\n            if(i.second==false){\n                return false;\n            }\n        }\n        return true;\n    }"
  },
  {
    "path": "DSA Essentials Solutions/Hashing/ArrayIntersection.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n\nvector<int> intersection(vector<int>& nums1, vector<int>& nums2) {\n        \n        unordered_map<int,int> map;\n        vector<int> result;\n        \n        for(int i=0;i<nums1.size();i++)\n        {\n            map[nums1[i]]++;\n        }      \n        for(int i=0;i<nums2.size();i++)\n        {\n            if(map[nums2[i]] > 0)\n            {\n                result.push_back(nums2[i]);\n                map[nums2[i]] = 0;\n            }\n        }    \n        sort(result.begin(), result.end());\n        return result;   \n    }\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Hashing/KSumSubarray.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n\nint longestSubarrayKSum(vector<int> arr,int k){\n    int n = arr.size();\n\tunordered_map<int,int> m;\n\tint pre = 0;\n\n\tint len = 0;\n\n\tfor(int i=0;i<n;i++){\n\t\tpre += arr[i];\n\n\t\tif(pre==k){\n\t\t\tlen = max(len,i+1);\n\t\t}\n\n\t\tif(m.find(pre-k)!=m.end()){\n\t\t\tlen = max(len,i - m[pre-k]);\n\t\t}\n\t\telse{\n\t\t\t//store the first occ\n\t\t\tm[pre] = i;\n\t\t}\n\n\t}\n\treturn len;\n\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Heaps/MaximumProduct.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n\nint maxProduct(vector<int>& nums) {\n        priority_queue<int> q;\n        for(int i=0; i<nums.size(); i++){\n            q.push((nums[i]-1));\n        }\n        \n        int p=q.top();\n        q.pop();\n        return p*q.top();\n    }\n\n\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Heaps/ReduceArraySizeToHalf.cpp",
    "content": "\n#include<bits/stdc++.h>\nusing namespace std;\n\nint minSetSize(vector<int>& arr) {\n        int n=arr.size();\n        priority_queue<int> q;\n        unordered_map<int,int> mp;\n        for(int i=0; i<n; i++){\n            mp[arr[i]]++;\n        }\n        for(auto pair:mp){\n            q.push(pair.second);\n        }\n        int sum=0;\n        int cnt=0;\n        while(n-sum>n/2){\n            sum+=q.top();\n            q.pop();\n            cnt++;\n            \n        }\n        return cnt;\n    }\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Heaps/RelativeRanks.cpp",
    "content": " #include<bits/stdc++.h>\nusing namespace std;\n   vector<string> findRelativeRanks(vector<int>& score) {\n        priority_queue<pair<int,int>> pq;\n        for(int i=0; i<score.size(); i++){\n            pq.push({score[i],i});\n        }\n       \n    int n= score.size();\n    \n    vector<string> vec(n);\n   \n    \n    int cnt=0;\n    \n    \n    while(!pq.empty()){\n        cnt++;\n        \n        if(cnt==1){\n            cout<<\"hey\"<<endl;\n            vec[pq.top().second].append(\"Gold Medal\");\n        }\n        else if(cnt==2){\n            vec[pq.top().second].append(\"Silver Medal\");\n        }\n        else if(cnt==3){\n            vec[pq.top().second].append(\"Bronze Medal\");\n        }\n        else {\n            vec[pq.top().second].append(to_string(cnt));\n        }\n        pq.pop();\n    }\n    return vec;\n    }\n\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Heaps/WeakestRows.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n\nvector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n        priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq; //Min-heap\n        for(int i=0;i<mat.size();i++)\n        {\n            int count=0;\n            for(int j=0;j<mat[i].size();j++)\n            {\n                if(mat[i][j]==1)\n                {\n                    count++; //Counting the number of soldiers in each case\n                }\n            }\n            pq.push(make_pair(count,i));\n        }\n        vector<int> x;\n        while(k>0)\n        {\n            pair<int,int> temp=pq.top();\n            x.push_back(temp.second);\n            pq.pop();\n            k--;\n        }\n        return x;\n    }\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Linked List/AlternateMerge.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nclass node{\npublic:\n\tint data;\n\tnode* next;\n\n\tnode(int data){\n\t\tthis->data = data;\n\t\tnext = NULL;\n\t}\n};\n\nnode* apend(node* root, int d){\n    if(root == NULL) return new node(d);\n    node* temp = root;\n    while(temp->next){\n        temp = temp->next;\n    }\n    temp->next = new node(d);\n    return root;\n}\n\nnode* alternateMerge(node * root1, node* root2){\n    //Complete this function \n    node* root = NULL;\n    if(!root1) return root2;\n    if(!root2) return root1;\n    while(root1 && root2){\n        root = apend(root, root1->data);\n        root = apend(root, root2->data);\n        root1 = root1->next;\n        root2 = root2->next;\n    }\n    if(root1){\n        while(root1){\n            root = apend(root, root1->data);\n            root1 = root1->next;\n        }\n    }\n    if(root2){\n        while(root2){\n            root = apend(root, root2->data);\n            root2 = root2->next;\n        }\n    }\n    \n    return root;\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Linked List/BubbleSortOnLinkedList.cpp",
    "content": "//Expected Time Complexity: O(n^2)\n\n#include <iostream>\nusing namespace std;\nclass node\n{\npublic:\n    int data;\n    node *next;\n    node(int data)\n    {\n        this->data = data;\n        this->next = NULL;\n    }\n};\n \n \nint len(node* head)\n{\n    node* temp = head ;\n    int i = 0 ;\n     while(temp!=NULL)\n     {\n         i++;\n         temp=temp->next ;\n     }\n    \n    return i ;\n}\nnode* bubble_sort_LinkedList_itr(node* head)\n{\n    int n = len(head)-1;\n  \n   while(n--)\n \n   {\n       node* prev =NULL;\n    node*cur = head;\n    while(cur->next!=NULL)\n    {\n        if(cur->data >=cur->next->data)\n        {\n            \n            if(prev==NULL)\n            {\n                //first node\n                node* nxt = cur->next ;\n                cur->next = nxt->next ;\n                nxt->next = cur ;\n               prev=nxt ;\n                head = prev ;\n               \n                \n            }\n            \n            else\n            {\n                \n                node* nxt = cur->next ;\n                prev->next = nxt ;\n                cur->next = nxt->next ;\n                nxt->next = cur ;\n                prev = nxt ;\n              \n                \n            }\n            \n        }\n        else\n        {\n           \n             prev = cur ; \n            cur=cur->next ;\n           \n        }\n        \n        \n    \n    }\n       \n   }\n   \n    \n    \n    return head ;\n    \n}\n \n"
  },
  {
    "path": "DSA Essentials Solutions/Linked List/DeleteTail.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nclass node{\npublic:\n\tint data;\n\tnode* next;\n    \n\tnode(int data){\n\t\tthis->data = data;\n\t\tnext = NULL;\n\t}\n};\n\nnode* deleteTail(node * head){\n    //Complete this function \n     if (head == NULL)\n        return NULL;\n \n    if (head->next == NULL) {\n        delete head;\n        return NULL;\n    }\n \n    // Find the second last node\n    node* second_last = head;\n    while (second_last->next->next != NULL)\n        second_last = second_last->next;\n \n    // Delete last node\n    delete (second_last->next);\n \n    // Change next of second last\n    second_last->next = NULL;\n \n    return head;\n}\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Linked List/KthLastElement.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n\nclass node{\npublic:\n\tint data;\n\tnode* next;\n\n\tnode(int data){\n\t\tthis->data = data;\n\t\tnext = NULL;\n\t}\n};\n\nint kthLastElement(node * head,int k){\n    //Complete this function to return kth last element\n    node * fast = head;\n    node * slow = head;\n    \n    int cnt = 0;\n    while(cnt < k){\n        fast = fast->next;\n        cnt++;\n    }\n    \n    while(fast!=NULL){\n        slow = slow->next;\n        fast = fast->next;\n    }\n    \n    return slow->data;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Queues/FirstNonRepeatingLetter.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst int MAX_CHAR = 26;\n\nvector<char> firstnonrepeating(vector<char> str)\n{\n\tqueue<char> q;\n    vector<char> v;\n\tint charCount[MAX_CHAR] = { 0 };\n\n\tfor (int i = 0; i<str.size(); i++) {\n\n\t\tq.push(str[i]);\n\n\t\tcharCount[str[i] - 'a']++;\n\n\t\twhile (!q.empty()) {\n\t\t\tif (charCount[q.front() - 'a'] > 1)\n\t\t\t\tq.pop();\n\t\t\telse {\n\t\t\t\tv.push_back(q.front());\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (q.empty())\n\t\t\tv.push_back('0');\n\t}\n\treturn v;\n}\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Queues/InterleaveTwoHalvesOfQueue.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nqueue<int> interLeave(queue<int> q){\n    int n=q.size();\n\tqueue<int> q1, q2; \n\tfor (int i=0;i<(n/2);i++) { \n\t\tq1.push(q.front()); \n\t\tq.pop(); //Expected Time Complexity: O(2^n)\n\n\n\t} \n\tfor (int i=0;i<(n/2);i++) { \n\t\tq2.push(q.front()); \n\t\tq.pop(); \n\t} \n\n\tfor (int i=0;i<(n/2);i++) { \n\t\tq.push(q1.front()); \n\t\tq1.pop(); \n\t\tq.push(q2.front()); \n\t\tq2.pop(); \n\t} \n    return q;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Queues/SortQueueWithConstantSpace.cpp",
    "content": "#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint minIndex(queue<int> &q, int sortedIndex)\r\n{\r\n    int min_index = -1;\r\n    int min_val = INT_MAX;\r\n    int n = q.size();\r\n    for (int i=0; i<n; i++)\r\n    {\r\n        int curr = q.front();\r\n        q.pop();  \r\n        \r\n        if (curr <= min_val && i <= sortedIndex)\r\n        {\r\n            min_index = i;\r\n            min_val = curr;\r\n        }\r\n        q.push(curr); \r\n    }\r\n    return min_index;\r\n}\r\n\r\nvoid insertMinToRear(queue<int> &q, int min_index)\r\n{\r\n    int min_val;\r\n    int n = q.size();\r\n    for (int i = 0; i < n; i++)\r\n    {\r\n        int curr = q.front();\r\n        q.pop();\r\n        if (i != min_index)\r\n            q.push(curr);\r\n        else\r\n            min_val = curr;\r\n    }\r\n    q.push(min_val);\r\n}\r\n  \r\nvoid sortQueue(queue<int> &q)\r\n{\r\n    for (int i = 1; i <= q.size(); i++)\r\n    {\r\n        int min_index = minIndex(q, q.size() - i);\r\n        insertMinToRear(q, min_index);\r\n    }\r\n}\r\n\r\nqueue<int> sortqueue(queue<int> &q)\r\n{\r\n    sortQueue(q);\r\n    return q;\r\n}\r\n  "
  },
  {
    "path": "DSA Essentials Solutions/Recursion/2DArrayMerge.cpp",
    "content": "Hint: Divide, sort row-wise, sort col-wise\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid merge_row(vector<vector<int>> &mat,int i, int cs, int cm, int ce){\n   vector<int> sorted;\n   int x=cs;\n   int y=cm+1;\n   //cout<<x<<\" \"<<cm<<\" \"<<y<<\" \"<<ce<<endl;\n   while(x<=cm && y<=ce){\n       if(mat[i][x]<mat[i][y]){\n           sorted.push_back(mat[i][x]);\n           x++;\n       }\n       else{\n           sorted.push_back(mat[i][y]);\n           y++;\n       }\n   }\n   \n   \n   while(x<=cm){\n       sorted.push_back(mat[i][x]);\n       x++;\n   }\n   while(y<=ce){\n       sorted.push_back(mat[i][y]);\n       y++;\n   }\n   int k=0;\n   for(int j=cs; j<=ce; j++){\n       mat[i][j]=sorted[k];\n       k++;\n   }\n   return;\n}\nvoid merge_col(vector<vector<int>> &mat,int j, int rs, int rm, int re){\n       vector<int> sorted;\n   int x=rs;\n   int y=rm+1;\n   while(x<=rm && y<=re){\n       if(mat[x][j]<mat[y][j]){\n           sorted.push_back(mat[x][j]);\n           x++;\n       }\n       else{\n           sorted.push_back(mat[y][j]);\n           y++;\n       }\n   }\n   while(x<=rm){\n       sorted.push_back(mat[x][j]);\n       x++;\n   }\n   while(y<=re){\n       sorted.push_back(mat[y][j]);\n       y++;\n   }\n   int k=0;\n   for(int i=rs; i<=re; i++){\n       mat[i][j]=sorted[k];\n       k++;\n   }\n   return;\n}\n\n\nvoid merge(int m, int n, vector<vector<int>> &mat, int rs, int rm, int re,int cs, int cm, int ce){\n    \n    \n    \n    //for sorting rows\n    for(int i=rs; i<=re; i++){\n        merge_row(mat,i,cs,cm,ce);\n    }\n    \n    //for sorting columns\n    for(int j=cs; j<=ce; j++){\n        merge_col(mat,j,rs,rm,re);\n    }\n    return;\n\n}\n\nvoid merge_sort(int m, int n, vector<vector<int>> &mat, int rs, int re, int cs, int ce){\n    //cout<<rs<<\" \"<<re<<endl;\n    //cout<<cs<<\" \"<<ce<<endl;\n     if(rs>=re && cs>=ce){\n         return;\n     }\n\n\n     int rm=(rs+re)/2;\n     int cm=(cs+ce)/2;\n      \n    // cout<<rs<<\" \"<<rm<<\" \"<<re<<\" \"<<cs<<\" \"<<cm<<\" \"<<ce<<endl; \n     \n     \n     //for dividing into subarrays\n     merge_sort(m,n,mat,rs,rm,cs,cm);\n     merge_sort(m,n,mat,rm+1,re,cs,cm);\n     merge_sort(m,n,mat,rs,rm,cm+1,ce);\n     merge_sort(m,n,mat,rm+1,re,cm+1,ce);\n\n     \n    //for merging sorted subarrays\n     merge(m,n,mat,rs,rm,re,cs,cm,ce);\n     return;\n}\n\nvector<vector<int>> mergeSort(int m, int n, vector<vector<int>> v){\n    merge_sort(m,n,v,0,m-1,0,n-1);\n    return v;\n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Recursion/AllOccurences.cpp",
    "content": "//Expected Time Complexity: O(N)\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nvector<int> vec;\n\n\nvoid helper(int k, vector<int> v, int i){\n    if(i==v.size()){\n        return;\n    }\n    if(v[i]==k){\n        vec.push_back(i);\n        \n    }\n    helper(k,v,i+1);\n    return;\n}\n\nvector<int> findAllOccurences(int k, vector<int> v){\n       vec.clear();\n       helper(k,v,0);\n       return vec;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Recursion/BinaryStrings.cpp",
    "content": "//Expected Time Complexity: O(2^n)\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nvector<string> v;\n\nvoid helper(string str,int n,int i){\n    if(i==n){\n        v.push_back(str);\n        return;\n    }\n    string s1= str;\n    s1.push_back('0');\n    helper(s1,n,i+1);\n\n    if(i>0 && str[i-1]=='0'){\n       str.push_back('1');\n       helper(str,n,i+1);\n    }\n    else if(i==0){\n        str.push_back('1');\n        helper(str,n,i+1);\n    }\n\n    return;\n}\n\nvector<string> binaryStrings(int n){\n     v.clear();\n     string str;\n     helper(str,n,0);\n     return v;\n\n}"
  },
  {
    "path": "DSA Essentials Solutions/Recursion/FriendsParty.cpp",
    "content": "//Expected Time Complexity: O(2^n)\n\n#include <iostream>\nusing namespace std;\n\nint help(int n)\n{\n    if (n <= 0) return 0;\n\tif(n == 2 || n == 1) return n;\n\treturn help(n - 1) + (n - 1) * help(n - 2);\n}\n\nint friendsPairing(int n){\n    \n    return help(n);\n    \n}"
  },
  {
    "path": "DSA Essentials Solutions/Recursion/PrintIncreasingNumbers.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nvoid help(int i, int n, vector<int> &v)\n{\n    if(i > n) return;\n    v.push_back(i);\n    help(i+1, n, v);\n}\n\nvector<int> increasingNumbers(int N) {\n    vector<int> v;\n    help(1, N, v);\n    return v;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Recursion/TilingProblem.cpp",
    "content": "//Expected Time Complexity: O(2^n)\n\n#include <iostream>\nusing namespace std;\n\nint tiles(int n,int m){\n    if(n<m) return 1;\n\tint op1 = tiles(n-1, m);\n\tint op2 = tiles(n-m, m);\n\treturn (op1 + op2);\n}\n\nint tillingProblem(int n, int m){\n    return tiles(n, m);\n}\n\n"
  },
  {
    "path": "DSA Essentials Solutions/Stacks/DuplicateParenthesis.cpp",
    "content": "\n//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nbool duplicateParentheses(string str){\n    \n    stack<char> Stack;\n  \n    for (char ch : str)\n    {\n        if (ch == ')')\n        {\n            char top = Stack.top();\n            Stack.pop();\n  \n            int elementsInside = 0;\n            while (top != '(')\n            {\n                elementsInside++;\n                top = Stack.top();\n                Stack.pop();\n            }\n            if(elementsInside < 1) {\n                return true;\n            }\n        }\n  \n        else\n            Stack.push(ch);\n    }\n  \n    return false;\n    \n}\n"
  },
  {
    "path": "DSA Essentials Solutions/Stacks/MaximumRectangularAreaInHistogram.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include<bits/stdc++.h>\nusing namespace std;\n \nint getMaxArea(vector<int> hist)\n{\n    int n = hist.size();\n    stack<int> s;\n \n    int max_area = 0; \n    int tp; \n    int area_with_top;\n \n    int i = 0;\n    while (i < n)\n    {\n        if (s.empty() || hist[s.top()] <= hist[i])\n            s.push(i++);\n        else\n        {\n            tp = s.top();  \n            s.pop();  \n            area_with_top = hist[tp] * (s.empty() ? i :\n                                   i - s.top() - 1);\n \n            if (max_area < area_with_top)\n                max_area = area_with_top;\n        }\n    }\n \n    while (s.empty() == false)\n    {\n        tp = s.top();\n        s.pop();\n        area_with_top = hist[tp] * (s.empty() ? i :\n                                i - s.top() - 1);\n \n        if (max_area < area_with_top)\n            max_area = area_with_top;\n    }\n \n    return max_area;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Stacks/NextGreaterElement.cpp",
    "content": "\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> nextGreaterElement(vector<int> arr){\n    int n = arr.size();\n    vector<int> arr1(n, 0);\n    stack<int> s;\n \n    for (int i = n - 1; i >= 0; i--)\n    {\n        while (!s.empty() && s.top() <= arr[i])\n            s.pop();\n \n        if (s.empty())\n            arr1[i] = -1;        \n        else\n            arr1[i] = s.top();       \n \n        s.push(arr[i]);\n    }\n        \n    return arr1;\n}\n    \n"
  },
  {
    "path": "DSA Essentials Solutions/Stacks/ReverseANumberUsingStack.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nint reverse(int n){\n    \n    int number = n;\n    stack <int> st;\n    while (number != 0) \n    {\n        st.push(number % 10);\n        number = number / 10;\n    }\n    \n    int rev = 0;\n    int i = 1;\n      \n    while (!st.empty()) \n    {\n        rev = rev + (st.top() * i);\n        st.pop();\n        i = i * 10;\n    }\n      \n    return rev;\n\t\n}"
  },
  {
    "path": "DSA Essentials Solutions/Stacks/StockSpanProblem.cpp",
    "content": "//Expected Time Complexity: O(n)\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nvector<int> stockSpanner(vector<int> &a){\n\tstack <int> s;\n\tint n = a.size();\n\ts.push(0);\n\tvector<int> arr(n, 1);\n\tfor (int i = 1; i < n; i++) {\n\t\twhile (!s.empty() and a[s.top()] <= a[i]) {\n\t\t\ts.pop();\n\t\t}\n\t\tif (!s.empty()) {\n\t\t\tarr[i] = i - s.top();\n\t\t} else arr[i] = i + 1;\n\t\ts.push(i);\n\t}\n\treturn arr;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Strings/ArePermutation.cpp",
    "content": "//Expected Time Complexity= O(N log N)\n//Hint: Permuatations are just different arrangements of same alphabets. Can you make the arrangement same?\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n \nbool arePermutation(string str1, string str2)\n{\n    // Get lenghts of both strings\n    int n1 = str1.length();\n    int n2 = str2.length();\n \n    // If length of both strings is not same,\n    // then they cannot be Permutation\n    if (n1 != n2)\n      return false;\n \n    // Sort both strings\n    sort(str1.begin(), str1.end());\n    sort(str2.begin(), str2.end());\n \n    // Compare sorted strings\n    for (int i = 0; i < n1;  i++)\n       if (str1[i] != str2[i])\n         return false;\n \n    return true;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Strings/BinaryStringToNumber.cpp",
    "content": "Expected Time Complexity : O(N)\n\n\n#include <iostream>\n#include <string>\nusing namespace std;\n \n// Function to convert binary to decimal\nint binaryToDecimal(string n)\n{\n    string num = n;\n    int dec_value = 0;\n \n    // Initializing base value to 1, i.e 2^0\n    int base = 1;\n \n    int len = num.length();\n    for (int i = len - 1; i >= 0; i--) {\n        if (num[i] == '1')\n            dec_value += base;\n        base = base * 2;\n    }\n \n    return dec_value;\n}\n "
  },
  {
    "path": "DSA Essentials Solutions/Strings/CheckPalindrome.cpp",
    "content": "Expected Time Complexity : O(N)\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nbool isPalindrome(string str)\n{\n    // Start from leftmost and rightmost corners of str\n    int l = 0;\n    int h = str.length() - 1;\n \n    // Keep comparing characters while they are same\n    while (h > l)\n    {\n        if (str[l++] != str[h--])\n        {\n            return false;\n        }\n    }\n    return true;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Strings/RemoveDuplicates.cpp",
    "content": "Expected Time Complexity : O(N)\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nstring removeDuplicate(string s){\n    // your code goes here\n    set<char> ss(s.begin(), s.end());\n    string str;\n \n    for (auto x : ss)\n       str.push_back(x);\n \n    return str;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Strings/StringCompression.cpp",
    "content": "Expected Time Complexity : O(N)\n\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nint compress(vector<char>& chars) {\n    \n\tint count_=1;\n    string ans;\n\t\n    for(int i=0;i<chars.size();i++)\n    {\n        while(i<chars.size()-1 && chars[i+1] == chars[i])\n        {\n            count_++;\n            i++;\n        }\n        ans += chars[i];\n        if(count_ == 1)\n        {\n            continue;\n        }\n        ans += to_string(count_);\n        count_ = 1;\n    }\n    \n     chars.clear();\n    \n     for(int i=0;i<ans.size();i++)\n     {\n          chars.push_back(ans[i]);\n     } \n \n    return chars.size();\n}"
  },
  {
    "path": "DSA Essentials Solutions/Strings/VowelFind.cpp",
    "content": "Expected Time Complexity : O(N)\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nstring vowel(string S){\n    // your code goes here\n    string out;\n    for(auto x : S){\n        if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u') out.push_back(x);\n    }\n    return out;\n} "
  },
  {
    "path": "DSA Essentials Solutions/Trie/PrefixStrings.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass node{\n    public:\n    char ch;\n    unordered_map<char,node*> next;\n    bool isTerminal;\n    node(char a){\n        ch=a;\n        bool isTerminal=false;\n    }\n};\nclass Trie{\n    public:\n    node*root= new node('\\0');\n    \n    void insert(string str){\n\n        node*temp=root;\n        for(int i=0; i<str.length(); i++){\n           if(temp->next.count(str[i])==0){\n               temp->next[str[i]]=new node(str[i]);\n           }\n           temp=temp->next[str[i]];\n        }\n        temp->isTerminal=true;\n        return;\n    }\n    void dfs(node*temp, vector<string> &v, string word ){\n        if(temp->isTerminal){\n            v.push_back(word);\n        }\n        if(temp->next.empty()){\n            return;\n        }\n        for(auto p:temp->next){\n          word.push_back(p.first);\n          dfs(temp->next[p.first],v,word);\n          word.pop_back();\n        }\n        return;\n    }\n\n    \n\n    vector<string> find(string str){\n        vector<string> v;\n        node* temp=root;\n        string word=\"\";\n        for(int i=0; i<str.length(); i++){\n           if(temp->next.count(str[i])==0){\n               return v;\n           }\n           word.push_back(str[i]);\n           temp=temp->next[str[i]];\n        }\n        if(temp->isTerminal){\n            v.push_back(word);\n        }\n        dfs(temp,v,word);\n        sort(v.begin(),v.end());\n        return v;\n    }\n\n    \n    \n\n};\n\n\n\nvector<string> findPrefixStrings(vector<string> words, string prefix){\n        Trie t;\n        for(auto s:words){\n            t.insert(s);\n        }\n        vector<string> res=t.find(prefix);\n        return res;\n    }\n"
  },
  {
    "path": "DSA Essentials Solutions/Vectors/MakeZeroes.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nvector<vector<int>> makeZeroes(vector<vector<int>> arr){\n    // your code goes here\n    vector<int> r,c;\n    int n = arr.size(), m = arr[0].size();\n    \n    for(int i=0; i<n; i++){\n        for(int j=0; j<m; j++){\n            if(arr[i][j] == 0){\n                r.push_back(i); c.push_back(j);\n            }\n        }\n    }\n    \n    for(auto x : r){\n        for(int i=0; i<n; i++){\n            arr[x][i] = 0;\n        }\n    }\n    for(auto x : c){\n        for(int i=0; i<n; i++){\n            arr[i][x] = 0;\n        }\n    }\n    \n    return arr;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Vectors/RotateImage.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nvoid rotate(vector<vector<int>>& matrix) {\n        int n = matrix.size();\n        int a = 0;\n        int b = n-1;\n        while(a<b){\n            for(int i=0;i<(b-a);++i){\n                swap(matrix[a][a+i], matrix[a+i][b]);\n                swap(matrix[a][a+i], matrix[b][b-i]);\n                swap(matrix[a][a+i], matrix[b-i][a]);\n            }\n            ++a;\n            --b;\n        }\n    }\n"
  },
  {
    "path": "DSA Essentials Solutions/Vectors/SortFruits.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nbool comp(pair<string,int> a, pair<string, int> b){\n    return a.second < b.second;\n}\n\nvector<pair<string,int>> sortFruits(vector<pair<string,int>> v, string S){\n    // your code  goes here\n    if(S==\"name\") sort(v.begin(), v.end());\n    else sort(v.begin(), v.end(), comp);\n    return v;\n}"
  },
  {
    "path": "DSA Essentials Solutions/Vectors/SortingCabs.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\nbool comp(pair<int,int> a, pair<int, int> b){\n    float x = sqrt((a.first*a.first) + (a.second*a.second));\n    float y = sqrt((b.first*b.first) + (b.second*b.second));\n    return x < y;\n}\n\nvector<pair<int,int>> sortCabs(vector<pair<int,int>> v){\n    // your code  goes here\n    sort(v.begin(), v.end(), comp);\n    return v;\n}"
  }
]