[
  {
    "path": "35_hacker_two_strings.cpp",
    "content": "//\n//  main.cpp\n//  Lecture 34\n//\n//  Created by Prince  Kumar on 17/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//                      HACKER EARTH\n\n//       --- **    Problems on Two Strings   ** ---           //\n\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        string s1,s2; cin>>s1>>s2;\n        // declare array for s1 and s2;\n        \n        // for s1\n        int a[26]={0};\n        \n        // for s2\n        int b[26]={0};\n        \n        // length of string\n        int k = (int)s1.size();\n        \n        for(int i=0;i<k;i++)\n        {\n            int x = s1[i]-97;  //  In c++ automatic data type conversion in char to int\n            a[x]++;\n            \n            int y = s2[i]-97;\n            b[y]++;\n        }\n        \n        \n        // we declare count\n        int count=0;\n        \n        // we got completer array a and b\n        \n        for(int j=0;j<26;j++)\n        {\n            if(a[j]!=b[j])\n                count++;\n        }\n        if(count==0)\n            cout<<\"YES\"<<endl;\n        else\n            cout<<\"NO\"<<endl;\n    }\n}\n\n\n"
  },
  {
    "path": "36_codechef_Encoding_message.cpp",
    "content": "//\n//  main.cpp\n//  Lecture 36\n//\n//  Created by Prince  Kumar on 17/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//                      CODE-CHEF\n\n//       --- **    Problems on Encoding Message   ** ---       //\n\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; cin>>n; // lenght of string\n        string s; cin>>s;\n        \n        // 1st step of encoding\n        if(n%2==0)\n        {\n            // even\n            for(int i=0;i<n;i=i+2)  // len= 6 ; index -> 0 to 5\n            {\n                char z = s[i+1];  // z='h'\n                s[i+1] = s[i] ;  //\n                s[i]=z;\n            }\n        }\n        else\n        {\n            // odd\n            for(int i=0;i<n-1;i=i+2)\n            {\n                char z = s[i+1];  // z='h'\n                s[i+1] = s[i] ;  //\n                s[i]=z;\n            }\n        }\n        \n        // 2nd stage of encoding\n        \n        for(int i=0;i<n;i++)\n        {\n            char c = s[i];   // recent character  // b --> 98\n            //int index  =  s[i]-97;\n            int index  =  c-97;   // 1\n            int req = 25-index;   // 24\n            \n            //  range 97 to 122\n            req = req + 97;\n            char y = (char)req;  // real ASCII code\n            cout<<y;\n            \n        }\n        cout<<endl;\n        \n        \n        \n    }\n}\n\n\n\n\n"
  },
  {
    "path": "37_codechef_spell_bob.cpp",
    "content": "//\n//  main.cpp\n//  Lecture 37\n//\n//  Created by Prince  Kumar on 17/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//                      CODE-CHEF\n\n//       --- **    Problems on Spell bob   ** ---       //\n\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        string s1,s2; cin>>s1>>s2;\n        int a[3]={0};  // b count\n        for(int i=0;i<3;i++)  // 'b' present  or not\n        {\n            if(s1[i]=='b' || s2[i]=='b')\n                a[i]=1;\n        }\n        int b_count=0;\n        for(int i=0;i<3;i++)\n        {\n            if(a[i]==1)\n                b_count++;\n        }\n        if(b_count<=1)\n            cout<<\"no\"<<endl;\n        else if(b_count==2)\n        {\n            int index=0;\n            for(int i=0;i<3;i++)\n            {\n                if(a[i]==0)\n                    index=i;\n            }\n            if(s1[index]=='o' || s2[index]=='o')\n                cout<<\"yes\"<<endl;\n            else\n                cout<<\"no\"<<endl;\n        }\n        else if(b_count==3)\n        {\n            int o_count=0;\n            for(int i=0;i<3;i++)\n            {\n                if(s1[i]=='o' || s2[i]=='o')\n                    o_count++;\n            }\n            if(o_count==0)\n                cout<<\"no\"<<endl;\n            else\n                cout<<\"yes\"<<endl;\n        }\n    }\n}\n\n\n"
  },
  {
    "path": "38_codechef_fits_square_in_triangle.cpp",
    "content": "//\n//  main.cpp\n//  CODECHEF\n//\n//  Created by Prince  Kumar on 14/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//   --- **  Fits square in the triangle ** ---\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int b; cin>>b;\n        if(b==1 || b==2 ||b==3)\n            cout<<\"0\"<<endl;\n        else\n        {\n            if(b%2==0)  // for EVEN\n            {\n                int area = 0.5 * b *b;\n                int res =  (area - b )/4;\n                cout<<res<<endl;\n            }\n            else   // for ODD\n            {\n                b=b-1;\n                int area = 0.5 * b *b;\n                int res =  (area - b )/4;\n                cout<<res<<endl;\n            }\n               \n        }\n    }\n}\n"
  },
  {
    "path": "39_codechef_chef_and_Eid.cpp",
    "content": "//\n//  main.cpp\n//  CODE-CHEF\n//\n//  Created by Prince  Kumar on 14/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n// ---- ** Chef and Eid ** ------\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nint main()\n{\n    int T;cin>>T;\n    while(T--)\n    {\n        int n ; cin>>n;\n        vector<int > v;\n        for(int i=0;i<n;i++)\n        {\n            // cin>>v[i];\n            int x; cin>>x;\n            v.push_back(x);\n        }\n        sort(v.begin(),v.end());\n        // sort\n        \n        vector<int> res;\n        for(int i=0;i<n-1;i++)\n        {\n            res.push_back(v[i+1]-v[i]);\n        }\n        sort(res.begin(),res.end());\n        cout<<res[0]<<endl;\n        \n        \n    }\n}\n\n"
  },
  {
    "path": "40_codechef_chef_judges_competition.cpp",
    "content": "//\n//  main.cpp\n//  CODE-CHEF\n//\n//  Created by Prince  Kumar on 15/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n// ---- ** chef judges a competition ** --- //\n\n\n#include <iostream>\n#include <algorithm>\nusing namespace std;\nint main()\n{\n    int T;cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        int a[n] ; // for ALICE\n        int b[n] ; // for BOB\n        \n        for(int i=0;i<n;i++)\n        {\n            cin>>a[i];\n        }\n        \n        for(int i=0;i<n;i++)\n        {\n            cin>>b[i];\n        }\n        \n        // sorting in ARRAY\n        sort(a,a+n);\n        sort(b,b+n);\n        \n        int suma =0;\n        int sumb = 0;\n        \n        for(int i=0;i<n-1;i++)\n        {\n            suma = suma + a[i];\n            sumb = sumb + b[i];\n        }\n        // we get sum results\n        \n        if(suma==sumb)\n            cout<<\"Draw\"<<endl;\n        else if( suma < sumb)\n            cout<<\"Alice\"<<endl;\n        else\n            cout<<\"Bob\"<<endl;\n        \n    }\n}\n\n\n\n\n\n\n\n"
  },
  {
    "path": "41_codechef_chef_and_glove.cpp",
    "content": "//\n//  main.cpp\n//  CODE-CHEF\n//\n//  Created by Prince  Kumar on 17/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//   ---- ** CHEF AND GLOVE ** ------- //\n\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        // numbering 1 to n\n        \n        int len[n+1];  // length of finger\n        int glov [n+1]; // lenght of sheath\n        \n        for(int i=1;i<n+1;i++)\n        {\n            cin>>len[i];\n        }\n        for(int i=1;i<n+1;i++)\n        {\n            cin>>glov[i];\n        }\n        \n        // front\n        int front=0;\n        for(int i=1;i<n+1;i++)  // loop runs n times\n        {\n            if(len[i]<=glov[i])\n                front++;\n        }\n        \n        // back\n        int back=0;\n        for(int i=1;i<n+1;i++)\n        {\n            if(len[i]<=glov[n+1-i])  // i=1 --> 8+1-1 = 8\n                back++;                // i=2  --> 8+1-2 =7\n        }\n        \n        if(front==n && back==n)\n        {\n            cout<<\"both\"<<endl;\n        }\n        else if(front!=n && back!=n )\n            cout<<\"none\"<<endl;\n        else if(front==n && back!=n)\n            cout<<\"front\"<<endl;\n        else if( front!=n && back ==n)\n            cout<<\"back\"<<endl;\n    }\n}\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "42_codechef_the_great_run.cpp",
    "content": "//\n//  main.cpp\n//  CODE-CHEF\n//\n//  Created by Prince  Kumar on 17/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//  ------ ** The Great Run ** ---------- //\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--){\n        \n        int n,k; cin>>n>>k;\n        int a[n];  // no. of girls per km\n        for(int i=0;i<n;i++)\n        {\n            cin>>a[i];\n        }\n        // we get values of girls\n        \n        int max=0;\n        for(int i=0;i<=n-k;i++)\n        {\n            int sum=0;\n            for(int j=i;j<i+k;j++)\n            {\n                sum+=a[j];\n            }\n            if(max<sum)\n                max=sum;\n        }\n        cout<<max<<endl;\n        \n    }\n}\n\n\n\n\n"
  },
  {
    "path": "43_codechef_attendance.cpp",
    "content": "//\n//  main.cpp\n//  CODE-CHEF\n//\n//  Created by Prince  Kumar on 18/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n// ------- ** Attendance ** --------- //\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T;cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        string f[n];\n        string l[n];\n        \n        for(int i=0;i<n;i++)\n        {\n            cin>>f[i]>>l[i];  // first name and last name\n        }\n        \n        int a[n];\n        for(int i=0;i<n;i++){a[i]=0;}\n        \n        // initalise the array - a --> to 0\n        \n        for(int i=0;i<n-1;i++)\n        {\n            for(int j=i+1;j<n;j++)\n            {\n                if(f[i]==f[j])\n                {a[i]++; a[j]++;}\n            }\n        }\n        \n        // we check the condition on array a\n        \n        for(int i=0;i<n;i++)\n        {\n            if(a[i]==0)\n            {\n                cout<<f[i]<<endl;\n            }\n            else\n            {\n                cout<<f[i]<<\" \"<<l[i]<<endl;\n            }\n        }\n    }\n}\n\n\n\n\n\n\n"
  },
  {
    "path": "44_codechef_making_a_meal.cpp",
    "content": "//\n//  main.cpp\n//  CODE-CHEF\n//\n//  Created by Prince  Kumar on 18/05/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//  ------ ** Making a Meal ** -------- //\n\n#include<iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nint main()\n{\n    int T;cin>>T;\n    while(T--)\n    {\n        int n;cin>>n;\n        int bowl[26]={0};\n        for(int i=0;i<n;i++)\n        {\n            string s;cin>>s;\n            for(int j=0;j<s.size();j++)\n            {\n                int x = s[j] - 97;\n                bowl[x]++;\n            }\n        }\n        // we get all letters\n        \n        vector<int> v;\n        v.push_back(bowl[2]/2); // for 'c'\n        v.push_back(bowl[3]/1);  // for 'd'\n        v.push_back(bowl[4]/2);  // for 'e'\n        v.push_back(bowl[5]/1);  // for 'f'\n        v.push_back(bowl[7]/1);  // for 'h'\n        v.push_back(bowl[14]/1);  // for 'o'\n        \n        sort(v.begin(),v.end());\n        cout<<v[0]<<endl;\n        \n    }\n}\n\n\n\n"
  },
  {
    "path": "45_codechef_uncle_johny.cpp",
    "content": "//\n//  main.cpp\n//  lecture 45\n//\n//  Created by Prince  Kumar on 25/07/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n// codechef question --** Uncle johny ** ---- //\n\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        vector<int> v;\n        for(int i=0;i<n;i++)\n        {\n            int x; cin>>x;\n            v.push_back(x);\n            // v.push_back(cin);\n        }\n        int k; cin>>k; // index of jhony unle song\n        // vector use --> indexing start from 0\n        int val  = v[k-1]; // uncle jhony\n        sort(v.begin(),v.end());\n        for(int i=0;i<n;i++)\n        {\n            if(v[i]==val)\n            {\n                cout<<i+1<<endl;\n                break;\n            }\n        }\n    }\n}\n\n\n\n\n\n"
  },
  {
    "path": "46_drink_codeforce.cpp",
    "content": "//\n//  main.cpp\n//  hello\n//\n//  Created by Prince  Kumar on 01/08/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int n; cin>>n;\n    // p[i] =  how much ml of orange juice\n    int p[n]; for(int i=0;i<n;i++)\n    {\n        int x ;cin>>x;\n        x = x*10;\n        p[i] = x;\n    }\n    // we calculate total orange juice\n    \n    int tot_orange  = 0;\n    for(int i=0;i<n;i++)\n    {\n        tot_orange+=p[i];\n    }\n    \n    double x = tot_orange*100.00;\n    //  / we calculate total orange juice\n    \n    int tot_vol = n*1000; //integer\n    \n    // we calcuate total volume\n    \n    double res = (x/tot_vol);\n    cout<<res<<endl;\n    \n     \n}\n"
  },
  {
    "path": "47_candles_codeforces.cpp",
    "content": "//\n//  main.cpp\n//  candles\n\n// codeforces question\n//                   A. New Year Candles\n\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int a,b; cin>>a>>b;\n    \n    int x = a;\n    while(a>=b)\n    {\n        x = x + (a/b);\n        a = (a/b) + (a%b);\n    }\n    cout<<x<<endl;\n    \n}\n"
  },
  {
    "path": "49_two_buttons_codeforces.cpp",
    "content": "//\n//  main.cpp\n//  Two Buttons\n\n//\n//  Created by Prince  Kumar on 13/08/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n///             TWO BUTTONS --> Code-forces\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int n,m; cin>>n>>m;\n    if(n>=m)\n    { // 10  1\n        cout<<n-m<<endl;\n    }\n    else\n    {\n        // back tracking\n        int count=0;\n        while(m>n)\n        {\n            if(m%2==0)\n            {m/=2; count++;}\n            else\n            {\n                m+=1; count++;\n            }\n        }\n        cout<<count+(n-m)<<endl;\n    }\n}\n"
  },
  {
    "path": "50_vanya_and_books_codeforces.cpp",
    "content": "//\n//  main.cpp\n//  books\n//\n//  Created by Prince  Kumar on 15/08/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//    codeforce --> Vanya and Books\n\n#include <iostream>\n#include <math.h>\n#define ll long long\nusing namespace std;\nint main()\n{\n    ll int n; cin>>n;\n    ll int a[13]={0};\n    for(int i=1;i<13;i++)\n    {\n        a[i]=pow(10,i)-1;\n    }\n    for(int i=2;i<13;i++)\n    {\n        for(int j=1;j<=i-1;j++)\n        {\n            a[i] = a[i]-a[j];\n        }\n    }\n//    for(int i=1;i<13;i++)\n//    {\n//        cout<<a[i]<<endl;\n//    }\n    // value in array is to set\n    \n    ll int count=0;\n    for(int i=1;i<13;i++ )\n    {\n        if(n-a[i]>=0)\n        {\n            count+=a[i]*i;\n            n=n-a[i];\n        }\n        else\n        {\n            count+=n*i;\n            break;\n        }\n    }\n    cout<<count<<endl;\n    \n}\n\n\n\n\n\n\n\n"
  },
  {
    "path": "51_eleven_codeforces.cpp",
    "content": "//\n//  main.cpp\n//  eleven\n//\n//  Created by Prince  Kumar on 21/08/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n//.      PROBLEMS --> ELEVEN from Codeforces\n\n#include <iostream>\n#include <cstring>\n#define ll long long\nusing namespace std;\nint main()\n{\n    ll int a[20]={0}; // store fibonacci series\n    a[0]=a[1]=a[2]=1;\n    for(int i=3;i<20;i++)\n    {\n        a[i]=a[i-1]+a[i-2];\n    }\n    //cout<<a[19]<<endl;\n    // 1 1 2 3 5 8 ...  if n==10\n    int n; cin>>n;\n    int b[n+1]; memset(b,0,sizeof(b));\n    \n    \n    // 1 represent 'O'\n    // 0 represent 'o'\n    for(int i=1;i<20;i++)\n    {\n        if(a[i]<=n)\n        {\n            b[a[i]]=1;\n        }\n    }\n    for(int i=1;i<=n;i++)\n    {\n        if(b[i]==1)\n            cout<<\"O\";\n        else\n            cout<<\"o\";\n    }\n    cout<<endl;\n    \n}\n\n\n\n"
  },
  {
    "path": "52_codechef_flatland.cpp",
    "content": "//\n//  main.cpp\n//  faltland\n//\n//  Created by Prince  Kumar on 05/09/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n//  Code Of \"FLATLAND\" codechef \n#include <iostream>\nusing namespace std;\nint main()\n{\n    int a[36];\n    for(int i=1;i<36;i++)\n    {\n        a[i]=i*i;\n    }\n    // we got a array of perfect square\n    \n    int T;cin>>T;\n    while(T--)\n    {\n        int n;cin>>n;\n        int count=0;\n        while(n!=0)\n        {\n            for(int i=1;i<36;i++)\n            {\n                if(a[i]<=n && a[i+1]>n)\n                {\n                    n=n-a[i];\n                unt++;\n                }\n            }\n        }\n        cout<<count<<endl;\n    }\n}\n\n\n"
  },
  {
    "path": "53_codeforces_MUH_and_sticks.cpp",
    "content": "//\n//  main.cpp\n//  code\n//\n//  Created by Prince  Kumar on 07/09/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//  codeforces --> MUH and Sticks\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int a[10]={0};\n    for(int i=1;i<=6;i++)\n    {\n        int x; cin>>x;\n        a[x]++;\n    }\n    \n    int leg =0;\n    int leg_value=0;\n    for(int i=1;i<=9;i++)\n    {\n        if(a[i]>=4)\n        {\n            leg=1;\n            leg_value=i;\n            a[i]=a[i]-4;\n            break;\n        }\n        \n    }\n    \n    int body=0;\n    int body_value=0;\n    \n    for(int i=1;i<=9;i++)\n    {\n        if(a[i]>=1)\n        {\n            body=1;\n            body_value=i;\n            a[i]=a[i]-1;\n            break;\n        }\n        \n    }\n    \n    int head=0;\n    int head_value=0;\n    \n    for(int i=1;i<=9;i++)\n    {\n        if(a[i]>=1)\n        {\n            head=1;\n            head_value=i;\n            a[i]=a[i]-1;\n            break;\n        }\n        \n    }\n    \n    // we got leg leg_value / body body_value / head head_value\n    \n    if(leg==1 && body==1 && head==1)\n    {\n        if(leg_value!=head_value && leg_value!=body_value && head_value!=body_value)\n            cout<<\"Bear\"<<endl;\n        else if(body_value!=head_value && (leg_value!=head_value || leg_value!=body_value))\n            cout<<\"Bear\"<<endl;\n        else if(leg_value!=head_value && leg_value!=body_value && head_value==body_value)\n            cout<<\"Elephant\"<<endl;\n        else if(leg_value==head_value && leg_value==body_value && head_value==body_value)\n            cout<<\"Elephant\"<<endl;\n    }\n    else\n        cout<<\"Alien\"<<endl;\n}\n"
  },
  {
    "path": "54_print_subset_of_size_k_of_array.cpp",
    "content": "//\n//  main.cpp\n//  subset\n//\n//  Created by Prince  Kumar on 09/09/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//      Print all subset of size 'k' of array of size 'n'\n\n#include <iostream>\n#include<vector>\n#include <math.h>\n#include <algorithm>\nusing namespace std;\nint main()\n{\n    cout<<\"Enter number of elemnets in array : \"<<endl;\n    int n; cin>>n;\n    cout<<\"Enter the size of subset : \"<<endl;\n    int k ; cin>>k;\n    \n    int a[n];\n    cout<<\"Enter the numbers : \"<<endl;\n    for(int i=0;i<n;i++)\n    {\n        cin>>a[i];\n    }\n    for(int i=1;i<pow(2,n);i++)\n    {\n        vector<int> v;\n        int x=i; // x=8\n        while(x>0)\n        {\n            int z = x%2;  //  0  0  0   1\n            v.push_back(z);\n            x=x/2;  // 4  2  1 0\n        }\n        int p  = n- (int)v.size();\n        for(int j=1;j<=p;j++)\n        {\n            v.push_back(0);\n        }\n        reverse(v.begin(), v.end());\n        int count=0;\n        for(int i=0;i<v.size();i++)\n        {\n            if(v[i]==1)\n                count++;\n        }\n        if(count==k)\n        {\n            for(int i=0;i<v.size();i++)\n            {\n                if(v[i]==1)\n                {\n                    cout<<a[i]<<\" \";\n                }\n            }\n            cout<<endl;\n        }\n        v.clear();\n        \n    }\n}\n"
  },
  {
    "path": "55_codechef_Easy_Fibonacci.cpp",
    "content": "//\n//  main.cpp\n//  fibonacciii\n//\n//  Created by Prince  Kumar on 23/09/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//  code of Easy Fibonacci\n\n#include <iostream>\n#include <math.h>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        long long int x; cin>>x;\n        long long int z = log2((long double)x);\n        if(z==0)\n            cout<<\"0\"<<endl;\n        else if(z==1)\n            cout<<\"1\"<<endl;\n        else\n        {\n            int a = z%4;\n            if(a==2)\n                cout<<\"2\"<<endl;\n            else if(a==3)\n                cout<<\"3\"<<endl;\n            else if(a==0)\n                cout<<\"0\"<<endl;\n            else if(a==1)\n                cout<<\"9\"<<endl;\n        }\n    }\n}\n\n\n\n\n"
  },
  {
    "path": "56_codechef_Chef_and_Interesting_Subsequences.cpp",
    "content": "//\n//  main.cpp\n//  code\n//\n//  Created by Prince  Kumar on 23/09/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//  code of Chef and Interesting Subsequences\n//  ** --- September long challenge  -- ** //\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#define ll long long\nusing namespace std;\nll int gcd(ll int a, ll int b)\n{\n    if(b==0)\n        return a;\n    else\n        return gcd(b,a%b);\n}\nvoid nCr(int n, int r)\n{\n    \n    // p holds the value of n*(n-1)*(n-2)...,\n    // k holds the value of r*(r-1)...\n    long long p = 1, k = 1;\n    \n    // C(n, r) == C(n, n-r),\n    // choosing the smaller value\n    if (n - r < r)\n        r = n - r;\n    \n    if (r != 0) {\n        while (r) {\n            p *= n;\n            k *= r;\n            \n            // gcd of p, k\n            long long m = gcd(p, k);\n            \n            // dividing by gcd, to simplify product\n            // division by their gcd saves from the overflow\n            p /= m;\n            k /= m;\n            \n            n--;\n            r--;\n        }\n        \n        // k should be simplified to 1\n        // as C(n, r) is a natural number\n        // (denominator should be 1 ) .\n    }\n    \n    else\n        p = 1;\n    \n    // if our approach is correct p = ans and k =1\n    cout << p << endl;\n}\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        vector<int> v;\n        int n,k;cin>>n>>k;\n        for(int i=0;i<n;i++)\n        {\n            int x; cin>>x;\n            v.push_back(x);\n        }\n        sort(v.begin(),v.end());\n        int last_index_of_k = v[k-1];\n        int count=0;\n        for(int i=0;i<n;i++)\n        {\n            if(v[i]==last_index_of_k)\n                count++;\n        }\n        // we get total number of last_element\n        \n        int num=0;\n        for(int i=0;i<k;i++)\n        {\n            if(v[i]==last_index_of_k)\n                num++;\n        }\n        nCr(count,num);  // countCnum\n        \n    }\n}\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "57_codechef_A-books.cpp",
    "content": "//\n//  main.cpp\n//  jdjd\n//\n//  Created by Prince  Kumar on 26/09/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n//   --- codechef --> A-Books ---\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        int a[n];\n        int b[1000001]={0};\n        // in b[]  we store last index of elements\n        for(int i=0;i<n;i++)  // i->index\n        {\n            int x; cin>>x;\n            a[i]=x;\n            b[x]=i;\n            \n//            cin>>a[i];\n//            b[a[i]]=i;\n        }\n        for(int i=0;i<n;i++)\n        {\n            //cout<<n-1-b[a[i]]<<endl;\n            int x = a[i];\n            int last_index = b[x];\n            cout<<n-1-last_index<<\" \";\n        }\n        cout<<endl;\n        \n    }\n}\n\n\n\n"
  },
  {
    "path": "58_codechef_phone_prices.cpp",
    "content": "//\n//  main.cpp\n//  test1\n//\n//  Created by Prince  Kumar on 06/10/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n//                                 **-- October Long Challenge --**\n//                                       **-- Phone prices --**\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        int a[n+1]; for(int i=1;i<=n;i++){cin>>a[i];}\n        // we have now prices on respective days\n        int count=1;\n        for(int i=2;i<=n;i++)\n        {\n            int price = a[i];\n            if(i==2)\n            {\n                if(price<a[i-1])\n                    count++;\n            }\n            else if(i==3)\n            {\n                if(price<a[i-1] && price<a[i-2])\n                    count++;\n            }\n            else if(i==4)\n            {\n                if(price<a[i-1] && price<a[i-2] && price<a[i-3])\n                    count++;\n            }\n            else if(i==5)\n            {\n                if(price<a[i-1] && price<a[i-2] && price<a[i-3] && price<a[i-4])\n                    count++;\n            }\n            else\n            {\n                if(price<a[i-1] && price<a[i-2] && price<a[i-3] && price<a[i-4] && price<a[i-5])\n                    count++;\n            }\n        }\n        cout<<count<<endl;\n    }\n}\n"
  },
  {
    "path": "59_codechef_operations_on_a_matrix.cpp",
    "content": "//\n//  main.cpp\n//  bbcfjc\n//\n//  Created by Prince  Kumar on 06/10/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n//                              ***-- October Long Challeneg 2019 --***\n/                                      ***-- Operations on a Matrix --****\n\n#include <iostream>\n#include <cstring>\n#include <string>\n#include <string.h>\n#define ll long long\nusing namespace std;\nint main()\n{\n    ll int T; cin>>T;\n    while(T--)\n    {\n        ll int n,m,q;cin>>n>>m>>q;\n        ll int a[n+1]; memset(a,0,sizeof(a)); // row\n        ll int c[m+1]; memset(c,0,sizeof(c)); // column\n        for(ll int i=0;i<q;i++)\n        {\n            ll int a1, a2;cin>>a1>>a2;\n            a[a1]++; c[a2]++;\n        }\n        ll int odd=0,even=0,a_zero=0;\n        for(ll int i=1;i<=n;i++)\n        {// row\n            \n            if(a[i]>0)\n            {\n            if(a[i]%2!=0)\n                odd++;\n            else\n                even++;\n                \n            }\n            else\n                a_zero++;\n        }\n        // for column\n        ll int count=0;\n        for(ll int i=1;i<=m;i++)\n        {\n            if(c[i]>0)\n            {\n                if(c[i]%2!=0)\n                {\n                    count+=even+a_zero;\n                }\n                else\n                {\n                    // even\n                    count+=odd;\n                }\n            }\n            else\n                count+=odd;\n        }\n        cout<<count<<endl;\n        \n    }\n}\n"
  },
  {
    "path": "60_Adding_one_to_the_numbers.cpp",
    "content": "//\n//  main.cpp\n//\n//  Created by Prince  Kumar on 16/04/20.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** ADD ONE TO THE NUMBER **---\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nint main(){\n    cout<<\"Enter The size of Vector : \"<<endl;\n    int n; cin>>n;\n    \n    vector<int> v; v.push_back(0);\n    for(int i=0;i<n;i++){\n        int x;\n        cin>>x;\n        v.push_back(x);\n    }\n    \n    // check conditions\n    int k = (int)v.size() - 1;\n    \n    if(v[k]<9){\n        v[k]+=1;  // v[k] = v[k] + 1;\n    }else{\n        \n        while(v[k]==9){\n            v[k]=0;\n            k= k-1;\n        }\n        \n        v[k]= v[k]+1;\n    }\n    \n    // Print the result\n    // we have to omit the leading zero's\n    \n    int s = 0;\n    for(int i=0;i<(int)v.size() ;i++){\n        if(v[i]!=0){\n            s=i;  // here we store index\n            break;\n        }\n    }\n    \n    for (int i=s;i<(int)v.size();i++){\n        cout<<v[i]<<\" \";\n    }\n    cout<<endl;\n}\n"
  },
  {
    "path": "Chef and Price Control.cpp",
    "content": "//\n//  COMPETITIVE PROGRAMMING .cpp\n//\n//  Created by Prince  Kumar on 15/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                       ---** COMPETITIVE PROGRAMMING in C++ **---\n//                            ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nint main(){\n    int T; cin>>T;\n    while(T--){\n        int n, k; cin>>n>>k;\n        int prev_amt=0;\n        int ori_amt=0;\n        // 2 3 4 7 10     5\n        for(int i=0;i<n;i++){\n            int x; cin>>x;   // x = 2\n            prev_amt+=x;  // profit initially   prev_Amt = 2\n            \n            if(x>k){\n                x=k;\n            }               // x= 5\n            ori_amt+=x;    // ori_amt = 2\n        }\n        cout<<prev_amt-ori_amt<<endl;\n        \n//        int a[n];\n//        for(int i=0;i<n;i++){\n//            cin>>a[i];\n//            prev_amt+=a[i];\n//        }\n//        for(int i=0;i<n;i++){\n//            if(a[i]>k){\n//                a[i]=k;\n//            }\n//            ori_amt+=a[i];\n//        }\n    }\n}\n"
  },
  {
    "path": "Data Structures/Add a node at the Middle of linked list.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 23/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** INSERTION OF NODE IN  LINKED LIST in C++ **---\n\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n};\n\n/* -------  Print the Linked List  -------*/\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in linked list is : \"<<count<<endl;\n}\n\n/* ------  INSERTION OF NODE AT FRONT OF LINKED LIST --------*/\n\nvoid push(node **head_ref , int newData){\n    node *newNode = new node();\n    newNode -> data = newData;\n    newNode -> next = *head_ref;\n    *head_ref = newNode;\n}\n\n/* ------  INSERTION OF NODE AT MIDDLE OF LINKED LIST --------*/\n\nvoid insertAfter(node *prev_node , int newData){\n    node *newNode = new node();\n    newNode->data = newData;\n    newNode->next = prev_node->next;\n    prev_node->next = newNode;\n}\n\nint main(){\n   \n    node *head = NULL;\n    push(&head , 5);\n    push(&head , 7);\n    push(&head , -3);\n    // -3 7 5\n    \n    insertAfter(head->next,79);\n    \n    printList(head);\n    \n}\n"
  },
  {
    "path": "Data Structures/Add a node at the end of linked list.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 24/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** INSERTION OF NODE IN  LINKED LIST in C++ **---\n\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n};\n\n/* -------  Print the Linked List  -------*/\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in linked list is : \"<<count<<endl;\n}\n\n/* ------  INSERTION OF NODE AT FRONT OF LINKED LIST --------*/\n\nvoid push(node **head_ref , int newData){\n    node *newNode = new node();\n    newNode -> data = newData;\n    newNode -> next = *head_ref;\n    *head_ref = newNode;\n}\n\n/* ------  INSERTION OF NODE AT MIDDLE OF LINKED LIST --------*/\n\nvoid insertAfter(node *prev_node , int newData){\n    node *newNode = new node();\n    newNode->data = newData;\n    newNode->next = prev_node->next;\n    prev_node->next = newNode;\n}\n\n/* ------  INSERTION OF NODE AT END OF LINKED LIST --------*/\n\n\nvoid append(node **head_ref, int newData){\n    \n    node *newNode = new node();\n    newNode->data = newData;\n    newNode->next = NULL;\n    \n    node *last = *head_ref;\n    \n    if(*head_ref == NULL){\n        *head_ref = newNode;\n        return;\n    }\n    \n    while(last->next != NULL){\n        last = last->next;\n    }\n    \n    last->next = newNode;\n    return;\n    \n}\n\nint main(){\n   \n    node *head = NULL;\n    push(&head , 5);\n    push(&head , 7);\n    push(&head , -3);\n    // -3 7 5\n    \n    insertAfter(head->next,79);\n    // -3 7 79 5\n    \n    append(&head, 90);\n    printList(head);\n    \n}\n\n\n"
  },
  {
    "path": "Data Structures/Add a node at the front of linked list.cpp",
    "content": "\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 22/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** INSERTION OF NODE IN  LINKED LIST in C++ **---\n\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n};\n\n/* -------  Print the Linked List  -------*/\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in linked list is : \"<<count<<endl;\n}\n\n//node *push(node *head , int newData){\n//    node *newNode = new node();\n//    newNode -> data = newData;\n//    newNode -> next = head;\n//    head = newNode;\n//    return head;\n//}\n\nvoid push(node **head_ref , int newData){\n    node *newNode = new node();\n    newNode -> data = newData;\n    newNode -> next = *head_ref;\n    *head_ref = newNode;\n}\n\nint main(){\n   \n    node *head = NULL;\n    push(&head , 5);\n    push(&head , 7);\n    push(&head , -3);\n    \n    printList(head);\n    \n}\n\n\n\n"
  },
  {
    "path": "Data Structures/Array_in_data_structures.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 08/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** ARRAYS in C++ **---\n\n#include <iostream>\nusing namespace std;\nint main(){\n    \n    //1st method\n//    int arr[5];\n//    arr[0] = 4;\n//    arr[1] = 3;\n//    arr[2] = -10;\n//    arr[3] = 8;\n//    arr[4] = -6;\n    \n    // 2nd method\n    int arr[5] = {4 , 3, -10, 8,-9};\n    \n    int arr1[] = {4 , 3, -10, 8,7 , 4, 2 , 11};\n    //int arr2[];\n    \n    \n    cout<<arr[3]<<endl;\n    cout<<arr1[5]<<endl;\n    cout<<\"Ans : \"<<arr1[3/2]<<endl;\n    \n    \n    int a[5]={0};\n    cout<<a[4]<<endl;\n    \n//    int b[5]={1};\n//    cout<<b[3]<<endl;\n}\n\n\n\n"
  },
  {
    "path": "Data Structures/Circular Linked List data_structure.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 20/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** CIRCULAR LINKED LIST in C++ **---\n\n//                     ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n//Linked list Node\nstruct node{\n    int data;\n    node *next;\n};\n\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in linked list is : \"<<count<<endl;\n}\n\nvoid printCircularList(node * first){\n    node *temp = first;\n    \n    if(first!=NULL){\n        cout<<temp->data<<endl;\n        temp = temp->next;  // this changes in temp\n        \n        while(temp != first){\n            cout<<temp->data<<endl;\n            temp = temp->next;\n        }\n    }\n}\n\nint main(){\n    \n//    /*                   Make A linked List                            */\n    node *head  = new node(); node *second = new node(); node *third = new node();\n    node *four  = new node(); node *five = new node(); node *six = new node();\n    node *seven  = new node(); node *eight = new node(); node *nine = new node();\n\n    head -> data = 5;   head -> next = second;\n    second->data = 1;   second ->next = third;\n    third -> data = -3; third ->next = four;\n    four -> data = 11;  four -> next = five;\n    five->data = 10;    five ->next = six;\n    six -> data = 2;    six ->next = seven;\n    seven -> data = 7;  seven -> next = eight;\n    eight->data = 9;    eight ->next = nine;\n    nine -> data = 18;  nine ->next = head;\n\n    printCircularList(four);\n}\n"
  },
  {
    "path": "Data Structures/Delete a node of a linked list.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 25/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** DELETION OF NODE IN  LINKED LIST in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n};\n\n/* -------  Print the Linked List  -------*/\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in linked list is : \"<<count<<endl;\n}\n\n/* ------  INSERTION OF NODE AT FRONT OF LINKED LIST --------*/\n\nvoid push(node **head_ref , int newData){\n    node *newNode = new node();\n    newNode -> data = newData;\n    newNode -> next = *head_ref;\n    *head_ref = newNode;\n}\n\n/* ------  DELETION OF NODE IN LINKED LIST --------*/\n\n\nvoid deleteNode(node **head_ref , int key){\n    // initialise prev and temp\n    node *prev, *temp;\n    \n    //store head to the temp;\n    temp  = *head_ref;\n    \n    //if key is present in head\n    if(temp!=NULL && temp->data == key){\n        *head_ref = temp->next;\n        free(temp);\n        return;\n    }\n    \n    //we traverse the linkedlist and keep track og prev node\n    // because we have to perform prev->next\n    \n    while(temp!=NULL && temp->data!=key){\n        prev=temp;\n        temp = temp->next;\n    }\n    \n    // we travserse whole linked list and we didn't got the key\n    if(temp==NULL) return;\n    \n    // but, if we found the key\n    prev->next = temp->next;\n    free(temp);\n}\n\n\nint main(){\n   \n    node *head = NULL;\n    push(&head , 5);\n    push(&head , 7);\n    push(&head , -3);\n    push(&head , 2);\n    push(&head , 9);\n    \n    printList(head);\n    \n    deleteNode(&head, 2);\n    \n    printList(head);\n    \n    \n}\n"
  },
  {
    "path": "Data Structures/Doubly Linked list.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 27/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** INSETION OF NODE IN DOUBLY LINKED LIST in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Doubly Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n    node *prev;\n};\n\n\n/*-------  Print the Douubly Linked List  ------- */\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in Doubly linked list is : \"<<count<<endl;\n}\n\n/*-------  Insert node in Doubly Linked List  ------- */\n\nvoid push(node **head_ref, int new_data){\n    \n    node *new_node = new node();\n    new_node->data=  new_data;\n    new_node->next = *head_ref;\n    new_node->prev = NULL;\n    \n    if((*head_ref) != NULL){\n        (*head_ref)->prev = new_node;\n    }\n    \n    (*head_ref) = new_node;\n}\n\n\nint main(){\n    \n    node *head= NULL;\n    push(&head, 4);\n    push(&head, 11);\n    push(&head, -3);\n    \n    // -3 11 4\n    \n    printList(head);\n}\n\n"
  },
  {
    "path": "Data Structures/Find the middle of a given linked list.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 20/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** LINKED LIST in C++ **---\n\n//                     ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n//Linked list Node\nstruct node{\n    int data;\n    node *next;\n};\n\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    \n    cout<<\"No. of element in linked list is : \"<<count<<endl;\n}\n\nvoid printMiddleElement( node *head){\n    node *slow_ptr = head;\n    node *fast_ptr = head;\n    \n    if(head!=NULL){\n        while(fast_ptr!=NULL && fast_ptr->next!=NULL){\n            fast_ptr = fast_ptr->next->next;\n            slow_ptr = slow_ptr->next;\n        }\n        cout<<\"Middle Element is : \"<<slow_ptr->data<<endl;\n    }\n    \n}\n\nint main(){\n    \n    /*                   Make A linked List                            */\n    node *head  = new node(); node *second = new node(); node *third = new node();\n    node *four  = new node(); node *five = new node(); node *six = new node();\n    node *seven  = new node(); node *eight = new node(); node *nine = new node();\n    \n    head -> data = 5;   head -> next = second;\n    second->data = 1;   second ->next = third;\n    third -> data = -3; third ->next = four;\n    four -> data = 11;  four -> next = five;\n    five->data = 10;    five ->next = six;\n    six -> data = 2;    six ->next = seven;\n    seven -> data = 7;  seven -> next = eight;\n    eight->data = 9;    eight ->next = nine;\n    nine -> data = 18;  nine ->next = NULL;\n    \n    \n    //printList(head);\n    \n//    node *start = head;\n//    for(int i=0;i<5;i++){\n//        cout<<start->data<<endl;\n//        start= start->next;\n//    }\n    \n    printMiddleElement(head);\n}\n"
  },
  {
    "path": "Data Structures/Insert Node at the End of Doubly Linked List.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 30/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** INSETION OF NODE IN DOUBLY LINKED LIST in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Doubly Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n    node *prev;\n};\n\n\n/*-------  Print the Doubly Linked List  ------- */\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in Doubly linked list is : \"<<count<<endl;\n}\n\n/*-------  Insert node in Front of Doubly Linked List  ------- */\n\nvoid push(node **head_ref, int new_data){\n    \n    node *new_node = new node();\n    new_node->data=  new_data;\n    new_node->next = *head_ref;\n    new_node->prev = NULL;\n    \n    if((*head_ref) != NULL){\n        (*head_ref)->prev = new_node;\n    }\n    \n    (*head_ref) = new_node;\n}\n\n/*-------  Insert node in Middle of Doubly Linked List  ------- */\n\nvoid insertAfter(node *prev_node, int new_data){\n    \n    if(prev_node == NULL){\n        cout<<\"given prev node can't be null\"<<endl;\n        return;\n    }\n    \n    node *new_node = new node();\n    new_node->data = new_data;\n    new_node->next = prev_node->next;\n    \n    prev_node->next = new_node;\n    new_node->prev = prev_node;\n    \n    if(new_node->next != NULL){\n        new_node->next->prev = new_node;\n    }\n}\n\n/*-------  Insert node in End of Doubly Linked List  ------- */\n\nvoid append(node **head_ref, int new_data){\n    node *new_node = new node();\n    new_node->data = new_data;\n    new_node->next = NULL;\n    \n    node *last  = *head_ref;  //head\n    if(*head_ref == NULL){\n        new_node->prev = NULL;\n        *head_ref = new_node;\n        return;\n    }\n    \n    while(last->next != NULL){\n        last = last->next;\n    }\n    \n    last->next = new_node;\n    new_node->prev = last;\n    \n    return;\n}\n\n\nint main(){\n    \n    node *head= NULL;\n    push(&head, 4);\n    push(&head, 11);\n    push(&head, -3);\n    // -3 11 4\n    \n    insertAfter(head->next, 10);\n    // -3 11 10 4\n    \n    append(&head, 9);\n    // -3 11 10 4 9\n    \n    printList(head);\n}\n"
  },
  {
    "path": "Data Structures/Insert Node in Middle of Doubly Linkedlist.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 30/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** INSETION OF NODE IN DOUBLY LINKED LIST in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n/* ----- Doubly Linked list Node  ------ */\nstruct node{\n    int data;\n    node *next;\n    node *prev;\n};\n\n\n/*-------  Print the Doubly Linked List  ------- */\nvoid printList (node *n){\n    int count=0;\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n        count++;\n    }\n    cout<<\"No. of element in Doubly linked list is : \"<<count<<endl;\n}\n\n/*-------  Insert node in Front of Doubly Linked List  ------- */\n\nvoid push(node **head_ref, int new_data){\n    \n    node *new_node = new node();\n    new_node->data=  new_data;\n    new_node->next = *head_ref;\n    new_node->prev = NULL;\n    \n    if((*head_ref) != NULL){\n        (*head_ref)->prev = new_node;\n    }\n    \n    (*head_ref) = new_node;\n}\n\n/*-------  Insert node in Middle of Doubly Linked List  ------- */\n\nvoid insertAfter(node *prev_node, int new_data){\n    \n    if(prev_node == NULL){\n        cout<<\"given prev. node can't be null\"<<endl;\n        return;\n    }\n    \n    node *new_node = new node();\n    new_node->data = new_data;\n    new_node->next = prev_node->next;\n    \n    prev_node->next = new_node;\n    new_node->prev = prev_node;\n    \n    if(new_node->next != NULL){\n        new_node->next->prev = new_node;\n    }\n}\n\nint main(){\n    \n    node *head= NULL;\n    push(&head, 4);\n    push(&head, 11);\n    push(&head, -3);\n    // -3 11 4\n    \n    insertAfter(head->next, 10);\n    // -3 11 10 4\n    \n    printList(head);\n}\n"
  },
  {
    "path": "Data Structures/LinkedList_Code_Practice.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 15/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** LINKED LIST in C++ **---\n\n//                     ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\n\n//Linked list Node\nstruct node{\n    int data;\n    node *next;\n};\n\nvoid printList (node *n){\n    while(n!=NULL){\n        cout<<n->data<<endl;\n        n = n->next;\n    }\n}\n\nint main(){\n    node *head = new node();\n    node *second = new node();\n    node *third = new node();\n    \n    head -> data = 5;\n    head -> next = second;\n    \n    second->data = 1;\n    second ->next = third;\n    \n    third -> data = 3;\n    third ->next = NULL;\n    \n    printList(head);\n\n}\n"
  },
  {
    "path": "Data Structures/Vectors_in_STL_data_structure.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 3/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <vector>\nusing namespace std;\nint main(){\n    vector<int> v;    /*  3 10 7*/\n    vector<int> :: iterator it;\n    v.push_back(3);\n    v.push_back(10);\n    v.push_back(7);\n    \n    auto a = v.begin();   // it provides iterator which points first element of vector\n    cout<<\"first element  : \"<<a[0]<<endl;\n    //v.pop_back();\n    \n    it = v.begin();\n    cout<<\"iterator points : \"<<it[0]<<endl;\n    \n    it = v.end();\n    //cout<<it<<endl;\n    \n    int size = (int)v.size();\n\n    for(int i=0;i<size;i++){\n        cout<<v[i]<<\" \";\n    }\n    cout<<endl;\n}\n\n\n"
  },
  {
    "path": "Data Structures/main.cpp",
    "content": "main file\n"
  },
  {
    "path": "Data Structures/structure_in_c++.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 11/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** STRUCTURE & CLASSES in C++ **---\n\n#include <iostream>\nusing namespace std;\nstruct student{\n  \n    int roll;\n    string name;\n    int age;\n    \n    void studentDetails(){\n        cout<<\"name is : \"<<name<<endl;\n        cout<<\"age is : \"<<age<<endl;\n        cout<<\"roll is : \"<<roll<<endl;\n    }\n    \n};\nint main(){\n    \n//    struct student prince;\n    student simran;\n    student prince;\n    prince.age= 21;\n    prince.name = \"prince\";\n    prince.roll = 44;\n    \n    struct student prateek = { 21, \"prateek\" ,20};\n    \n    prince.studentDetails();\n    cout<<endl;\n    prateek.studentDetails();\n    cout<<endl;\n    \n    \n}\n"
  },
  {
    "path": "Kadane's_algorithm.cpp",
    "content": "//\n//  main.cpp\n//\n//  Created by Prince  Kumar on 21/04/20.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** MAX SUM CONTIGUOUS SUBARRAY **---\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nint main(){\n    cout<<\"Enter the size of Array : \"<<endl;\n    int n; cin>>n;\n    \n    int a[n];\n    for(int i=0;i<n;i++){\n        cin>>a[i];\n    }\n    \n    int max_so_far = a[0], max_ending_here =0;  // It store sum\n    int start = 0 , end=0 , s=0;  // it store index\n    \n    for(int i=0;i<n;i++){\n        max_ending_here+=a[i];\n        if(max_so_far < max_ending_here){\n            max_so_far=max_ending_here;\n            start = s; end=i;\n        }\n        \n        if(max_ending_here<0){\n            max_ending_here = 0;\n            s = i+1;\n        }\n    }\n    \n    int sum=0;\n    for(int i=start ;i<=end ; i++){\n        sum+=a[i];\n        cout<<a[i]<<\" \";\n        \n    }\n    cout<<endl;\n    cout<<sum<<endl;\n    \n    \n}\n"
  },
  {
    "path": "Lecture - 15.cpp",
    "content": "//\n//  main.cpp\n//  lecture 15\n//\n//  Created by Prince  Kumar on 14/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nint main()\n{\n    vector<int > v;\n    v.push_back(10);\n    v.push_back(23);\n    v.push_back(22);\n    v.push_back(78);\n    v.push_back(98);\n    \n    // iterators // pointers\n    \n    // sort // ascending to descending...\n    sort(v.begin(),v.end());  // important\n    \n    v.pop_back();\n    int k  = (int)v.size();   // k=5\n    \n    \n    \n    \n    for(int i=0;i<k;i++)\n    {\n        cout<<v[i]<<\" \";\n    }\n    cout<<endl;\n    \n}\n"
  },
  {
    "path": "Lecture - 16.cpp",
    "content": "//\n//  main.cpp\n//  lecture -16\n//\n//  Created by Prince  Kumar on 15/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n#include <iostream>\n#include <sstream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;    // int n= 7929024\n        ostringstream str1;\n        str1<<n;\n        string s = str1.str();\n        \n        // single char  'a', '3' ' $'\n        // set of char == string  == \"prince\"  , \"78292\"\n        // string  s = 7929024    k = 7\n        // find the string size\n        int count=0;\n        int k = (int)s.size();\n        for(int i=0;i<k;i++)\n        {\n            if(s[i]=='4')\n                count++;\n            else\n                count=count;\n        }\n        cout<<count<<endl;\n    }\n}\n"
  },
  {
    "path": "Lecture - 17.cpp",
    "content": "//\n//  main.cpp\n//  lecture -17\n//\n//  Created by Prince  Kumar on 17/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int a,b,c,d; cin>>a>>b>>c>>d;\n        if((a==c && b==d)|| (a==b && c==d)||(a==d && c==b))\n            cout<<\"YES\"<<endl;\n        else\n            cout<<\"NO\"<<endl;\n    }\n}\n"
  },
  {
    "path": "Lecture - 18.cpp",
    "content": "#include <iostream>\nusing namespace std;\nint main()\n{\n    int T;cin>>T;\n    while(T--)\n    {\n        int n; cin>>n;\n        int k ; cin>>k;\n        string s; cin>>s;\n        int cap=0;\n        int small=0;\n        for(int i=0;i<n;i++)\n        {\n            char x = s[i];\n            int p = int(x); // ASCII CODE\n            // CAPITAL   ASCII    65 to 90\n            // SMALL     ASCII    97  to 122\n            if(p>=65 && p<=90)\n                cap++;\n            else\n                small++;\n        }\n        // we have no. of small and capital letters.\n        if(cap==small)\n        {\n            if(k>=cap)\n                cout<<\"both\"<<endl;\n            else if(k<cap)\n                cout<<\"none\"<<endl;\n        }\n        else if(small>cap)\n        {\n            if(k>=small)\n                cout<<\"both\"<<endl;\n            else if(k<cap)\n                cout<<\"none\"<<endl;\n            else\n                cout<<\"chef\"<<endl;\n                \n        }\n        else if(cap>small)\n        {\n            if(k>=cap)\n                cout<<\"both\"<<endl;\n            else if(k<small)\n                cout<<\"none\"<<endl;\n            else\n                cout<<\"brother\"<<endl;\n        }\n    }\n}\n"
  },
  {
    "path": "Lecture - 19.cpp",
    "content": "\n// ** -- code of \"Studying alphabet \" --Code chef -- **\n#include <iostream>\nusing namespace std;\nint main()\n{\n    string s; cin>>s;\n    int a[26]={0}; // we put the value 0 in all the blocks\n    int len = (int)s.size();  // length of string\n    for(int i=0;i<len;i++)\n    {\n        char x = s[i]; // lets suppose x ='c'\n        int p = int(x); // p =99\n        p = p-97;  // index of that character // p =2\n        a[p]=1;\n    }\n    int n; cin>>n;\n    for(int i=0;i<n;i++)\n    {\n        int count=0;  // no. of charcter that not present in string s\n        string k; cin>>k;  // k--> words\n        for(int j=0;j<k.size();j++)\n        {\n            char z = k[j]; // let's supose z= 'f'\n            int h = int(z);  // h=102\n            h = h-97;  // h=5\n            if(a[h]==0)\n                count++;\n            else\n                count=count;\n        }\n        if(count>0)\n            cout<<\"No\"<<endl;\n        else\n            cout<<\"Yes\"<<endl;\n        \n    }\n}\n"
  },
  {
    "path": "Lecture - 20.cpp",
    "content": "#include <iostream>\n#include <sstream>\nusing namespace std;\nint main()\n{\n    string s;\n    //cin>>s;\n    getline(cin,s);\n    cout<<s<<endl;\n    cout<<s[0]<<endl;\n    cout<<s[1]<<endl;\n    cout<<s[2]<<endl;\n    cout<<s[3]<<endl;\n    cout<<s[4]<<endl;\n    \n    // -- we want to extrat the words --\n    stringstream str(s);\n    string word;   // it stores the words present in the string s\n    while(str>>word)\n    {\n        cout<<word<<endl;\n    }\n}\n"
  },
  {
    "path": "Lecture - 21.cpp",
    "content": "#include <iostream>\n#include <cstring>\nusing namespace std;\nint main()\n{\n    // problem 1.\n    /*int a[10]={0};\n    cout<<a[5]<<endl;\n    \n    int b[10]={21};  // method wrong ... and luckily valid for only 0 (zero )\n    cout<<b[5]<<endl;  */\n    \n    // problem 2.\n   /* int n ; cin>>n;\n    int a[n]={0};\n    cout<<a[5]<<endl; */\n    \n    // solution of these problem\n    // memset ()\n    int n;\n    cout<<\"Input the size of array\"<<endl;\n    cin>>n;\n    int a[n]; // block name --- a\n    memset(a,0 ,sizeof(a));  // value --> 0 & -1\n    cout<<a[4]<<endl;\n    \n    int val[9];\n    memset(val, -1 , sizeof(val));\n    for(int i=0;i<9;i++)\n    {\n        cout<<val[i]<<\" \";\n    }\n    cout<<endl;\n    \n}\n"
  },
  {
    "path": "Lecture - 22.cpp",
    "content": "// **--- program of print prime numbers ---**//\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int n;\n    cout<<\"Enter value of n upto which you want to print prime number : \"<<endl;\n    cin>>n;\n    for(int i=2;i<=n;i++)   /// 10\n    {\n        int x = i;  // 10\n        int count=0;\n        for(int j=1;j<=x;j++)  // j=1 to j=10\n        {\n            if(x%j==0) // 10%2==0\n                count++;\n        }\n        if(count==2)\n            cout<<x<<endl;\n    }\n}\n"
  },
  {
    "path": "Lecture - 24.cpp",
    "content": "//\n//  main.cpp\n//  Lecture - 24\n//\n//  Created by Prince  Kumar on 28/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//  seive of eratosthenes -- //\n\n#include <iostream>\n#include <cstring>\nusing namespace std;\n\nvoid seive( int n)\n{\n    // create boolean array\n    bool prime[n+1];\n    memset(prime, true ,sizeof(prime));\n    \n    for(int p=2;p*p<=n;p++)\n    {\n        //  if prime[p] --> false  --> it is not prime\n        if(prime[p]==true)\n        {\n            for(int i=p*p;i<=n;i=i+p)\n            {\n                prime[i]=false;\n            }\n        }\n    }\n    \n    // print prime numbers\n    for(int j=2;j<=n;j++)\n    {\n        if(prime[j]==true)\n            cout<<j<<endl;\n    }\n}\nint main()\n{\n    cout <<\"Enter number upto which you want to print prime numbers \"<<endl;\n    int n ; cin>>n;\n    seive(n);\n}\n"
  },
  {
    "path": "Lecture - 25.cpp",
    "content": "//\n//  main.cpp\n//  hbhbhbs\n//\n//  Created by Prince  Kumar on 29/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n// ** --- Euclidean Algorithm -- for finding GCD of 2 number **//\n\n#include <iostream>\nusing namespace std;\nint gcd(int a, int b)\n{\n    if(a==0)\n        return b;\n    else\n        return gcd(b%a ,a);\n    \n}\nint main()\n{\n    int a,b;\n    cout<<\"Enter two numbers \"<<endl;\n    cin>>a>>b;\n    int result = gcd(a,b);\n    cout<<result<<endl;\n}\n"
  },
  {
    "path": "Lecture - 26.cpp",
    "content": "//\n//  main.cpp\n//  hsgts\n//\n//  Created by Prince  Kumar on 29/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//   Chef and his daily routine Problem Code: CHEFROUT\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        string s; cin>>s;\n        int count=0;\n        for(int i=0;i<s.size()-1;i++)\n        {\n            if(s[i]=='C')\n            {\n                if(s[i+1]=='E' ||s[i+1]=='S' || s[i+1]=='C')\n                    count++;\n            }\n            else if(s[i]=='E')\n            {\n                if(s[i+1]=='S' || s[i+1]=='E')\n                    count++;\n            }\n            else if(s[i]=='S')\n            {\n                if(s[i+1]=='S')\n                    count++;\n            }\n        }\n        if(count==s.size()-1)\n            cout<<\"yes\"<<endl;\n        else\n            cout<<\"no\"<<endl;\n    }\n}\n"
  },
  {
    "path": "Lecture - 27.cpp",
    "content": "//\n//  main.cpp\n//  lecture 27\n//\n//  Created by Prince  Kumar on 31/03/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//  code of codechef problem - Two vs Ten\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int x; cin>>x;\n        if(x%10==0)\n            cout<<\"0\"<<endl;\n        else if(x%5==0)\n            cout<<\"1\"<<endl;  // 5*2 =10\n        else\n            cout<<\"-1\"<<endl;\n    }\n}\n"
  },
  {
    "path": "Lecture - 31.cpp",
    "content": "//\n//  main.cpp\n//  lecture 31\n//\n//  Created by Prince  Kumar on 04/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//\n// --- * Check the number is power of 2 * --- //\n#include <iostream>\nusing namespace std;\nint main()\n{\n    cout<<\"Enter the number \"<<endl;\n    int x;\n    cin>>x;\n    int a = x & (x-1);\n    if(a==0)\n        cout<<\"Number is the power of 2\"<<endl;\n    else\n        cout<<\"Number is NOT the power of 2\"<<endl;\n        \n}\n"
  },
  {
    "path": "Lecture - 32.cpp",
    "content": "//\n//  main.cpp\n//  lecture 32\n//\n//  Created by Prince  Kumar on 05/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//  -- ** code of COUNT THE THE NUMBER OF ONE'S IN THE BINARY REPRESENTATION OF GIVEN NUMBER ** --- //\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    cout<<\"Enter the number :\"<<endl;\n    int n; cin>>n;\n    int x = n & (n-1);\n    int count=1;\n    while(x!=0)\n    {\n        count++;\n        x = x & (x-1);\n    }\n    cout<<count<<endl;\n    \n    /*\n     \n     cout<<\"Enter the number :\"<<endl;\n     int n; cin>>n;\n     n = n & (n-1);\n     int count=1;\n     while(n!=0)\n     {\n     count++;\n     n = n & (n-1);\n     }\n     \n     \n     */\n}\n"
  },
  {
    "path": "Lecture - 33.cpp",
    "content": "//\n//  main.cpp\n//  lecture 33\n//\n//  Created by Prince  Kumar on 05/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//  -- **  code of  --> Check the ith bit is set in the binary form of given number ** --- //\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    cout<<\"Enter the number : \"<<endl;\n    int n ; cin>>n;\n    bool  a = n & ( 1<<3);\n    if(a==true)\n        cout<<\"Yes, bit is set\"<<endl;\n    else\n        cout<<\"No,  bit is not set\"<<endl;\n        \n}\n"
  },
  {
    "path": "Lecture - 34.cpp",
    "content": "//\n//  main.cpp\n//  Lecture 34\n//\n//  Created by Prince  Kumar on 17/04/19.\n//  Copyright © 2019 Prince  Kumar. All rights reserved.\n//   -- * Problems from codechef -> Train Partner -- ANKTRAIN * -//\n\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int T; cin>>T;\n    while(T--)\n    {\n        int n; // berth number\n        cin>>n;\n        if(n%8==0)\n        {cout<<n-1<<\"SL\"<<endl;}\n        else if(n%8==7)\n        {cout<<n+1<<\"SU\"<<endl;}\n        else if(n%8==1)\n        {cout<<n+3<<\"LB\"<<endl;}\n        else if(n%8==4)\n        {cout<<n-3<<\"LB\"<<endl;}\n        else if(n%8==2)\n        {cout<<n+3<<\"MB\"<<endl;}\n        else if(n%8==5)\n        {cout<<n-3<<\"MB\"<<endl;}\n        else if(n%8==3)\n        {cout<<n+3<<\"UB\"<<endl;}\n        else if(n%8==6)\n        {cout<<n-3<<\"UB\"<<endl;}\n    }\n}\n"
  },
  {
    "path": "Leetcode/Add Digits.cpp",
    "content": "// https://leetcode.com/problems/add-digits/\n\n\nclass Solution {\npublic:\n    \n    int addDigitsHelper(int num){\n        int sum = 0;\n        while(num != 0){\n            int digit = num % 10;\n            sum += digit;\n            num = num / 10;\n        }\n        return sum;\n    }\n    \n    int addDigits(int num) {\n        \n        while(num > 9){\n            num = addDigitsHelper(num);\n        }\n        \n        return num;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Add Two Numbers Leetcode Solutions in Linkedlist.cpp",
    "content": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n \n *     https://leetcode.com/problems/add-two-numbers/\n \n * };\n */\nclass Solution {\npublic:\n    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n        ListNode *ans = new ListNode(0);\n        ListNode *p = l1, *q=l2, *curr = ans;\n        int carry=0;\n        while(p!=NULL || q!=NULL){\n            int x = (p!=NULL) ? p->val : 0;\n            int y = (q!=NULL) ? q->val : 0;\n            int sum = carry + x+ y;\n            carry = sum/10;\n            curr->next = new ListNode(sum%10);\n            curr = curr->next;\n            if(p!=NULL) p = p->next;\n            if(q!=NULL) q = q->next;\n        }\n        if(carry>0){\n            curr->next = new ListNode(carry);\n        }\n        return ans->next;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Binary Search leetcode Solution.cpp",
    "content": "// https://leetcode.com/problems/binary-search/\n\n\nclass Solution {\npublic:\n    int search(vector<int>& nums, int target) {\n        \n        int n = (int)nums.size();\n        \n        int low = 0;\n        int high = n-1;\n        \n        while(low<=high){\n            int mid = (low+high)/2;\n            \n            if(nums[mid] == target){\n                return mid;\n            }else if(nums[mid] < target ){\n                low = mid+1;\n            }else{\n                high = mid-1;\n            }\n        }\n        \n        return -1;\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Boolean Matrix.cpp",
    "content": "// Boolean Matrix: https://practice.geeksforgeeks.org/problems/boolean-matrix-problem-1587115620/1#\n\nvoid booleanMatrix(vector<vector<int> > &matrix)\n    {\n        // code here \n        int row = matrix.size();\n        int col = matrix[0].size();\n        \n        bool arr_row[row]; fill(arr_row, arr_row+row, false);\n        bool arr_col[col]; fill(arr_col, arr_col+col, false);\n        \n        for(int i=0;i<row;i++)\n        {\n            for(int j=0;j<col;j++){\n                if(matrix[i][j] == 1){\n                    arr_row[i] = true;\n                    arr_col[j] = true;\n                }\n            }\n        }\n        \n        for(int i=0;i<row;i++){\n            if(arr_row[i]){\n                for(int j=0;j<col;j++){\n                    matrix[i][j]= 1;\n                }\n            }\n        }\n        \n        for(int i=0;i<col;i++){\n            if(arr_col[i]){\n                for(int j=0;j<row;j++){\n                    matrix[j][i] = 1;\n                }\n            }\n        }\n        \n    }\n"
  },
  {
    "path": "Leetcode/Count the Number of Consistent Strings.cpp",
    "content": "// https://leetcode.com/problems/count-the-number-of-consistent-strings/\n\nclass Solution {\npublic:\n    int countConsistentStrings(string allowed, vector<string>& words) {\n        unordered_set<char> s;\n        for(auto x: allowed)\n            s.insert(x);\n        \n        int count = 0;\n        for(auto word: words){\n            \n            bool status = true;\n            for(int i=0; i<word.size(); i++){\n                if(s.find(word[i]) == s.end()){\n                    status = false;\n                    break;\n                }\n            }\n            if(status)\n                count++;\n        }\n        \n        return count;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/All Paths From Source to Target.cpp",
    "content": "// https://leetcode.com/problems/all-paths-from-source-to-target/\n\nclass Solution {\npublic:\n    \n    void dfs(vector<vector<int>>& graph, vector<vector<int>>& ans, vector<int>&path, int curr){\n        \n        path.push_back(curr);\n        if(curr == graph.size()-1){\n            ans.push_back(path);\n        }\n        else{\n            for(auto x: graph[curr]){\n                dfs(graph, ans, path, x);\n            }\n        }\n        \n        path.pop_back();\n        \n    }\n    \n    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {\n        vector<vector<int>> ans;\n        vector<int>path;\n        \n        dfs(graph, ans, path, 0);\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Course Schedule.cpp",
    "content": "// https://leetcode.com/problems/course-schedule/\n\nclass Solution {\npublic:\n    \n    bool DFSRec(int s, vector<bool>&visited, vector<bool>&currVisited, vector<int>adj[]){\n        visited[s] = true;\n        currVisited[s] = true;\n        \n        vector<int>data = adj[s];\n        for(auto x: data){\n            if(!visited[x]){\n                if(DFSRec(x, visited, currVisited, adj)){\n                    return true;\n                }\n            }\n            else if(visited[x] && currVisited[x]){\n                return true;\n            }\n        }\n        \n        currVisited[s] = false;\n        return false;\n    }\n    \n    bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n        \n        int n = numCourses;\n        vector<bool>visited(n, false), currVisited(n, false);\n        \n        vector<int>adj[n];\n        for(auto x: prerequisites){\n            vector<int>data = x;\n            int a = data[0];\n            int b = data[1];\n            adj[a].push_back(b);\n        }\n        \n        for(int i=0; i<n; i++){\n            if(!visited[i]){\n                if(DFSRec(i, visited, currVisited, adj)){\n                    return false;\n                }\n            }\n        }\n        \n        return true;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Detect cycle in a directed graph.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/detect-cycle-in-a-directed-graph/1\n\nclass Solution {\n  public:\n    // Function to detect cycle in a directed graph.\n    \n    bool cycle(int s, vector<bool>&visited, vector<bool>&currVisited, vector<int> adj[]){\n        visited[s] = true;\n        currVisited[s] = true;\n        \n        for(auto x: adj[s]){\n            if(!visited[x]){\n                if(cycle(x, visited, currVisited, adj))\n                    return true;\n            }\n            else if(visited[x] == true && currVisited[x] == true){\n                return true;\n            }\n        }\n        \n        currVisited[s] = false;\n        return false;\n    }\n    \n    bool isCyclic(int V, vector<int> adj[]) {\n        // code here\n        vector<bool>visited(V, false), currVisited(V, false);\n        for(int i=0; i<V; i++){\n            if(!visited[i]){\n                if(cycle(i, visited, currVisited, adj))\n                    return true;\n            }\n        }\n        \n        return false;\n    }\n};\n\n"
  },
  {
    "path": "Leetcode/Graph/Find Eventual Safe States.cpp",
    "content": "// https://leetcode.com/problems/find-eventual-safe-states/\n\nclass Solution {\npublic:\n    \n    bool DFSRec(int s, vector<bool>&visited, vector<bool>&dfsVisited, vector<vector<int>>& graph, vector<bool> &present_cycle){\n        visited[s] = true;\n        dfsVisited[s] = true;\n        \n        vector<int>data = graph[s];\n        for(auto x: data){\n            if(!visited[x]){\n                if(DFSRec(x, visited, dfsVisited, graph, present_cycle)){\n                    return present_cycle[s] = true;\n                }\n            }\n            else if(visited[x] && dfsVisited[x]){\n                return present_cycle[s] = true;\n            }\n        }\n        \n        dfsVisited[s] = false;\n        return false;\n    }\n    \n    vector<int> eventualSafeNodes(vector<vector<int>>& graph) {\n        vector<int> ans;\n        \n        int n = graph.size();\n        vector<bool>visited(n, false), dfsVisited(n, false);\n        vector<bool> present_cycle(n, false);\n        \n        for(int i=0; i<n; i++){\n            if(!visited[i]){\n                DFSRec(i, visited, dfsVisited,graph, present_cycle);\n            }\n        }\n        \n        for(int i=0; i<n; i++){\n            if(!present_cycle[i]){\n                ans.push_back(i);\n            }\n        }\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Find if Path Exists in Graph.cpp",
    "content": "// https://leetcode.com/problems/find-if-path-exists-in-graph/\n\nclass Solution {\npublic:\n    bool validPath(int n, vector<vector<int>>& edges, int start, int end) {\n        \n        unordered_map<int, vector<int>> umap;\n        for(auto x: edges){\n            vector<int>temp = x;\n            \n            int u = temp[0];\n            int v = temp[1];\n            \n            umap[u].push_back(v);\n            umap[v].push_back(u);\n        }\n        \n        vector<bool>visited(n+1, false);\n        \n        queue<int>q;\n        q.push(start);\n        visited[start] = true;\n        \n        while(!q.empty()){\n            \n            int v = q.front();\n            q.pop();\n            \n            vector<int>temp = umap[v];\n            for(int i=0; i<temp.size(); i++){\n                int vertex = temp[i];\n                if(visited[vertex] == false){\n                    q.push(vertex);\n                    visited[vertex] = true;\n                }\n\n            }\n            \n            if(visited[end])\n                return visited[end];\n        }\n        \n        return visited[end];\n        \n        \n        \n        \n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Find the Town Judge.cpp",
    "content": "// https://leetcode.com/problems/find-the-town-judge/\n\nclass Solution {\npublic:\n    int findJudge(int n, vector<vector<int>>& trust) {\n        \n        vector<int>data(n+1, 0);\n        for(auto x: trust)\n        {\n            data[x[0]]--;\n            data[x[1]]++;\n        }\n        \n        for(int i=1; i<=n; i++){\n            int x = data[i];\n            if(x == n-1)\n                return i;\n        }\n        \n        return -1;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Flood Fill.cpp",
    "content": "// https://leetcode.com/problems/flood-fill/\n\nclass Solution {\npublic:\n    \n    bool isValid(vector<vector<int>>& image, int i, int j, int n, int m , int color){\n        \n        if(i>=0 && i<n && j>=0 && j<m && image[i][j] == color)\n            return true;\n        \n        return false;\n    }\n        \n    void floodFillRec(vector<vector<int>>& image, int i, int j, int n, int m , int color, int newColor){\n        \n        image[i][j] = newColor;\n        \n        if(isValid(image, i+1, j, n, m , color))\n            floodFillRec(image, i+1, j, n, m , color, newColor);\n        \n        if(isValid(image, i-1, j, n, m , color))\n            floodFillRec(image, i-1, j, n, m , color, newColor);\n        \n        if(isValid(image, i, j+1, n, m , color))\n            floodFillRec(image, i, j+1, n, m , color, newColor);\n        \n        if(isValid(image, i, j-1, n, m , color))\n            floodFillRec(image, i, j-1, n, m , color, newColor);\n    }\n    \n    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {\n        \n        int n = image.size();\n        int m = image[0].size();\n        \n        int color = image[sr][sc];\n        \n        if(color == newColor)\n            return image;\n        \n        floodFillRec(image, sr, sc, n, m, color, newColor);\n        \n        return image;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Keys and Rooms.cpp",
    "content": "// https://leetcode.com/problems/keys-and-rooms/\n\nclass Solution {\npublic:\n    bool canVisitAllRooms(vector<vector<int>>& rooms) {\n        \n        int n = rooms.size();\n        vector<bool>visited(n, false);\n        \n        queue<int>q;\n        q.push(0);\n        visited[0] = true;\n        \n        while(!q.empty()){\n            int room = q.front();\n            q.pop();\n            \n            for(auto key : rooms[room]){\n                if(!visited[key]){\n                    visited[key] = true;\n                    q.push(key);\n                }\n            }\n        }\n        \n        \n        for(auto x: visited){\n            if(!x)\n                return x;\n        }\n        \n        return true;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Max Area of Island.cpp",
    "content": "// https://leetcode.com/problems/max-area-of-island/\n\nclass Solution {\npublic:\n    \n    bool isValid(int i, int j, int n, int m, vector<vector<int>>& grid){\n        if(i>=0 && i<n && j>=0 && j<m && grid[i][j] == 1){\n            return true;\n        }\n        return false;\n    }\n    \n    void dfs(vector<vector<int>>& grid, int i, int j, int n, int m, int &area){\n        area++;\n        grid[i][j] = 0;\n        \n        if(isValid(i+1, j, n, m, grid)){\n            dfs(grid, i+1, j, n, m, area);\n        }\n        if(isValid(i-1, j, n, m, grid)){\n            dfs(grid, i-1, j, n, m, area);\n        }\n        if(isValid(i, j+1, n, m, grid)){\n            dfs(grid, i, j+1, n, m, area);\n        }\n        if(isValid(i, j-1, n, m, grid)){\n            dfs(grid, i, j-1, n, m, area);\n        }\n    }\n    \n    int maxAreaOfIsland(vector<vector<int>>& grid) {\n        \n        int n = grid.size();\n        int m = grid[0].size();\n        int ans = 0;\n        \n        for(int i=0; i<n;i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == 1){\n                    int area = 0;\n                    dfs(grid, i, j, n, m, area);\n                    ans = max(ans, area);\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Minimum Time to Collect All Apples in a Tree.cpp",
    "content": "// https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree/\n\nclass Solution {\npublic:\n    vector<bool>visited;\n    int dfs(vector<vector<int>>&adj, int node, int mycost, vector<bool>& hasApple){\n        if(visited[node]) return 0;\n        visited[node]= true;\n\n        int childCost = 0;\n        for(auto x: adj[node]){\n            childCost += dfs(adj, x, 2, hasApple);\n        }\n        if(childCost == 0 && !hasApple[node]) return 0;\n        return childCost + mycost;\n    }\n    int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {\n        vector<vector<int>>adj(n, vector<int>(0, -1));\n        for(auto x: edges){\n            adj[x[0]].push_back(x[1]);\n            adj[x[1]].push_back(x[0]);\n        }\n        for(int i=0; i<n; i++){visited.push_back(false);}\n        int time = 0;\n        time = dfs(adj, 0, 0, hasApple);\n        return time;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Number of Enclaves.cpp",
    "content": "// https://leetcode.com/problems/number-of-enclaves/\n\nclass Solution {\npublic:\n    \n    int count(vector<vector<int>>& grid){\n        int n = grid.size();\n        int m = grid[0].size();\n        int ans = 0;\n        \n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == 1)\n                    ans++;\n            }\n        }\n        \n        return ans;\n    }\n    \n    bool isValid(int i, int j, int n, int m, vector<vector<int>>& grid){\n        if(i>=0 && i<n && j>=0 && j<m && grid[i][j] == 1 ){\n            return true;\n        }\n        return false;\n    }\n    \n    void dfs(int i, int j, int n, int m, vector<vector<int>>& grid){\n        grid[i][j] = 0;\n        \n        int ax[4] = {1, -1, 0, 0};\n        int ay[4] = {0, 0, 1, -1};\n        \n        for(int k=0; k<4; k++){\n            int nx = i + ax[k];\n            int ny = j + ay[k];\n            \n            if(isValid(nx,ny, n, m, grid)){\n                dfs(nx, ny, n, m, grid);\n            }\n        }\n    }\n    \n    int numEnclaves(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        \n        // boundary travers\n        for(int i=0; i<n; i++){\n            \n            int j = 0;\n            if(grid[i][j] == 1){\n                dfs(i, j, n, m, grid);\n            }\n            \n            j = m-1;\n            if(grid[i][j] == 1){\n                dfs(i, j, n, m, grid);\n            }\n            \n        }\n        \n        \n        for(int j=0; j<m; j++){\n            \n            int i = 0;\n            if(grid[i][j] == 1){\n                dfs(i, j, n, m, grid);\n            }\n            \n            i = n-1;\n            if(grid[i][j] == 1){\n                dfs(i, j, n, m, grid);\n            }\n            \n        }\n        \n        return count(grid);\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Number of Islands.cpp",
    "content": "// https://leetcode.com/problems/number-of-islands/\n\nclass Solution {\npublic:\n    \n    \n    bool isValid(int i, int j, int n , int m, vector<vector<char>>& grid){\n        if(i>=0 && i<n && j>=0 && j<m && grid[i][j] == '1')\n            return true;\n        \n        return false;\n    }\n    \n    void numIslandsRec(int i, int j, int n , int m, vector<vector<char>>& grid){\n        \n        grid[i][j] = '0';\n        \n        if(isValid(i+1, j, n, m , grid))\n            numIslandsRec(i+1, j, n, m, grid);\n        \n        if(isValid(i-1, j, n, m , grid))\n            numIslandsRec(i-1, j, n, m, grid);\n        \n        if(isValid(i, j+1, n, m , grid))\n            numIslandsRec(i, j+1, n, m, grid);\n        \n        if(isValid(i, j-1, n, m , grid))\n            numIslandsRec(i, j-1, n, m, grid);\n        \n    }\n    \n    int numIslands(vector<vector<char>>& grid) {\n        \n        int n = grid.size();\n        int m = grid[0].size();\n        int ans = 0;\n        \n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == '1'){\n                    ans++;\n                    numIslandsRec(i, j, n, m, grid);\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Number of Provinces.cpp",
    "content": "// https://leetcode.com/problems/number-of-provinces/\n\nclass Solution {\npublic:\n    \n    void dfs(int s, int n, vector<vector<int>>& isConnected, vector<bool>&visited){\n        visited[s] = true;\n        // s = 1\n        \n        // 0 1 2 3 4  -- index\n        // 1 2 3 4 5  -- city name\n        // 1 1 0 1 0  -- connection\n        \n        vector<int>adj;\n        for(int i=0; i<n; i++ ){\n            int x =  isConnected[s][i];  // x = connection\n            if(x == 1)\n                adj.push_back(i);\n        }\n        \n        for(auto x: adj){\n            if(!visited[x]){\n                dfs(x, n, isConnected, visited);\n            }\n        }\n        \n        \n    }\n    \n    int findCircleNum(vector<vector<int>>& isConnected) {\n        \n        int n = isConnected.size();\n        vector<bool>visited(n, false);\n        int count = 0;\n        \n        for(int i=0; i<n; i++){\n            if(!visited[i]){\n                count++;\n                dfs(i, n, isConnected, visited);\n            }\n        }\n        \n        return count;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Number of closed Islands.cpp",
    "content": "// https://leetcode.com/problems/number-of-closed-islands/\n\nclass Solution {\npublic:\n    \n    \n    bool isValid(int i, int j, int n, int m ,vector<vector<int>>& grid){\n        if(i>=0 && i<n && j>=0 && j<m && grid[i][j] == 0){\n            return true;\n        }\n        return false;\n    }\n    \n    void dfs(int i, int j, int n, int m ,vector<vector<int>>& grid){\n        grid[i][j] = 1;\n        \n        int ax[4] = {1, -1, 0, 0};\n        int ay[4] = {0, 0, 1, -1};\n        \n        for(int k =0; k<4; k++){\n            int nx = i + ax[k];\n            int ny = j + ay[k];\n            \n            if(isValid(nx, ny, n, m, grid)){\n                dfs(nx, ny, n, m, grid);\n            }\n        }\n    }\n    \n    int closedIsland(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        // boundary DFS\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(i*j == 0 || i == n-1 || j==m-1){\n                    // cout<<i<<\" \"<<j<<endl;\n                    if(grid[i][j] == 0){\n                        dfs(i, j, n, m, grid);\n                    }\n                }\n            }\n        }\n        \n        // call DFS in whole grid\n        int ans = 0;\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == 0){\n                    ans++;\n                    dfs(i, j, n, m, grid);\n                }\n            }\n        }\n        \n        return ans;\n    }\n    \n};\n"
  },
  {
    "path": "Leetcode/Graph/Rotting Oranges.cpp",
    "content": "// https://leetcode.com/problems/rotting-oranges/\n\nclass Solution {\npublic:\n    \n    \n    bool isValid(int i, int j, int n, int m, vector<vector<int>>& grid){\n        if(i>=0 && i<n && j>=0 && j<m && grid[i][j] == 1){\n            return true;\n        }\n        return false;\n    }\n    \n    int orangesRotting(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        int fresh = 0, time = 0;\n        queue<pair<int, int>>q;\n        \n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == 2){\n                    // push into queue\n                    q.push({i, j});\n                }\n                else if(grid[i][j] == 1){\n                    fresh++;\n                }\n            }\n        }\n        if(fresh == 0) return 0;\n        \n        // start BFS traversal\n        while(!q.empty()){\n            \n            int size_q = q.size();\n            int temp = 0;\n            while(size_q != 0){\n                \n                pair<int, int>p = q.front();\n                q.pop();\n                \n                int x1 = p.first;\n                int y1 = p.second;\n                \n                int ax[4] = { 1, -1, 0, 0};\n                int ay[4] = { 0, 0 , 1 , -1};\n                \n                for(int i=0; i<4; i++){\n                    int x = ax[i] + x1;\n                    int y = ay[i] + y1;\n                    \n                    if(isValid(x, y, n, m, grid)){\n                        temp++;\n                        grid[x][y] = 2;\n                        q.push({x, y});\n                    }\n                }\n                \n                size_q--;\n                \n            }\n            if(temp != 0) time++;\n        }\n        \n        \n        \n        // we checked if any fresh oranges are still there\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == 1){\n                    time = 0;\n                    break;\n                }\n            }\n        }\n        \n        \n        \n        return (time == 0) ? -1 : time ;\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Steps by Knight.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/steps-by-knight5927/1\n\nclass Solution \n{\n    public:\n    //Function to find out minimum steps Knight needs to reach target position.\n    \n    bool isValid(int i, int j, int n, vector<vector<bool>>&visited){\n        if(i>=0 && i<n && j>=0 && j<n && visited[i][j] == false){\n            return true;\n        }\n        return false;\n    }\n    \n\tint minStepToReachTarget(vector<int>&KnightPos,vector<int>&TargetPos,int N)\n\t{\n\t    // Code here\n\t    int n = N;\n\t    int tx = TargetPos[0]-1, ty = TargetPos[1]-1;\n\t    int x1 = KnightPos[0]-1, y1 = KnightPos[1]-1;\n\t    \n\t    if(x1 == tx && y1 == ty) return 0;\n\t    \n\t    vector<vector<bool>>visited(n, vector<bool>(n, false));\n\t    \n\t    queue<pair<int, int>>q;\n\t    q.push({x1, y1});\n\t    visited[x1][y1] = true;\n\t    \n\t    int ans = 0;\n\t    while(!q.empty()){\n\t        \n\t        int size = q.size();\n\t        ans++;\n\t        while(size != 0){\n\t            pair<int,int>p = q.front();\n\t            q.pop();\n\t            \n\t            int xx = p.first;\n\t            int yy = p.second;\n\t            \n\t            int ax[8] = {1, 1, -1, -1, 2, -2, 2, -2};\n\t            int ay[8] = {2, -2, 2, -2, 1, 1, -1, -1};\n\t            \n\t            for(int i=0; i<8; i++){\n\t                int nx = xx + ax[i];\n\t                int ny = yy + ay[i];\n\t                \n\t                if(nx == tx && ny == ty) return ans;\n\t                \n\t                if(isValid(nx, ny, n, visited)){\n\t                    visited[nx][ny] = true;\n\t                    q.push({nx, ny});\n\t                }\n\t            }\n\t           \n\t            size--;\n\t        }\n\t    }\n\t    \n\t    \n\t    return ans;\n\t    \n\t    \n\t}\n};\n"
  },
  {
    "path": "Leetcode/Graph/Surrounded Regions.cpp",
    "content": "// https://leetcode.com/problems/surrounded-regions/\n\nclass Solution {\npublic:\n    \n    void convert(vector<vector<char>>& board){\n        int n = board.size();\n        int m = board[0].size();\n        \n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(board[i][j] == 'B'){\n                    board[i][j] = 'O';\n                }\n                else if(board[i][j] == 'O'){\n                    board[i][j] = 'X';\n                }\n            }\n        }\n    }\n    \n    bool isValid(int i , int j, int n, int m, vector<vector<char>>& board){\n        if(i>=0 && i<n && j>=0 && j<m && board[i][j] == 'O'){\n            return true;\n        }\n        return false;\n    }\n    \n    void dfs(vector<vector<char>>& board, int i , int j, int n, int m){\n        board[i][j] = 'B';\n        \n        if(isValid(i+1, j, n, m, board)){\n            dfs(board, i+1, j, n, m);\n        }\n        if(isValid(i-1, j, n, m, board)){\n            dfs(board, i-1, j, n, m);\n        }\n        if(isValid(i, j+1, n, m, board)){\n            dfs(board, i, j+1, n, m);\n        }\n        if(isValid(i, j-1, n, m, board)){\n            dfs(board, i, j-1, n, m);\n        }\n    }\n    \n    void solve(vector<vector<char>>& board) {\n        int n = board.size();\n        int m = board[0].size();\n        \n        for(int i=0; i<n; i++){\n            \n            // left -> top bottom\n            int j =0;\n            if(board[i][j] == 'O'){\n                dfs(board, i, j, n, m);\n            }\n            \n            j = m-1;\n            // right -> top bootm \n            if(board[i][j] == 'O'){\n                dfs(board, i, j, n, m);\n            }\n        }\n        \n        for(int j=0; j<m; j++){\n            \n            // top -> left right\n            int i =0;\n            if(board[i][j] == 'O'){\n                dfs(board, i, j, n, m);\n            }\n            \n            i = n-1;\n            // bottom -> left right\n            if(board[i][j] == 'O'){\n                dfs(board, i, j, n, m);\n            }\n        }\n        \n        convert(board);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Time Needed to Inform All Employees.cpp",
    "content": "// https://leetcode.com/problems/time-needed-to-inform-all-employees/\n\n\nclass Solution {\npublic:\n    \n    unordered_map<int, vector<int>>umap;\n    int ans =0 , mx= 0;\n    \n    void dfs(int manager, vector<int>& informTime){\n        mx = max(mx, ans);\n        for(auto employee : umap[manager]){\n            ans += informTime[manager];\n            \n            dfs(employee, informTime);\n            \n            ans -= informTime[manager];\n        }\n        \n    }\n    \n    int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n        \n        // Fill umap\n        for(int i=0; i<n; i++){\n            int val = manager[i];\n            if(val != -1){\n                umap[val].push_back(i);\n            }\n        }\n        \n        dfs(headID, informTime);\n        return mx;\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Graph/Topological sort .cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/topological-sort/1\n\nclass Solution\n{\n\tpublic:\n\t//Function to return list containing vertices in Topological order. \n\tvector<int> topoSort(int V, vector<int> adj[]) \n\t{\n\t    // code here\n\t    vector<int> ans;\n\t    queue<int>q;\n\t    \n\t    vector<int> indegree(V, 0);\n\t    for(int i=0; i<V; i++){\n\t        vector<int> data = adj[i];\n\t        for(auto x: data){\n\t            indegree[x]++;\n\t        }\n\t    }\n\t    \n\t    for(int i=0; i<V; i++){\n\t        if(indegree[i] == 0)\n\t            q.push(i);\n\t    }\n\t    \n\t    while(! q.empty()){\n\t        int u = q.front();\n\t        q.pop();\n\t        ans.push_back(u);\n\t        \n\t        for(auto v: adj[u]){\n\t            indegree[v]--;\n\t            if(indegree[v] == 0)\n\t                q.push(v);\n\t        }\n\t    }\n\t    \n\t    return ans;\n\t}\n};\n"
  },
  {
    "path": "Leetcode/Graph/Topological sort using dfs.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/topological-sort/1\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n // } Driver Code Ends\nclass Solution\n{\n\tpublic:\n\t//Function to return list containing vertices in Topological order. \n\t\n\tvoid DFSRec(int s, stack<int>&st, vector<bool>&visited, vector<int> adj[]){\n\t    visited[s] = true;\n\t    \n\t    vector<int>data = adj[s];\n\t    for(auto v: data){\n\t        if(!visited[v]){\n\t            DFSRec(v, st, visited, adj);\n\t        }\n\t    }\n\t    \n\t    st.push(s);\n\t}\n\t\n\tvector<int> topoSort(int V, vector<int> adj[]) \n\t{\n\t    // code here\n\t    stack<int>st;\n\t    vector<bool>visited(V, false);\n\t    \n\t    for(int i=0; i<V; i++){\n\t        if(!visited[i]){\n\t            DFSRec(i, st, visited, adj);\n\t        }\n\t    }\n\t    \n\t    vector<int>ans;\n\t    while(!st.empty()){\n\t        int x = st.top();\n\t        st.pop();\n\t        ans.push_back(x);\n\t    }\n\t    \n\t    return ans;\n\t    \n\t}\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Check if two arrays are equal or not.cpp",
    "content": "// Question Link: https://practice.geeksforgeeks.org/problems/check-if-two-arrays-are-equal-or-not3847/1\n\nclass Solution{\n    public:\n\n    //Function to check if two arrays are equal or not.\n    bool check(vector<ll> A, vector<ll> B, int n) {\n        //code here\n        unordered_map<ll,ll>umap;\n        for(int i=0;i<n;i++)\n            umap[A[i]]++;\n        for(int i=0;i<n;i++){\n            ll key = B[i];\n            if(umap.find(key)!=umap.end()){\n                auto itr = umap.find(key);\n                \n                if(itr->second>0)\n                    itr->second--;\n                else\n                    return false;\n                \n            }else\n                return false;\n        }\n        \n        return true;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Custom Sort String.cpp",
    "content": "// https://leetcode.com/problems/custom-sort-string/\n\nclass Solution {\npublic:\n    string customSortString(string order, string str) {\n        map<char, int>mp;\n        string ans = \"\";\n        \n        for(auto x: str)\n            mp[x]++;\n        for(auto x: order){\n            if(mp.find(x)!=mp.end()){\n                auto temp = mp.find(x);\n                int count = temp->second;\n                // c-> 5  || ccccc\n                string s(count, x);\n                ans+=s;\n                mp.erase(x);\n            }\n        }\n        \n        for(auto x: mp){\n            string s(x.second, x.first);\n            ans+=s;\n        }\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/First Repeating Element.cpp",
    "content": "// Question Link: https://practice.geeksforgeeks.org/problems/first-repeating-element4018/1\n\nclass Solution{\n    public:\n    //Function to return the position of the first repeating element.\n    int firstRepeated(int arr[], int n) {\n        //code here\n        unordered_map<int,int> umap;\n        for(int i=0;i<n;i++)\n            umap[arr[i]]++;\n        for(int i=0;i<n;i++){\n            int key = arr[i];\n            \n            auto temp = umap.find(key); \n            int val= temp->second;\n            if(val >1)\n                return i+1;\n        }\n        \n        return -1;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Group Anagrams.cpp",
    "content": "// https://leetcode.com/problems/group-anagrams/\n\nclass Solution {\npublic:\n    vector<vector<string>> groupAnagrams(vector<string>& strs) {\n        vector<vector<string>> ans;\n        unordered_map<string, vector<string>>umap;\n        \n        for(auto x: strs){\n            string temp = x;\n            sort(x.begin(), x.end());\n            umap[x].push_back(temp);\n        }\n      \n        for(auto x : umap){\n            ans.push_back(x.second);\n        }\n        return ans;\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Intersection of two arrays.cpp",
    "content": "// Question Link: https://practice.geeksforgeeks.org/problems/intersection-of-two-arrays2404/1\n\nint NumberofElementsInIntersection (int a[], int b[], int n, int m )\n{\n    // Your code goes here\n    unordered_set<int>s;\n    for(int i=0;i<n;i++)    \n        s.insert(a[i]);\n    \n    int count=0;\n    for(int i=0;i<m;i++){\n        int key = b[i];\n        if(s.find(key)!=s.end()){\n            count++;\n            s.erase(key);\n        }\n    }\n    return count;\n}\n"
  },
  {
    "path": "Leetcode/Hashing/Key Pair.cpp",
    "content": "// Problem Link: https://practice.geeksforgeeks.org/problems/key-pair5616/1\n\nclass Solution{\npublic:\t\n\t// Function to check if array has 2 elements\n\t// whose sum is equal to the given value\n\tbool hasArrayTwoCandidates(int arr[], int n, int x) {\n\t    // code here\n\t    unordered_map<int,int> umap;\n\t    for(int i=0;i<n;i++)\n\t        umap[arr[i]]++;\n\t    for(auto itr = umap.begin(); itr!=umap.end(); itr++){\n\t        int key = itr->first;\n\t        int val = itr->second;\n\t        \n\t        int pair = x-key;\n\t        if(pair==key){\n\t            if(val>1)\n\t                return true;\n\t        }else{\n\t            if(umap.find(pair)!=umap.end())\n\t                return true;\n\t        }\n\t    }\n\t    \n\t    return false;\n\t}\n};\n"
  },
  {
    "path": "Leetcode/Hashing/LFU Cache.cpp",
    "content": "/* https://leetcode.com/problems/lfu-cache/ */\n\nclass LFUCache {\npublic:\n    int capacity, minFreq;\n    unordered_map<int, pair<int, int>>keyVal;\n    unordered_map<int, list<int>> freqList;\n    unordered_map<int, list<int>::iterator > pos;\n\n    void updateFreq(int key){\n        // update the Frequency  \n        // -- delete key from curr_freq \n        // -- increment freq \n        // -- insert key in new freq\n        // -- update new pos of key\n        // -- check for minFreq \n        int curr_freq = keyVal[key].second; \n        freqList[curr_freq].erase(pos[key]);\n\n        keyVal[key].second++;\n        curr_freq = keyVal[key].second;\n\n        freqList[curr_freq].push_back(key);\n\n        pos[key] = --freqList[curr_freq].end();\n\n        if(freqList[minFreq].empty()){\n            minFreq++;\n        }\n    }\n\n    LFUCache(int capacity) {\n        this->capacity = capacity;\n        minFreq = 0;\n    }\n    int get(int key) {\n        if(keyVal.find(key) == keyVal.end()){\n            return -1;\n        }\n        updateFreq(key);\n        return keyVal[key].first;\n    }\n    \n    void put(int key, int value) {\n        if(capacity == 0) return;\n        if(keyVal.find(key) != keyVal.end()){\n            // update Case\n            keyVal[key].first = value;\n            updateFreq(key);\n            return;\n        }\n        if(keyVal.size() == capacity){\n            // Find the LRU;\n            int delKey = freqList[minFreq].front();\n            keyVal.erase(delKey);\n            pos.erase(delKey);\n            freqList[minFreq].pop_front();\n        }\n        keyVal[key] = {value, 1};\n        freqList[1].push_back(key);\n        pos[key] = --freqList[1].end();\n        minFreq = 1;\n    }\n};\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache* obj = new LFUCache(capacity);\n * int param_1 = obj->get(key);\n * obj->put(key,value);\n */\n"
  },
  {
    "path": "Leetcode/Hashing/Non-Repeating Element.cpp",
    "content": "// Question Link: https://practice.geeksforgeeks.org/problems/non-repeating-element3958/1\n\n\nclass Solution{\n    public:\n    int firstNonRepeating(int arr[], int n) \n    { \n        // Complete the function\n        unordered_map<int, int> umap;\n        for(int i=0;i<n;i++)\n            umap[arr[i]]++;\n        \n        // int key = arr[i];\n        // umap[key]++;\n        \n        for(int i=0;i<n;i++){\n            int key = arr[i];\n            auto temp = umap.find(key);\n            if(temp->second ==1)\n                return key;\n        }\n        \n        return 0;\n    } \n  \n};\n"
  },
  {
    "path": "Leetcode/Hashing/Pairs with Positive Negative values.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/pairs-with-positive-negative-values3719/1\n\n\nclass Solution{\n  public:\n    vector<int> PosNegPair(int a[], int n) {\n        vector<int>v, ans;\n        map<int,int>mp;\n        \n        for(int i=0;i<n;i++){\n            if(a[i]<0)\n                v.push_back(a[i]);\n            else\n                mp[a[i]]++;\n        }\n        \n        sort(v.begin(), v.end());\n        \n        for(int i=(int)v.size()-1; i>=0 ; i--){\n            int data = abs(v[i]);\n            if(mp[data]>0){\n                ans.push_back(v[i]);\n                ans.push_back(data);\n                mp[data]-=1;\n            }\n        }\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Relative Sort Array.cpp",
    "content": "// https://leetcode.com/problems/relative-sort-array/\n\nclass Solution {\npublic:\n    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {\n        vector<int> ans;\n        \n        map<int, int>mp;\n        for(auto x: arr1)\n            mp[x]++;\n        for(auto temp :  arr2){\n            if(mp.find(temp)!=mp.end()){\n                auto x  = mp.find(temp);\n                int count = x->second;  // 5->2\n                vector<int>v(count, temp); // v = 5 5 \n                ans.insert(ans.end(), v.begin(), v.end());\n                mp.erase(temp);\n            }\n        }\n        \n        for(auto x : mp){\n            int ele = x.first;\n            int count = x.second;\n            vector<int>v(count, ele);\n            ans.insert(ans.end(), v.begin(), v.end());\n        }\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Sort Array by Increasing Frequency.cpp",
    "content": "// https://leetcode.com/problems/sort-array-by-increasing-frequency/\n\nclass Solution {\npublic:\n    vector<int> frequencySort(vector<int>& nums) {\n        unordered_map<int, int>umap;\n        for(auto x: nums){\n            umap[x]++;\n        }\n        \n        sort(nums.begin(), nums.end() , [&](int a , int b) \n             { return  umap[a] != umap[b] ? umap[a] < umap[b] :  a > b ; } );\n        \n        return nums;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Subarray with 0 sum.cpp",
    "content": "// Link: https://practice.geeksforgeeks.org/problems/subarray-with-0-sum-1587115621/1\n\nclass Solution{\n    public:\n    //Complete this function\n    //Function to check whether there is a subarray present with 0-sum or not.\n    bool subArrayExists(int arr[], int n)\n    {\n        //Your code here\n        unordered_set<int>s;\n        int pre_sum=0;\n        for(int i=0;i<n;i++){\n            pre_sum += arr[i];\n            \n            if(pre_sum == 0)\n                return true;\n            if(s.find(pre_sum)!=s.end())\n                return true;\n            \n            s.insert(pre_sum);\n        }\n        return false;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Hashing/Winner of an election.cpp",
    "content": "//  https://practice.geeksforgeeks.org/problems/winner-of-an-election-where-votes-are-represented-as-candidate-names-1587115621/1\n\nclass Solution{\n  public:\n  \n    //Function to return the name of candidate that received maximum votes.\n    vector<string> winner(string arr[],int n)\n    {\n        // Your code here\n        // Return the string containing the name and an integer\n        // representing the number of votes the winning candidate got\n        \n        unordered_map<string , int>umap;\n        for(int i=0;i<n;i++){\n            umap[arr[i]]++;\n        }\n        \n        string name = \"\";\n        int max_vote = 0;\n        \n        for(auto itr = umap.begin(); itr!=umap.end(); itr++){\n            string key = itr->first;\n            int val = itr->second;\n            \n            if(val>max_vote){\n                max_vote = val;\n                name = key;\n            }\n            else if(val == max_vote){\n                if(key<name)\n                    name = key;\n            }\n        }\n        \n        vector<string> ans;\n        ans.push_back(name);\n        string temp = to_string(max_vote);\n        ans.push_back(temp);\n        \n        return ans;\n    }  \n};\n"
  },
  {
    "path": "Leetcode/Hashing/unordered_map.cpp",
    "content": "#include<bits/stdc++.h>\n#include<unordered_map>\n\nusing namespace std;\nint main(){\n    unordered_map<string,int> umap;\n    umap[\"prince\"] = 44;\n    umap[\"gfg\"] = 56;\n    umap[\"helloworld\"] = 90;\n\n    for(auto x : umap)\n        cout<<x.first<<\" \"<<x.second<<endl;\n\n    \n\n    string key = \"prince\";\n    \n    if(umap.find(key) != umap.end())\n        cout<<\"key found\"<<endl;\n    else \n        cout<<\"key not found\"<<endl;\n\n    if(umap.find(key) != umap.end()){\n        auto temp = umap.find(key);\n        cout<<\"key is : \"<<temp->first<<endl;\n        cout<<\"value is : \"<<temp->second<<endl;\n    }\n\n    umap.insert(make_pair(\"mobile\", 17000));\n\n    key = \"helloworld\";\n    umap.erase(key);\n\n    for(auto itr = umap.begin() ; itr!=umap.end() ; itr++)\n        cout<<itr->first<<\" \"<<itr->second<<endl;\n\n    cout<<umap.size()<<endl;\n\n\n    int arr[] = {7, 1, 0, 3, 5, 0, 1, 3, 2, 5, 7, 3, 8, 9, 9};\n    unordered_map<int,int> umaped;\n\n    for(int i=0;i<15;i++){\n        int key = arr[i];\n        umaped[key]++;\n    }\n\n\n    for(auto itr = umaped.begin() ; itr!=umaped.end() ; itr++)\n        cout<<itr->first<<\" \"<<itr->second<<endl;\n}\n"
  },
  {
    "path": "Leetcode/Hashing/unordered_set.cpp",
    "content": "#include<bits/stdc++.h>\n#include<unordered_set>\n\nusing namespace std;\nint main(){\n\n    unordered_set<int> s;\n    s.insert(10);\n    s.insert(5);\n    s.insert(15);\n    s.insert(20);\n    \n    for(auto it = s.begin() ; it!=s.end() ;it++)\n        cout<<(*it)<<endl;\n    \n    cout<<\"number of element : \"<<s.size()<<endl;\n\n    s.clear();\n    cout<<\"number of element : \"<<s.size()<<endl;\n\n\n    int key = 20;\n\n    if(s.find(key) == s.end()){\n        cout<<\"key not found\"<<endl;\n    }else{\n        \n        auto temp = s.find(key);\n        s.erase(temp);\n\n    }\n\n    int deleted_key = 25;\n    s.erase(deleted_key);\n\n    for(auto it = s.begin() ; it!=s.end() ;it++)\n        cout<<(*it)<<endl;\n\n    cout<<\"number of element : \"<<s.size()<<endl;\n\n\n    if(s.find(key)!=s.end())\n        cout<<\"key found\"<<endl;\n\n\n    if(s.count(5))\n        cout<<\"key found\"<<endl;\n    else\n        cout<<\"not found\"<<endl;\n}\n"
  },
  {
    "path": "Leetcode/Interchanging the rows of a Matrix.cpp",
    "content": "// problems: https://practice.geeksforgeeks.org/problems/reversing-the-rows-of-a-matrix-1587115621/1/?track=DSASP-Matrix&batchId=154\n\n\nvoid interchangeRows(vector<vector<int> > &matrix)\n    {\n        // code here\n        int row = matrix.size();\n        int col = matrix[0].size();\n        \n        for(int i=0;i<(row/2);i++){\n            for(int j=0;j<col;j++)\n                swap(matrix[i][j], matrix[row-1-i][j]);\n        }\n    }\n"
  },
  {
    "path": "Leetcode/Majority Element Geeksforgeeks leetcode Moore's Voting Algorithm.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/majority-element/0\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n// Function to find majority element in the array\nint majorityElement(int arr[], int n)\n{\n    int count=1; int res=0;\n    for(int i=1; i<n; i++){\n        if(arr[res] == arr[i])\n            count++;\n        else\n            count--;\n            \n        if(count==0){\n            count=1;\n            res=i;\n        }\n    }\n    \n    //2nd   res \n    count=0;\n    for(int i=0;i<n;i++){\n        if(arr[res]==arr[i])\n            count++;\n    }\n    \n    if(count <= (n/2))\n        return -1;\n    else\n        return arr[res];\n}\n\nint main(){\n\n    int t;\n    cin >> t;\n\n    while(t--){\n        int n;\n        cin >> n;\n        int arr[n];\n        \n        for(int i = 0;i<n;i++){\n            cin >> arr[i];\n        }\n        \n        cout << majorityElement(arr, n) << endl;\n    }\n\n    return 0;\n}\n"
  },
  {
    "path": "Leetcode/Median of Two sorted arrays.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/median-of-two-sorted-arrays1618/1/?track=DSASP-Searching&batchId=154\n\n\n// arr : given array with size n \n// brr : given array with size m\nint findMedian(int arr[], int n, int brr[], int m){\n    // code here\n    int begin1 = 0 ; int end1 = n;\n    while(begin1<=end1){\n        int i1 = (begin1+end1)/2;\n        int i2 = (n+m+1)/2 - i1;\n        \n        int min1 = (i1==n) ? INT_MAX : arr[i1];\n        int max1 = (i1==0) ? INT_MIN : arr[i1-1];\n        \n        int min2 = (i2==m) ? INT_MAX : brr[i2];\n        int max2 = (i2==0) ? INT_MIN : brr[i2-1];\n        \n        if((max1<=min2) && (max2<=min1) ){\n            if((n+m)%2==0){\n                return ((double) (max(max1,max2) + min(min1, min2)) / 2) ;\n            }else{\n                return ((double) max(max1, max2));\n            }\n        }\n        else if(max1>min2){\n            end1 = i1-1;\n        }else{\n            begin1 = i1+1;\n        }\n    }\n}\n"
  },
  {
    "path": "Leetcode/Middle of the Linked List Leetcode.cpp",
    "content": "// https://leetcode.com/problems/middle-of-the-linked-list/\n\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    \n    int size(ListNode* head){\n        int n=0;\n        while(head != NULL){\n            n++;\n            head = head->next;\n        }\n        return n;\n    }\n    \n    ListNode* middleNode(ListNode* head) {\n        int n  = size(head);\n        \n        n = (n/2) + 1;\n        \n        int i=0;\n        while(head != NULL){\n            i++;\n            if(i==n)\n                return head;\n            head = head->next;\n        }\n        \n        return head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Middle of the Linked List.cpp",
    "content": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* middleNode(ListNode* head) {\n        \n        vector<ListNode*> v = {head};\n        while(v.back()->next!=NULL){\n            v.push_back(v.back()->next);\n        }\n        return v[(int)v.size()/2];\n        \n        \n        \n//       int count=0;\n//         ListNode* temp = head;\n//         while(temp!=NULL){\n//             count++;\n//             temp = temp->next;\n//         }\n        \n//         count/=2;\n//         int i=0;\n//         ListNode* ans;\n        \n//         while(i<=count){\n//             ans = head;\n//             head = head->next;\n//             i++;\n//         }\n        \n//         return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Move Zeroes.cpp",
    "content": "// https://leetcode.com/problems/move-zeroes/\n\nclass Solution {\npublic:\n    void moveZeroes(vector<int>& nums) {\n        \n        int n = nums.size();\n        int j=0;\n        \n        for(int i=0; i<n; i++){\n            if(nums[i]!=0){\n                nums[j] = nums[i];\n                j++;\n            }\n        }\n        \n        for(; j<n; j++){\n            nums[j] = 0;\n        }\n    }\n};\n"
  },
  {
    "path": "Leetcode/Multiply two matrices.cpp",
    "content": "// Problem link: https://practice.geeksforgeeks.org/problems/multiply-the-matrices-1587115620/1\n\nvector<vector<int> > multiplyMatrix( const vector<vector<int> >& A, const vector<vector<int> >& B)\n    {\n        // code here\n        int n1,m1, n2, m2;\n        n1 = A.size();\n        n2 = B.size();\n        \n        //col\n        m1 = A[0].size();\n        m2 = B[0].size();\n        vector<vector<int>> ans;\n\n        if(m1 == n2){\n            for(int i=0;i<n1;i++){\n                vector<int> temp;\n                \n                for(int j=0; j<m2;j++){\n                    int sum=0;\n                    for(int k=0;k<m1;k++){\n                        sum = sum + (A[i][k] * B[k][j]);\n                    }\n                    temp.push_back(sum);\n                }\n                ans.push_back(temp);\n            }\n        }\n        \n        return ans;\n    }\n"
  },
  {
    "path": "Leetcode/Naive Pattern Search.cpp",
    "content": "GFG : https://practice.geeksforgeeks.org/problems/naive-pattern-search-1587115620/1/\nLeetcode : https://leetcode.com/problems/implement-strstr/\n\n\nbool search(string pat, string txt) \n{ \n\t\n\t// Your code here\n\tint m = txt.size();\n\tint n = pat.size();\n\t\n\tfor(int i=0; i<=(m-n) ;i++){\n\t    \n\t    bool isBool = true;\n\t    for(int j=0; j<n ;j++){\n\t        if(pat[j]!=txt[j+i]){\n\t            isBool = false;\n\t            break;\n\t        }\n\t    }\n\t    \n\t    if(isBool){\n\t        return true;\n\t    }\n\t    \n\t}\n\t\n\treturn false;\n}\n"
  },
  {
    "path": "Leetcode/Next Greater Element.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/next-larger-element-1587115620/1\n\n\n{\n    public:\n    //Function to find the next greater element for each element of the array.\n    vector<long long> nextLargerElement(vector<long long> arr, int n){\n        // Your code here\n        stack<long long> st;\n        vector<long long>ans;\n        \n        ans.push_back(-1);\n        st.push(arr[n-1]);\n        \n        for(long long i= n-2; i>=0; i--){\n            \n            while(!st.empty() && st.top() <= arr[i])\n                st.pop();\n                \n            long long next = (st.empty()) ? -1 : st.top();\n            ans.push_back(next);\n            st.push(arr[i]);\n        }\n        \n        reverse(ans.begin(), ans.end());\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Non Repeating Character.cpp",
    "content": "// Complete this function\nchar nonrepeatingCharacter(string s)\n{\n   int chars = 256;\n   int n = s.size();\n   \n   int arr[chars];\n   fill(arr, arr+chars, 0);\n   \n   for(int i=0;i<n;i++){\n       arr[s[i]]++;\n   }\n   \n   // 1 1 2 1\n   \n   for(int i=0;i<n;i++){\n       if(arr[s[i]] == 1)\n            return (char)s[i];\n   }\n   \n   return '$';\n   \n}\n"
  },
  {
    "path": "Leetcode/Peak element.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/peak-element/1\n\nint peakElement(int arr[], int n)\n{\n   // Your code here\n   int low = 0;\n   int high = n-1;\n   \n   while(low<=high){\n       int mid = (low+high)/2;\n       \n       if(\n          (mid==0 || arr[mid]>=arr[mid-1]) &&\n          (mid == n-1 || arr[mid]>=arr[mid+1])\n         ){\n             return mid;\n         }\n        else if(arr[mid]<=arr[mid+1]){\n            low = mid+1;\n        }else{\n            high = mid-1;\n        }\n   }\n   \n   return -1;\n}\n"
  },
  {
    "path": "Leetcode/Rearrange Array Alternately Geeksforgeeks.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/-rearrange-array-alternately/0\n\n#include <iostream>\nusing namespace std;\n\nvoid rearrange(long long int arr[], int n){\n    int max_index = n-1;\n    int min_index = 0;\n    int max = arr[n-1]+1;\n    \n    for(int i=0;i<n;i++){\n        if(i%2==0){\n            arr[i] = ( arr[max_index]%max ) * max + arr[i];\n            max_index--;\n        }else{\n            arr[i] = ( arr[min_index]%max ) * max + arr[i];\n            min_index++;\n        }\n    }\n    \n    for(int i=0;i<n;i++){\n        arr[i]/=max; // arr[i] = arr[i]/max;\n    }\n}\n\nint main() \n{\n    int t;\n    \n    //testcases\n    cin >> t;\n    \n    while(t--){\n        \n        //size of array\n        int n;\n        cin >> n;\n        \n        long long int arr[n];\n        \n        //adding elements to the array\n        for(int i = 0;i<n;i++){\n            cin >> arr[i];\n        }\n        \n        //calling rearrange() function\n        rearrange(arr, n);\n        \n        //printing the elements\n        for (int i = 0; i < n; i++) \n\t\t    cout << arr[i] << \" \";\n\t\t\n\t\tcout << endl;\n    }\n\treturn 0; \n}\n"
  },
  {
    "path": "Leetcode/Recursion/0-1 Knapsack Problem Top down.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1\n\nclass Solution\n{\n    public:\n    //Function to return max value that can be put in knapsack of capacity W.\n    int knapSack(int W, int wt[], int val[], int n) \n    {\n       // Your code here\n       vector<vector<int>>dp(n+1, vector<int>(W+1, -1));\n       for(int i=0; i<=n; i++){\n           dp[i][0] = 0;\n       }\n       for(int i=0; i<=W; i++){\n           dp[0][i] = 0;\n       }\n       \n       for(int i=1; i<=n; i++){\n           for(int j=1; j<=W; j++){\n               if(wt[i-1] <= j){\n                   dp[i][j] = max( val[i-1] + dp[i-1][j-wt[i-1]], \n                                   dp[i-1][j]    );\n               }else{\n                   dp[i][j] = dp[i-1][j];\n               }\n           }\n       }\n       \n       return dp[n][W];\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Best Time to Buy and Sell Stock.cpp",
    "content": "// https://leetcode.com/problems/best-time-to-buy-and-sell-stock/\n\nclass Solution {\npublic:\n    int maxProfit(vector<int>& prices) {\n        int i=1, profit = 0, min_price = prices[0], n = prices.size();\n        while(i<n){\n            if(prices[i] < min_price){\n                min_price = prices[i];\n            }else{\n                profit = max(profit, prices[i]-min_price);\n            }\n            i++;\n        }\n        return profit;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Climbing Stairs.cpp",
    "content": "// https://leetcode.com/problems/climbing-stairs/\n\nvector<int>dp(46, -1);\nclass Solution {\npublic:\n    int climbStairs(int n) {\n        if(dp[n] != -1) return dp[n];\n        if(n<=2){\n            return dp[n] = n;\n        }\n        return dp[n] = climbStairs(n-1) + climbStairs(n-2);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Decode Ways.cpp",
    "content": "// https://leetcode.com/problems/decode-ways/\n\nvector<int>dp(101, -1);\nclass Solution {\npublic:\n    int n = 0;\n    int numDecodingsHelper(string s, int pos){\n        if(pos == n) return 1;\n        if(s[pos] == '0') return 0;\n        \n        if(dp[pos] != -1) return dp[pos];\n\n        int count = numDecodingsHelper(s , pos+1);\n        if(pos < n-1 && s.substr(pos, 2) < \"27\"){\n            count += numDecodingsHelper(s, pos+2);\n        }\n        return dp[pos] = count;\n    }\n    int numDecodings(string s) {\n        n = s.size();\n        fill(dp.begin(), dp.end(), -1);\n        return numDecodingsHelper(s, 0);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Delete middle element of a stack.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/delete-middle-element-of-a-stack/1\n\nclass Solution\n{\n    public:\n    //Function to delete middle element of a stack.\n    \n    void deleteMidHelper(stack<int>&st, int count, int &pos){\n        if(st.empty()) return;\n        if(count == pos) {st.pop(); return;}\n        \n        int top = st.top(); st.pop();\n        deleteMidHelper(st, count+1, pos);\n        \n        st.push(top);\n    }\n    \n    void deleteMid(stack<int>&s, int sizeOfStack)\n    {\n        // code here.. \n        int pos = ceil((sizeOfStack+1)/2.0);\n        deleteMidHelper(s, 1, pos);\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Divisor Game.cpp",
    "content": "// https://leetcode.com/problems/divisor-game/\n\nclass Solution {\npublic:\n    bool divisorGame(int n) {\n        // if(n<=1) return false;\n        // for(int x=1; x<n; x++){\n        //     if(n%x==0){\n        //         return !divisorGame(n-x);\n        //     }\n        // }\n        // return false;\n\n        if(n%2==0)return true;\n        return false;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Factorial.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/factorial5739/1\n\nclass Solution{\npublic:\n    long long int factorial(int N){\n        //code here\n        if(N<=1) return 1;\n        return N * factorial(N-1);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Fibonacci Number.cpp",
    "content": "// https://leetcode.com/problems/fibonacci-number/\n\nclass Solution {\npublic:\n    int fib(int n) {\n        if(n<=1) return n;\n        return fib(n-1)+fib(n-2);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/House Robber.cpp",
    "content": "// https://leetcode.com/problems/house-robber/\n\nvector<int>dp(101, -1);\nclass Solution {\npublic:\n    int fun(vector<int>& nums, int n){\n        if(n<=0) return 0;\n        if(dp[n] != -1) return dp[n];\n        return dp[n] = max(\n            fun(nums, n-1),\n            nums[n-1] + fun(nums, n-2)\n        );\n    }\n    int rob(vector<int>& nums) {\n        int n = nums.size();\n        fill(dp.begin(), dp.end(), -1);\n        return fun(nums, n);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Largest Element in Array.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/largest-element-in-array4009/1\n\nclass Solution\n{\npublic:\n    int largest(vector<int> &arr, int n)\n    {\n        if(n==1) return arr[0];\n        return max( largest(arr, n-1), arr[n-1] );\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Min Cost Climbing Stairs.cpp",
    "content": "// https://leetcode.com/problems/min-cost-climbing-stairs/\n\nvector<int>dp(1001, -1);\nclass Solution {\npublic:\n\n    int minCost(vector<int>& cost, int n){\n        if(dp[n] != -1) return dp[n];\n        if(n<=1) return dp[n] = 0;\n        if(n==2) return dp[n] =  min(cost[0], cost[1]);\n        return dp[n] =  min( minCost(cost, n-1) + cost[n-1],\n                    minCost(cost, n-2) + cost[n-2] );\n    }\n    int minCostClimbingStairs(vector<int>& cost) {\n        int n = cost.size();\n        fill(dp.begin(), dp.end(), -1);\n        return minCost(cost, n);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Nth Fibonacci Number.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/nth-fibonacci-number1335/1\n\nvector<long long int>dp(1001, -1);\nclass Solution {\n  public:\n    int mod = 1000000007;\n    long long int nthFibonacci(long long int n){\n        if(dp[n] != -1) return dp[n];\n        // code here\n        if(n<=1){\n            return dp[n] = n;\n        };\n        return dp[n] = (nthFibonacci(n-1)%mod + nthFibonacci(n-2)%mod)%mod;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Partition Equal Subset Sum.cpp",
    "content": "// https://leetcode.com/problems/partition-equal-subset-sum/\n\n/****************************** RECURSION *************************************************/\n/****************************** TIME LIMIT EXCEEDED *************************************************/\n\nclass Solution {\npublic:\n\n    bool subsetSum(vector<int>& nums, int n, int sum){\n        if(n==0) return false;\n        if(sum==0) return true;\n        if(nums[n-1] <= sum){\n            return subsetSum(nums, n-1, sum-nums[n-1]) || subsetSum(nums, n-1, sum);\n        }else{\n            return subsetSum(nums, n-1, sum);\n        }\n    }\n    bool canPartition(vector<int>& nums) {\n        int n = nums.size();\n        int sum = 0;\n        for(auto x: nums){\n            sum += x;\n        }\n        if(sum%2 != 0) return false;\n        \n        sum = sum/2;\n        return subsetSum(nums, n, sum);\n    }\n};\n\n\n\n\n/****************************** MEMOIZATION *************************************************/\nclass Solution {\npublic:\n\n    bool subsetSum(vector<int>& nums, int n, int sum, vector<vector<int>>&dp){\n        if(dp[n][sum] != -1) return dp[n][sum];\n        if(nums[n-1] <= sum){\n            return dp[n][sum] = subsetSum(nums, n-1, sum-nums[n-1], dp) || subsetSum(nums, n-1, sum, dp);\n        }else{\n            return dp[n][sum] = subsetSum(nums, n-1, sum, dp);\n        }\n    }\n    bool canPartition(vector<int>& nums) {\n        int n = nums.size();\n        int sum = 0;\n        for(auto x: nums){\n            sum += x;\n        }\n        if(sum%2 != 0) return false;\n        \n        sum = sum/2;\n        vector<vector<int>>dp(n+1, vector<int>(sum+1, -1));\n        for(int i=0; i<=sum; i++){\n            dp[0][i] = false;\n        }\n        for(int i=0; i<=n; i++){\n            dp[i][0] = true;\n        }\n        return subsetSum(nums, n, sum, dp);\n    }\n};\n\n\n\n\n/****************************** TOP DOWN *************************************************/\n\nclass Solution {\npublic:\n    bool canPartition(vector<int>& nums) {\n        int sum = 0, n = nums.size();\n        for(auto x: nums) sum += x;\n        if(sum % 2 != 0) return false; \n        sum /= 2;\n        vector<vector<bool>>t(n+1, vector<bool>(sum+1, false));\n        for(int i=0; i<n+1; i++){t[i][0] = true;}\n        for(int i=1; i<n+1; i++){\n            for(int j=1; j<sum+1; j++){\n                if(nums[i-1]<=j){\n                    t[i][j] = ( t[i-1][j-nums[i-1]] || t[i-1][j] );\n                }else{\n                    t[i][j] = t[i-1][j];\n                }\n            }\n        }\n        return t[n][sum];\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Perfect Squares.cpp",
    "content": "// https://leetcode.com/problems/perfect-squares/\n\nvector<int>dp(10001, -1);\nclass Solution {\npublic:\n    int solve(int n){\n        if(n<=0) return 0;\n        int ans = INT_MAX;\n        if(dp[n] != -1) return dp[n];\n\n        for(int i=1; i*i<=n; i++){\n            int sqnum = i*i;\n            int count = 1+ solve(n-sqnum);\n            ans = min(ans, count);\n        }\n        return dp[n] = ans;\n    }\n    int numSquares(int n) {\n        return solve(n);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Perfect Sum Problem.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/perfect-sum-problem5633/1\n\n\n/****************************** RECURSION *************************************************/\n/****************************** TIME LIMIT EXCEEDED *************************************************/\n\nclass Solution{\n\n\tpublic:\n\tint mod = 1e9+7;  // 1000000007\n\tint countSubset(int arr[], int n, int sum){\n\t    if(n==0 and sum > 0) return 0;\n\t    else if(n==1){\n\t        if(sum==0){\n\t            if(arr[0] == 0) return 2;\n\t            else return 1;\n\t        }else{\n\t            if(arr[0] == sum) return 1;\n\t            else return 0;\n\t        }\n\t    }\n\t    else if(n==0 and sum==0) return 1;\n\t    \n\t    if(arr[n-1] <= sum){\n\t        return countSubset(arr,n-1, sum-arr[n-1]) + countSubset(arr, n-1, sum);\n\t    }else\n\t        return countSubset(arr, n-1, sum);\n\t}\n\tint perfectSum(int arr[], int n, int sum)\n\t{\n        // Your code goes here\n        return countSubset(arr, n, sum);\n        \n\t}\n\t  \n};\n\n\n/****************************** MEMOIZATION *************************************************/\n\nclass Solution{\n\n\tpublic:\n\tint mod = 1e9+7;  // 1000000007\n\tint countSubset(int arr[], int n, int sum, vector<vector<int>>&dp){\n\t    if(dp[n][sum] != -1) return dp[n][sum];\n\t    if(n==0 and sum > 0) return 0;\n\t    else if(n==1){\n\t        if(sum==0){\n\t            if(arr[0] == 0) return 2;\n\t            else return 1;\n\t        }else{\n\t            if(arr[0] == sum) return 1;\n\t            else return 0;\n\t        }\n\t    }\n\t    else if(n==0 and sum==0) return 1;\n\t    \n\t    int ans = countSubset(arr, n-1, sum, dp) % mod;\n\t    if(arr[n-1] <= sum){\n\t        ans+=countSubset(arr,n-1, sum-arr[n-1], dp);\n\t        ans %= mod;\n\t    }\n\t    return dp[n][sum] = ans;\n\t}\n\tint perfectSum(int arr[], int n, int sum)\n\t{\n        // Your code goes here\n        vector<vector<int>>dp(n+1, vector<int>(sum+1, -1));\n        return countSubset(arr, n, sum, dp) % mod;\n        \n\t}\n\t  \n};\n"
  },
  {
    "path": "Leetcode/Recursion/Power Of Numbers.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/power-of-numbers-1587115620/1\n\nclass Solution{\n    public:\n    //You need to complete this fucntion\n    \n    long long power(int N,int R)\n    {\n        int MOD = 1e9+7;\n       //Your code here\n       if(N==0) return 0;\n       if(R==0) return 1;\n       if(R%2==0){\n           long long ans = power(N, R/2);\n           return ( ans%MOD * ans%MOD  )%MOD;\n       }else{\n           long long ans = power(N, (R-1)/2);\n           return ( ans%MOD * ans%MOD * N%MOD)%MOD;\n       }\n    }\n\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Print 1 To N Without Loop.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/print-1-to-n-without-using-loops-1587115620/1\n\nclass Solution{\n    public:\n    //Complete this function\n    void printNos(int N)\n    {\n        //Your code here\n        if(N==0) return;\n        printNos(N-1);\n        cout<<N<<\" \";\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Reverse a String.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/reverse-a-string/1\n\nstring reverseWord(string str){\n    \n  //Your code here\n  if(str.size() == 0 || str.size()== 1) return str;\n  return reverseWord(str.substr(1)) + str[0];\n}\n"
  },
  {
    "path": "Leetcode/Recursion/Subset Sum Problem.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/subset-sum-problem-1611555638/1\n\n/****************************** RECURSION *************************************************/\n/****************************** TIME LIMIT EXCEEDED *************************************************/\n\nclass Solution{   \npublic:\n    bool subsetSum(vector<int>arr, int n, int sum){\n        if(n==0) return false;\n        if(sum==0) return true;\n        if(arr[n-1] <= sum){\n            return subsetSum(arr, n-1, sum-arr[n-1]) || subsetSum(arr, n-1, sum);\n        }else{\n            return subsetSum(arr, n-1, sum);\n        }\n    }\n    bool isSubsetSum(vector<int>arr, int sum){\n        // code here\n        int n = arr.size();\n        return subsetSum(arr, n, sum);\n    }\n};\n\n\n\n/****************************** MEMOIZATION *************************************************/\nclass Solution{   \npublic:\n    bool subsetSum(vector<int>arr, int n, int sum, vector<vector<int>>&dp){\n        if(dp[n][sum] != -1) return dp[n][sum];\n        if(arr[n-1] <= sum){\n            return dp[n][sum] = subsetSum(arr, n-1, sum-arr[n-1], dp) || subsetSum(arr, n-1, sum, dp);\n        }else{\n            return dp[n][sum] = subsetSum(arr, n-1, sum, dp);\n        }\n    }\n    bool isSubsetSum(vector<int>arr, int sum){\n        // code here\n        int n = arr.size();\n        vector<vector<int>>dp(n+1, vector<int>(sum+1, -1));\n        for(int i=0; i<=sum; i++){\n            dp[0][i] = false;\n        }\n        for(int i=0; i<=n; i++){\n            dp[i][0] = true;\n        }\n        return subsetSum(arr, n, sum, dp);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Sum of Array.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/sum-of-array2326/1\n\nclass Solution{\npublic:\n\t// function to return sum of elements\n\t// in an array of size n\n\tint sum(int arr[], int n) {\n\t    // code here\n\t    if(n == 0) return 0;\n\t    return arr[n-1] + sum(arr, n-1);\n\t}\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Target Sum.cpp",
    "content": "// https://leetcode.com/problems/target-sum/\n\nclass Solution {\npublic:\n\n\t\tint countSubset(vector<int>& nums, int n, int sum, vector<vector<int>>&dp){\n\t    if(dp[n][sum] != -1) return dp[n][sum];\n\t    if(n==0 and sum > 0) return 0;\n\t    else if(n==1){\n\t        if(sum==0){\n\t            if(nums[0] == 0) return 2;\n\t            else return 1;\n\t        }else{\n\t            if(nums[0] == sum) return 1;\n\t            else return 0;\n\t        }\n\t    }\n\t    else if(n==0 and sum==0) return 1;\n\t    \n\t    int ans = countSubset(nums, n-1, sum, dp);\n\t    if(nums[n-1] <= sum){\n\t        ans+=countSubset(nums,n-1, sum-nums[n-1], dp);\n\t    }\n\t    return dp[n][sum] = ans;\n\t}\n    int findTargetSumWays(vector<int>& nums, int target) {\n        int n = nums.size();\n\t\t\t\tint sum = 0;\n\t\t\t\tfor(auto x: nums) {sum += x;}\n\t\t\t\tif(sum < abs(target) || (target + sum) % 2 !=0 ) return 0;\n\t\t\t\t\n\t\t\t\tsum = (sum+target)/2;\n\t\t\t\tvector<vector<int>>dp(n+1, vector<int>(sum+1, -1));\n        return countSubset(nums, n, sum, dp);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Recursion/Tower Of Hanoi.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/tower-of-hanoi-1587115621/1\n\nclass Solution{\n    public:\n    // You need to complete this function\n\n    // avoid space at the starting of the string in \"move disk.....\"\n    long long count = 0;\n    void TOHHelper(int N, int from, int to, int aux){\n        if(N>0){\n            TOHHelper(N-1, from, aux, to);\n            cout << \"move disk \" << N << \" from rod \" << from << \" to rod \" << to << endl;\n            count++;\n            TOHHelper(N-1, aux, to, from);\n        }\n    } \n    long long toh(int N, int from, int to, int aux) {\n        // Your code here\n        TOHHelper(N, from, to , aux);\n        return count;\n    }\n\n};\n"
  },
  {
    "path": "Leetcode/Reverse Linked List.cpp",
    "content": "// https://leetcode.com/problems/reverse-linked-list/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* reverseList(ListNode* head) {\n        ListNode* new_head = NULL;\n         \n        while( head != NULL){\n             ListNode* temp = head;\n             head = head->next;\n             temp->next = new_head;\n             new_head = temp;\n        }\n        \n        return new_head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Rotate Array Leetcode.cpp",
    "content": "class Solution {\npublic:\n    \n    void reverse(vector<int> &num, int low, int high){\n        while(low < high){\n            swap(num[low], num[high]);\n            low++;\n            high--;\n        }\n    }\n    void rotate(vector<int>& nums, int k) {\n        \n        int n = (int)nums.size();\n        k = k%n;\n        reverse(nums, 0, n-k-1);\n        reverse(nums, n-k, n-1);\n        reverse(nums, 0, n-1);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Rotate List.cpp",
    "content": "// https://leetcode.com/problems/rotate-list/\n\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    \n    int size(ListNode* head){\n        int n = 0;\n        while(head != NULL){\n            n++;\n            head = head->next;\n        }\n        return n;\n    }\n    \n    ListNode* rotateRight(ListNode* head, int k) {\n        if(head == NULL)\n            return head;\n        \n        int n = size(head);\n        int loop = k % n;\n        loop = n - loop;\n        \n        if( n == 1 || loop == n)\n            return head;\n        \n        int j=0;\n        ListNode* temp = head;\n        ListNode* firstAddress = head;\n        \n        while(temp != NULL){\n            j++;\n            if(j == loop){\n                firstAddress = temp->next;\n                temp->next = NULL;\n                break;\n            }\n            temp = temp->next;\n        }\n        \n        temp = firstAddress;\n        while(temp->next != NULL){\n            temp = temp->next;\n        }\n        \n        temp->next = head;\n        return firstAddress;\n        \n        \n    }\n};\n\n"
  },
  {
    "path": "Leetcode/Search in a row-column sorted Matrix.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/search-in-a-matrix-1587115621/1\n\n\n\nbool search(vector<vector<int> > matrix, int n, int m, int x) \n{\n    // code here\n    int row=0;\n    for(int i=0;i<n;i++){\n        if(matrix[i][0] == x)\n            return true;\n        else if(matrix[i][0] > x)\n        {\n            row = i-1;  \n            break;\n        }else{\n            row = i;\n        }\n    }\n    \n    if(row>=0){\n        for(int i=0;i<m;i++){\n            if(matrix[row][i] == x)\n                return true;\n        }\n    }\n    \n    return false;\n    \n}\n"
  },
  {
    "path": "Leetcode/Single Number Leetcode solution.cpp",
    "content": "//https://leetcode.com/problems/single-number/\n\n\n\nclass Solution {\npublic:\n    int singleNumber(vector<int>& nums) {\n        int n = (int)nums.size();\n        int a=0;\n        for(int i=0;i<n;i++){\n            //a= a^nums[i];\n            a ^= nums[i];\n        }\n        return a;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Sort Array By Parity.cpp",
    "content": "class Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& A) {\n       vector<int> odd;\n       vector<int> even;\n        \n        int n = (int)A.size();\n        for(int i=0;i<n;i++){\n            if(A[i]%2==0){even.push_back(A[i]);}\n            else{odd.push_back(A[i]);}\n        }\n        \n        even.insert(even.end(), odd.begin(), odd.end() );\n        return even;\n        \n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/Sort Colors.cpp",
    "content": "// https://leetcode.com/problems/sort-colors/\n\n// or\n\n// https://practice.geeksforgeeks.org/problems/sort-an-array-of-0s-1s-and-2s4231/1\n\n\nclass Solution {\npublic:\n    void sortColors(vector<int>& nums) {\n        \n        // Method 1:\n        //sort(nums.begin(), nums.end());\n        \n        \n        // Method 2:\n        \n        /*\n        int n = (int)nums.size();\n        \n        int f=0, s=0,t=0;\n        for(int i=0;i<n;i++){\n            if(nums[i]==0)\n                f++;\n            else if(nums[i]==1)\n                s++;\n            else\n                t++;\n        }\n        \n        for(int i=0;i<f;i++){\n            nums[i]=0;\n        }\n        for(int i=f;i<f+s;i++){\n            nums[i]=1;\n        }\n        for(int i=f+s;i<f+s+t;i++){\n            nums[i]=2;\n        }\n        \n        */\n        \n        \n        // Method 3:\n        \n        int l=0;\n        int m=0;\n        int h=n-1;\n        \n        while(m<=h){\n            int x = nums[m];\n            if(x==0){\n                swap(nums[l], nums[m]);\n                l++;\n                m++;\n            }\n            else if(x==1){\n                m++;\n            }\n            else{\n                swap(nums[h], nums[m]);\n                h--;\n            }\n        }\n        \n    }\n};\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "Leetcode/Spirally traversing a matrix.cpp",
    "content": "Spirally traversing a matrix: https://practice.geeksforgeeks.org/problems/spirally-traversing-a-matrix-1587115621/1\n\nclass Solution\n{   \npublic:     \n    vector<int> spirallyTraverse(vector<vector<int> > matrix, int r, int c) \n    {\n        // code here\n        int top = 0;\n        int bottom = r-1;\n        int left = 0;\n        int right = c-1;\n        \n        vector<int> ans;\n        \n        while(top<=bottom && left<=right){\n            \n            for(int i=left; i<=right ; i++)\n                ans.push_back(matrix[top][i]);\n            top++;\n            \n            for(int i=top;i<=bottom;i++)\n                ans.push_back(matrix[i][right]);\n            right--;\n            \n            if(top<=bottom){\n                for(int i=right;i>=left;i--)\n                    ans.push_back(matrix[bottom][i]);\n                bottom--;\n            }\n            \n            if(left<=right){\n                for(int i=bottom;i>=top;i--)\n                    ans.push_back(matrix[i][left]);\n                left++;\n            }\n        }\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Square root.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/square-root/1\n\n\n\n#include<bits/stdc++.h>\nusing namespace std;\n\nlong long int floorSqrt(long long int x);\n  \n  \n// Function to find square root\n// x: element to find square root\nlong long int floorSqrt(long long int x) \n{\n    // Your code goes here\n    int low = 1;\n    int high = x;\n    int ans = -1;\n    \n    while(low<=high){\n        long long int mid = (low+high)/2;\n        \n        long long int sqr = mid*mid;\n        \n        if(sqr == x)\n            return mid;\n        else if(sqr < x){\n            ans = mid;\n            low = mid+1;\n        }else{\n            high = mid-1;\n        }\n    }\n    \n    return ans;\n    \n}\n\nint main()\n{\n\tint t;\n\tcin>>t;\n\twhile(t--)\n\t{\n\t\tlong long n;\n\t\tcin>>n;\n\t\tcout << floorSqrt(n) << endl;\n\t}\n    return 0;   \n}\n"
  },
  {
    "path": "Leetcode/Subarray sum equals K.cpp",
    "content": "class Solution {\npublic:\n    int subarraySum(vector<int>& nums, int k) {\n        int n  =(int)nums.size();\n        \n        int count=0;\n        \n        unordered_map<int, int> prevSum;\n        int sum=0;\n        \n        for(int i=0;i<n;i++){\n            sum+=nums[i];\n            \n            if(sum==k)\n                count++;\n            \n            if(prevSum.find(sum-k) != prevSum.end())\n                count+=prevSum[sum-k];\n            \n            prevSum[sum]++;\n        }\n        \n        return count;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Trapping Rain Water.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// function to find the trapped water in between buildings\n// arr: input array\n// n: size of array\nint trappingWater(int arr[], int n){\n    \n    int lmax[n]; lmax[0] = arr[0];\n    for(int i=1;i<n;i++){\n        int temp = max(arr[i], lmax[i-1]);\n        lmax[i] = temp;\n    }\n    \n    int rmax[n]; rmax[n-1] = arr[n-1];\n    for(int i=n-2; i>=0 ;i--){\n        int temp = max(arr[i], rmax[i+1]);\n        rmax[i] = temp;\n    }\n    \n    int water=0;\n    for(int i=1;i<n-1;i++){\n        water+= min(lmax[i], rmax[i]) - arr[i];\n    }\n    \n    return water;\n}\n\n\n// { Driver Code Starts.\n\nint main(){\n    \n    int t;\n    //testcases\n    cin >> t;\n    \n    while(t--){\n        int n;\n        \n        //size of array\n        cin >> n;\n        \n        int a[n];\n        \n        //adding elements to the array\n        for(int i =0;i<n;i++){\n            cin >> a[i];            \n        }\n        \n        //calling trappingWater() function\n        cout << trappingWater(a, n) << endl;\n        \n    }\n    \n    return 0;\n}  // } Driver Code Ends\n"
  },
  {
    "path": "Leetcode/Tree/Balanced Binary Tree.cpp",
    "content": "// https://leetcode.com/problems/balanced-binary-tree/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    int height(TreeNode* root){\n        if(root == NULL)\n            return 0;\n        else \n            return max( height(root->left), height(root->right) ) +1;\n    }\n    \n    void inorderUtil(TreeNode* root, bool & ans){\n        if(root!=NULL){\n            inorderUtil(root->left, ans);\n            \n            int lh = height(root->left);\n            int rh = height(root->right);\n            \n            if(abs(lh-rh) >1)\n                ans = ans && false;\n            \n            inorderUtil(root->right, ans);\n        }\n    }\n    \n    bool isBalanced(TreeNode* root) {\n        bool ans = true;\n        inorderUtil(root, ans);\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Binary Tree Inorder Traversal.cpp",
    "content": "// https://leetcode.com/problems/binary-tree-inorder-traversal/\n\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    void preorder(TreeNode* root, vector<int>  &ans){\n        if(root!=NULL){\n            ans.push_back(root->val);\n            preorder(root->left, ans);\n            preorder(root->right, ans);\n        }\n    }\n    \n    vector<int> inorderTraversal(TreeNode* root) {\n        vector<int> ans;\n        preorder(root, ans);\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Binary Tree Right Side View.cpp",
    "content": "// https://leetcode.com/problems/binary-tree-right-side-view/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    vector<int> rightSideView(TreeNode* root) {\n        vector<int> ans;\n        queue<TreeNode*>q;\n        q.push(root);\n        \n        if(root == NULL)\n            return ans;\n        while(1){\n            int size = q.size();\n            if(size==0)\n                return ans;\n            int data = 0;\n            while(size>0){\n                TreeNode* temp = q.front();\n                q.pop();\n                \n                data = (temp->val);\n                if(temp->left!=NULL)\n                    q.push(temp->left);\n                if(temp->right!=NULL)\n                    q.push(temp->right);\n                size--;\n                   \n            }\n            ans.push_back(data);\n        }\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Binary Tree Zigzag Level Order Traversal.cpp",
    "content": "// https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/\n\nvector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n        vector<vector<int>> ans;\n        queue<TreeNode*> q;\n        q.push(root);\n        \n        int count = 0;\n        if(root == NULL)\n            return ans;\n        \n        while(1){\n            int size = q.size();\n            if(size == 0)\n                return ans;\n            count++;\n            vector<int>data;\n            \n            while(size>0){\n                TreeNode* temp = q.front();\n                q.pop();\n\n                data.push_back(temp->val);\n                if(temp->left != NULL)\n                    q.push(temp->left);\n                if(temp->right != NULL)\n                    q.push(temp->right);\n                size--;\n            }\n            if(count%2==0)\n                reverse(data.begin(), data.end());\n            ans.push_back(data);\n            \n        }\n        return ans;\n    \n    }\n"
  },
  {
    "path": "Leetcode/Tree/Children Sum Parent.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/children-sum-parent/1/\n\nint isSumProperty(Node *root)\n{\n  if( root == NULL  || (root->left == NULL && root->right==NULL))\n    return 1;\n  \n  int left_sum = 0, right_sum = 0;\n  if(root->left != NULL)\n    left_sum = root->left->data;\n  if(root->right != NULL)\n    right_sum = root->right->data;\n \n  if( root->data == (left_sum+right_sum) &&\n      isSumProperty(root->left) &&\n      isSumProperty(root->right) ){\n          return 1;\n      }\n  else\n     return 0;\n \n}\n"
  },
  {
    "path": "Leetcode/Tree/Construct Binary Tree from Preorder and Inorder Traversal.cpp",
    "content": "// https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    int preIndex = 0;\n    \n    TreeNode* buildTreeUtil(vector<int>& preorder, vector<int>& inorder, int is, int ie){\n        if(is > ie)\n            return NULL;\n        \n        TreeNode* root = new TreeNode(preorder[preIndex]);\n        preIndex++;\n        \n        \n        int inIndex;\n        for(int i=is; i<=ie; i++){\n            if(inorder[i] == root->val){\n                inIndex = i;\n                break;\n            }\n        }\n        \n        root->left = buildTreeUtil(preorder, inorder, is, inIndex-1);\n        root->right = buildTreeUtil(preorder, inorder, inIndex+1, ie);\n        \n        return root;\n        \n    }\n    \n    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {\n        TreeNode* ans = buildTreeUtil(preorder, inorder, 0, inorder.size()-1);\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Diameter of Binary Tree.cpp",
    "content": "// https://leetcode.com/problems/diameter-of-binary-tree/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    int res = 0;\n    \n    int height(TreeNode* root){\n        if(root == NULL)\n            return 0;\n        \n        int lh = height( root-> left);\n        int rh = height( root-> right);\n        \n        res = max(res, 1+lh+rh);\n        \n        return 1+ max(lh, rh);\n        \n    }\n    \n    int diameterOfBinaryTree(TreeNode* root) {\n        int data = height(root);\n        return res-1;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Invert Binary Tree.cpp",
    "content": "// https://leetcode.com/problems/invert-binary-tree/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    TreeNode* invertTree(TreeNode* root) {\n        stack <TreeNode*> st;\n        st.push(root);\n        \n        while(!st.empty()){\n            TreeNode* node = st.top();\n            st.pop();\n            \n            if(node != NULL){\n                st.push(node->left);\n                st.push(node->right);\n                swap(node->left, node->right);\n            }\n        }\n        \n        return root;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Level Order Traversal.cpp",
    "content": "// https://leetcode.com/problems/binary-tree-level-order-traversal/\n\nvector<vector<int>> levelOrder(TreeNode* root) {\n        vector<vector<int>> ans;\n        queue<TreeNode*>q;\n        q.push(root);\n        \n        if(root == NULL)\n            return ans;\n        while(1){\n            int size = q.size();\n            if(size==0)\n                return ans;\n            vector<int>data;\n            while(size>0){\n                TreeNode* temp = q.front();\n                q.pop();\n                \n                data.push_back(temp->val);\n                if(temp->left!=NULL)\n                    q.push(temp->left);\n                if(temp->right!=NULL)\n                    q.push(temp->right);\n                size--;\n                   \n            }\n            ans.push_back(data);\n        }\n        return ans;\n    }\n"
  },
  {
    "path": "Leetcode/Tree/Lowest Common Ancestor of a Binary Tree.cpp",
    "content": "// https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/\n\n\n//                  METHOD - 01\n\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    \n    bool findPath(TreeNode* root,  vector<TreeNode*> &path, TreeNode* n){\n        if(root == NULL)\n            return false;\n        path.push_back(root);\n        if(root == n) return true;\n        \n        if( findPath(root->left, path, n) || findPath(root->right, path, n) )\n            return true;\n        \n        path.pop_back();\n        return false;\n    }\n    \n\n    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n      \n        vector<TreeNode*> path1, path2;\n        if( !findPath(root, path1, p) || !findPath(root, path2, q)  )\n            return NULL;\n        TreeNode* ans = NULL;\n        for(int i=0; i<path1.size() && i<path2.size(); i++){\n            if(path1[i] == path2[i])\n                ans = path2[i];\n        }\n        return ans;\n        \n    }\n\n};\n\n\n\n\n\n\n//                  METHOD - 02\n\n\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    \n\n    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n      \n        if(root == NULL)\n            return NULL;\n        if(root == p || root == q)\n            return root;\n        \n        TreeNode* lca1 = lowestCommonAncestor(root->left, p, q);\n        TreeNode* lca2 = lowestCommonAncestor(root->right, p, q);\n        \n        if(lca1 != NULL && lca2 != NULL)\n            return root;\n        if(lca1 != NULL)\n            return lca1;\n        else\n            return lca2;\n        \n    }\n\n};\n\n\n\n"
  },
  {
    "path": "Leetcode/Tree/Maximum Depth of Binary Tree.cpp",
    "content": "// https://leetcode.com/problems/maximum-depth-of-binary-tree/\n\nclass Solution {\npublic:\n    int maxDepth(TreeNode* root) {\n        if(root == NULL)\n            return 0;\n        else\n            return max( maxDepth(root->left), maxDepth(root->right) ) + 1;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Populating Next Right Pointers in Each Node.cpp",
    "content": "// https://leetcode.com/problems/populating-next-right-pointers-in-each-node/\n\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* left;\n    Node* right;\n    Node* next;\n\n    Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n    Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n    Node(int _val, Node* _left, Node* _right, Node* _next)\n        : val(_val), left(_left), right(_right), next(_next) {}\n};\n*/\n\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        if(root == NULL)\n            return root;\n        \n        queue<Node*>q;\n        q.push(root);\n        \n        while(!q.empty()){\n            int size = q.size();\n            if( size == 0)\n                return root;\n            \n            while(size>0){\n                Node* temp;\n                \n                if(size>1){\n                    temp = q.front();\n                    q.pop();\n                    \n                    Node* nextAdd = q.front();\n                    temp->next = nextAdd;\n                    \n                }\n                else{\n                    temp = q.front();\n                    q.pop();\n                }\n                \n                if(temp->left != NULL)\n                    q.push(temp->left);\n                if(temp->right != NULL)\n                    q.push(temp->right);\n                \n                size--;\n                \n            }\n        }\n        \n        return root;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Subtree of Another Tree.cpp",
    "content": "// https://leetcode.com/problems/subtree-of-another-tree/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    bool ans = false;\n    \n    \n    bool match(TreeNode* root, TreeNode* subRoot){\n        \n        if(root!=NULL && subRoot!=NULL){\n            bool a = match(root->left, subRoot->left);\n            bool b = match(root->right, subRoot->right);\n            \n            if( (root->val == subRoot->val) && a && b ){\n                return true;\n            }else\n                return false;\n        }\n        else if(root==NULL && subRoot==NULL)\n            return true;\n        else\n            return false;\n    }\n    \n    \n    void inorder(TreeNode* root, TreeNode* subRoot){\n        if(root!=NULL){\n            inorder(root->left, subRoot);\n            \n            bool x = match(root, subRoot);\n            if(x){ans = x;}\n            \n            inorder(root->right, subRoot);\n        }\n    }\n    \n    bool isSubtree(TreeNode* root, TreeNode* subRoot) {\n        inorder(root, subRoot);\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Symmetric Tree.cpp",
    "content": "// https://leetcode.com/problems/symmetric-tree/\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    bool match(TreeNode* root1, TreeNode* root2){\n        if(root1 != NULL && root2 != NULL){\n            bool a = match(root1->left, root2->right);\n            bool b = match(root1->right, root2->left);\n            \n            if((root1->val == root2->val) && a && b)\n                return true;\n            else\n                return false;\n            \n        }\n        else if(root1 == NULL && root2 == NULL){\n            return true;\n        }else\n            return false;\n    }\n    \n    bool isSymmetric(TreeNode* root) {\n        if(root == NULL)\n            return true;\n        \n        return match(root->left, root->right);\n    }\n};\n"
  },
  {
    "path": "Leetcode/Tree/Vertical Width of a Binary Tree .cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/vertical-width-of-a-binary-tree/1\n\n\n\n/*Structure of node of binary tree is as follows\nstruct Node\n{\n    int data;\n    struct Node* left;\n    struct Node* right;\n    \n    Node(int x){\n        data = x;\n        left = right = NULL;\n    }\n};\n*/\n\nunordered_set<int>st;\n\nvoid inorderUtil(Node* root, int hd){\n    if(root != NULL){\n        inorderUtil(root->left, hd-1);\n        st.insert(hd);\n        inorderUtil(root->right, hd+1);\n    }\n}\n\n//Function to find the vertical width of a Binary Tree.\nint verticalWidth(Node* root)\n{\n    // Code here\n    st.clear();\n    inorderUtil(root, 0);\n    return st.size();\n    \n}\n"
  },
  {
    "path": "Leetcode/Tree/same Tree.cpp",
    "content": "// https://leetcode.com/problems/same-tree/\n\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    \n    void inorder(TreeNode* root, vector<int>&v){\n        if(root!=NULL){\n            inorder(root->left, v);\n            v.push_back(root->val);\n            inorder(root->right, v);\n        }else\n            v.push_back(100000);\n    }\n    \n    void preorder(TreeNode* root, vector<int>&v){\n        if(root!=NULL){\n            v.push_back(root->val);\n            preorder(root->left, v);\n            preorder(root->right, v);\n        }else\n            v.push_back(100000);\n    }\n    \n    bool isSameTree(TreeNode* p, TreeNode* q) {\n        \n        vector<int> inp, inq, prep, preq;\n        inorder(p, inp);\n        inorder(q, inq);\n        \n        preorder(p, prep);\n        preorder(q, preq);\n        \n        if(inp == inq  && prep == preq)\n            return true;\n        else\n            return false;\n    }\n};\n\n\n// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n// Recursive Solution\n\nclass Solution {\npublic:\n    bool isSameTree(TreeNode* p, TreeNode* q) {\n        if(p==NULL && q==NULL)\n            return true;\n        if(p==NULL || q==NULL)\n            return false;\n        return ( p->val == q->val  && \n                 isSameTree( p->left, q->left ) && \n                 isSameTree( p->right, q->right )  );\n    }\n};\n"
  },
  {
    "path": "Leetcode/count 1's in binary array.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/count-1s-in-binary-array-1587115620/1\n\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to count number of Ones\n// arr: input array \n// N: size of input array\nint countOnes(int arr[], int N)\n{\n    \n    // Your code here\n    int low=0;\n    int high=N-1;\n    \n    while(low<=high){\n        int mid = (low+high)/2;\n        \n        if(arr[mid]==0){\n            high = mid-1;\n        }\n        else{\n            if(arr[mid+1]==0 || mid==N-1){\n                return mid+1;\n            }else{\n                low = mid+1;\n            }\n        }\n        \n         \n    }\n    \n    return 0;\n    \n}\n\nint main()\n{\n    int t;\n    cin>>t;\n    \n    while(t--)\n    {\n        int n;\n        cin>>n;\n        int *arr = new int[n]; \n        for(int i = 0; i < n; i++)\n            cin>>arr[i];\n        \n        cout <<countOnes(arr, n)<<endl;\n    }\n    return 0;\n}\n\n\n\n\n/*\n\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to count number of Ones\n// arr: input array \n// N: size of input array\nint countOnes(int arr[], int N)\n{\n    \n    // Your code here\n    int low= 0;\n    int high = N-1;\n    \n    while(low<=high){\n        int mid = (low+high) /2;\n        \n        if(arr[mid]==0){\n            if(arr[mid-1]==1 || mid == 0){\n                return mid;\n            }else{\n                high = mid-1;\n            }\n            \n        }\n        else{\n            \n            if(arr[mid+1]==0 || mid == N-1){\n                return mid+1;\n            }else{\n                low = mid+1;\n            }\n        }\n    }\n    \n    return 0;\n    \n}\n\nint main()\n{\n    int t;\n    cin>>t;\n    \n    while(t--)\n    {\n        int n;\n        cin>>n;\n        int *arr = new int[n]; \n        for(int i = 0; i < n; i++)\n            cin>>arr[i];\n        \n        cout <<countOnes(arr, n)<<endl;\n    }\n    return 0;\n}\n\n\n*/\n"
  },
  {
    "path": "Leetcode/linked-list-cycle.cpp",
    "content": "// https://leetcode.com/problems/linked-list-cycle/\n\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    bool hasCycle(ListNode *head) {\n        if(head == NULL || head->next == NULL){\n            return false;\n        }\n        \n        ListNode *slow = head;\n        ListNode *fast = head->next;\n        \n        while(slow!=fast){\n            if(fast==NULL || fast->next == NULL){\n                return false;\n            }\n            slow = slow->next;\n            fast = fast->next->next;\n        }\n        return true;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Copy List with Random Pointer.cpp",
    "content": "// https://leetcode.com/problems/copy-list-with-random-pointer/\n\n\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* next;\n    Node* random;\n    \n    Node(int _val) {\n        val = _val;\n        next = NULL;\n        random = NULL;\n    }\n};\n*/\n\nclass Solution {\npublic:\n    Node* copyRandomList(Node* head) {\n        if( head == NULL) return head;\n        Node* newhead = new Node(0);\n        Node* new_curr = newhead;\n        Node* curr = head;\n        unordered_map<Node*, Node*> umap;\n        \n        while(curr){\n            Node* temp = new Node(curr->val);\n            umap.insert({curr, temp});\n            \n            new_curr->next = temp;\n            new_curr = new_curr->next;\n            curr = curr->next;\n        }\n        curr = head;\n        new_curr = newhead->next;\n        \n        while(curr){\n            Node* random = curr->random;\n            Node* newNode = umap[random];\n            new_curr->random = newNode;\n            \n            new_curr = new_curr->next;\n            curr = curr->next;\n        }\n        \n        return newhead->next;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Delete Node in a Linked List.cpp",
    "content": "// https://leetcode.com/problems/delete-node-in-a-linked-list/\n\nclass Solution {\npublic:\n    void deleteNode(ListNode* node) {\n        ListNode* curr = node->next;\n        node->val = curr->val;\n        node->next = curr->next;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Intersection of Two Linked Lists.cpp",
    "content": "// https://leetcode.com/problems/intersection-of-two-linked-lists/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {\n        ListNode* curr = headA;\n        int a =0, b=0;\n        while(curr){\n            a++;\n            curr = curr->next;\n        }\n        curr =headB;\n        while(curr){\n            b++;\n            curr = curr->next;\n        }\n        int diff = abs(a-b);\n        if(a<b){\n            while(diff--){\n                headB = headB->next;\n            }\n        }else{\n            while(diff--){\n                headA = headA->next;\n            }\n        }\n        \n        while(headA and headB){\n            if(headA == headB){\n                return headA;\n            }\n            headA = headA->next;\n            headB = headB->next;\n        }\n        return NULL;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Linked List Cycle II.cpp",
    "content": "// https://leetcode.com/problems/linked-list-cycle-ii/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode *detectCycle(ListNode *head) {\n        if(head == NULL) return NULL;\n        ListNode* slow = head, *fast = head, *entry = head;\n        while(fast->next != NULL && fast->next->next != NULL){\n            slow = slow->next;\n            fast = fast->next->next;\n            \n            if(slow == fast){\n                while(entry != slow){\n                    slow = slow->next;\n                    entry = entry->next;\n                }\n                return slow;\n            }\n        }\n        return NULL;\n        \n        /*\n        \n        unordered_set<ListNode*> set;\n        ListNode* curr = head;\n        while(curr != NULL){\n            if(set.find(curr) != set.end()){\n                return curr;\n            }else{\n                set.insert(curr);\n                curr = curr->next;\n            }\n        }\n        return NULL;\n        \n        */\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Merge Two Sorted Lists.cpp",
    "content": "// https://leetcode.com/problems/merge-two-sorted-lists/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {\n        ListNode* head;\n        \n        if(list1->val <= list2->val){\n              head = list1;\n             list1 = list1->next;\n        }else{\n             head = list2;\n            list2 = list2->next;\n        }\n        \n        ListNode* curr = head;\n\n        while(list1 != NULL && list2 != NULL){\n            if(list1->val <= list2->val){\n                curr->next = list1;\n                list1 = list1->next;\n            }else{\n                curr->next = list2;\n                list2 = list2->next;\n            }\n            curr = curr->next;\n        }\n        \n        if(list1 != NULL) curr->next = list1;\n        if(list2 != NULL) curr->next = list2;\n            \n        return head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Palindrome Linked List.cpp",
    "content": "// https://leetcode.com/problems/palindrome-linked-list/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    bool isPalindrome(ListNode* head) {\n        ListNode* slow = head, *fast = head;\n        while(fast and fast->next){\n            slow = slow->next;\n            fast = fast->next->next;\n        }\n        if(fast != NULL and fast->next == NULL ){\n            slow = slow->next;\n        }\n        \n        ListNode* prev = NULL;\n        while(slow and slow->next){\n            ListNode* temp = slow->next;\n            slow->next = prev;\n            prev = slow;\n            slow = temp;\n        }\n        if(slow != NULL){slow->next = prev;}\n        fast = head;\n        while(slow and fast){\n            if(slow->val != fast->val)\n                return false;\n            slow = slow->next;\n            fast = fast->next;\n        }\n        return true;\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Remove Duplicates from Sorted List.cpp",
    "content": "// https://leetcode.com/problems/remove-duplicates-from-sorted-list/\n\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        ListNode* curr = head;\n        while(curr != NULL && curr->next != NULL){\n            if(curr->val == curr->next->val){\n                // same \n                ListNode* temp = curr->next;\n                curr->next = temp->next;\n                delete(temp);\n            }else{\n                curr = curr->next;\n            }\n        }\n        return head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Remove Nth Node From End of List.cpp",
    "content": "// https://leetcode.com/problems/remove-nth-node-from-end-of-list/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* removeNthFromEnd(ListNode* head, int n) {\n        ListNode *slow = head, *fast = head;\n        while(n--){\n            fast = fast->next;\n        }\n        if(fast == NULL) return slow->next;\n        \n        while(fast->next != NULL){\n            slow = slow->next;\n            fast = fast->next;\n        }\n        \n        slow->next = slow->next->next;\n        return head;\n        \n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Remove duplicates from an unsorted linked list.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/remove-duplicates-from-an-unsorted-linked-list/0\n\n/*\nThe structure of linked list is the following\n\nstruct Node {\n  int data;\n  struct Node *next;\n  Node(int x) {\n    data = x;\n    next = NULL;\n  }\n};\n*/\n\n\nclass Solution\n{\n    public:\n    //Function to remove duplicates from unsorted linked list.\n    Node * removeDuplicates( Node *head) \n    {\n     // your code goes here\n        unordered_set<int>seen;\n        Node* curr = head;\n        \n        if(curr == NULL)\n            return head;\n        else\n            seen.insert(curr->data);\n            \n        while(curr != NULL && curr->next != NULL){\n            if(seen.find(curr->next->data) != seen.end()){\n                // same \n                curr->next = curr->next->next;\n            }else{\n                // not same\n                seen.insert(curr->next->data);\n                curr = curr->next;\n            }\n        }\n        return head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Reverse Linked List.cpp",
    "content": "// https://leetcode.com/problems/reverse-linked-list/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* reverseList(ListNode* head) {\n        ListNode* prev = NULL, *curr = head;\n        while(curr != NULL){\n            ListNode *temp = curr->next;\n            curr->next = prev;\n            prev = curr;\n            curr = temp;\n        }\n        return prev;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Sort List.cpp",
    "content": "// https://leetcode.com/problems/sort-list/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    \n    ListNode* Mid(ListNode* head){\n        ListNode* slow = head;\n        ListNode* fast = head;\n        \n        while(fast->next != NULL and fast->next->next != NULL){\n            slow = slow->next;\n            fast = fast->next->next;\n        }\n        return slow;\n    }\n    \n    ListNode* mergeSortedList(ListNode *p1, ListNode *p2){\n        if(p1 == NULL or p2 == NULL){\n            return (p1==NULL) ? p2 : p1;\n        }\n        \n        ListNode * ans = new ListNode(0);\n        ListNode* curr = ans;\n        \n        while(p1 != NULL and p2 != NULL){\n            if(p1->val < p2->val){\n                curr->next = p1;\n                p1= p1->next;\n            }else{\n                curr->next = p2;\n                p2 = p2->next;\n            }\n            curr = curr->next;\n        }\n        \n        if(p1 != NULL or p2 != NULL){\n            curr->next = (p1 != NULL) ?  p1 : p2;\n        }\n        return ans->next;\n    }\n    \n    ListNode* sortList(ListNode* head) {\n        if( head == NULL or head->next == NULL) return head;\n        ListNode* mid = Mid(head);\n        ListNode* newhead = mid->next;\n        mid->next = NULL;\n        \n        ListNode* left_half = sortList(head);\n        ListNode* right_half = sortList(newhead);\n        \n        return mergeSortedList(left_half, right_half);\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Swap Nodes in Pairs.cpp",
    "content": "// https://leetcode.com/problems/swap-nodes-in-pairs/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* swapPairs(ListNode* head) {\n        if(head == NULL || head->next == NULL) return head;\n        ListNode *curr = head->next->next;\n        ListNode * prev = head;\n        head = head->next;\n        head->next = prev;\n        \n        while(curr != NULL && curr->next != NULL){\n            prev->next = curr->next;\n            prev = curr;\n            ListNode * temp = curr->next->next;\n            curr->next->next = curr;\n            curr = temp;\n        }\n        \n        prev->next = curr;\n        return head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/linkedlist/Swapping Nodes in a Linked List.cpp",
    "content": "// https://leetcode.com/problems/swapping-nodes-in-a-linked-list/\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* swapNodes(ListNode* head, int k) {\n        ListNode* slow = head,  *fast = head;\n        while(--k){\n            fast = fast->next;\n        }\n        ListNode *first = fast;\n        \n        while(fast->next != NULL){\n            slow = slow->next;\n            fast = fast->next;\n        }\n        \n        swap(first->val, slow->val);\n        return head;\n    }\n};\n"
  },
  {
    "path": "Leetcode/stack/Evaluate Reverse Polish Notation.cpp",
    "content": "// https://leetcode.com/problems/evaluate-reverse-polish-notation/\n\nclass Solution {\npublic:\n    int evalRPN(vector<string>& tokens) {\n        stack<int>st;\n        for(auto x: tokens){\n            if(x == \"+\" || x == \"-\" || x ==\"/\" || x == \"*\"){\n                int op2 = st.top(); st.pop();\n                int op1 = st.top(); st.pop();\n                \n                if(x == \"+\"){\n                    st.push(op1 + op2);\n                }\n                if(x == \"-\"){\n                    st.push(op1 - op2);\n                }\n                if(x == \"*\"){\n                    st.push(op1 * op2);\n                }\n                if(x == \"/\"){\n                    st.push(op1 / op2);\n                }\n            }\n            else{\n                stringstream ss(x);\n                int data;\n                ss >> data;\n                st.push(data);\n            }\n        }\n        \n        return st.top();\n    }\n};\n"
  },
  {
    "path": "Leetcode/stack/Implement Queue using Stacks.cpp",
    "content": "// https://leetcode.com/problems/implement-queue-using-stacks/\n\nclass MyQueue {\n\nprivate:\n    stack<int>input, output;\n    \npublic:\n    MyQueue() {\n        \n    }\n    \n    void push(int x) {\n        input.push(x);\n    }\n    \n    int pop() {\n        int val = peek();\n        output.pop();\n        return val;\n    }\n    \n    int peek() {\n        if( output.empty() ){\n            while( input.empty() != true ){\n                output.push(input.top());\n                input.pop();\n            }\n        }\n        \n        return output.top();\n    }\n    \n    bool empty() {\n        return input.empty() && output.empty();\n    }\n};\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue* obj = new MyQueue();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->peek();\n * bool param_4 = obj->empty();\n */\n"
  },
  {
    "path": "Leetcode/stack/Implement Stack using Queues.cpp",
    "content": "// https://leetcode.com/problems/implement-stack-using-queues/\n\nclass MyStack {\npublic:\n    queue<int>q1,q2;\n    \n    \n    MyStack() {\n        \n    }\n    \n    void push(int x) {\n        while(!q1.empty()){\n            q2.push(q1.front());\n            q1.pop();\n        }\n        q1.push(x);\n        while(!q2.empty()){\n            q1.push(q2.front());\n            q2.pop();\n        }\n        \n    }\n    \n    int pop() {\n        int val = q1.front();\n        q1.pop();\n        return val;\n        \n    }\n    \n    int top() {\n        return q1.front();\n    }\n    \n    bool empty() {\n        return q1.empty();\n    }\n};\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack* obj = new MyStack();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->top();\n * bool param_4 = obj->empty();\n */\n"
  },
  {
    "path": "Leetcode/stack/Largest Rectangle in Histogram.cpp",
    "content": "// https://leetcode.com/problems/largest-rectangle-in-histogram/\n\nclass Solution {\npublic:\n    \n    vector<int> previous_smaller(vector<int>& heights){\n        vector<int> ans;\n        stack<int>st;\n        int n = heights.size();\n        \n        for(int i=0; i<n; i++){\n            while(st.empty() == false && heights[st.top()] >= heights[i] ){\n                st.pop();\n            }\n            int ele = (st.empty()) ? -1 : st.top();\n            ans.push_back(ele);\n            st.push(i);\n        }\n        return ans;\n    }\n\n    vector<int> next_smaller(vector<int>& heights){\n        vector<int> ans;\n        stack<int>st;\n        int n = heights.size();\n        \n        for(int i=n-1; i>=0; i--){\n            while(st.empty() == false && heights[st.top()] >= heights[i] ){\n                st.pop();\n            }\n            int ele = (st.empty()) ? n : st.top();\n            ans.push_back(ele);\n            st.push(i);\n        }\n        reverse(ans.begin(), ans.end());\n        return ans;\n    }\n    \n    int largestRectangleArea(vector<int>& heights) {\n        int res = 0;\n        int n = heights.size();\n        vector<int>ps = previous_smaller(heights);\n        vector<int>ns = next_smaller(heights);\n        \n        for(int i=0; i<n; i++){\n            int curr = ( ns[i] - ps[i] -1 ) * heights[i];\n            res = max(res , curr);\n        }\n        return res;\n    }\n};\n\n\n"
  },
  {
    "path": "Leetcode/stack/Min Stack.cpp",
    "content": "// https://leetcode.com/problems/min-stack/\n\nclass MinStack {\npublic:\n    \n    stack<int>st, s2;\n    MinStack() {\n        \n    }\n    \n    void push(int val) {\n        if( s2.empty() || val <= s2.top() ){\n            s2.push(val);\n        }\n        \n        st.push(val);\n    }\n    \n    void pop() {\n        \n        if(st.top() == s2.top()){\n            s2.pop();\n        }\n        st.pop();\n        \n    }\n    \n    int top() {\n        return st.top();\n    }\n    \n    int getMin() {\n        return s2.top();\n    }\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack* obj = new MinStack();\n * obj->push(val);\n * obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->getMin();\n */\n"
  },
  {
    "path": "Leetcode/stack/Next Greater Element I.cpp",
    "content": "// https://leetcode.com/problems/next-greater-element-i/\n\nclass Solution {\npublic:\n    vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n        unordered_map<int,int>umap;\n        stack<int>st;\n        int n = nums2.size();\n        \n        for(int i=n-1; i>=0; i--){\n            int ele = nums2[i];\n            while(!st.empty() && st.top() <= ele){\n                st.pop();\n            }\n            int res = (st.empty()) ? -1 : st.top();\n            umap.insert({ele, res});\n            st.push(ele);\n        }\n        \n        vector<int> ans;\n        for(auto x: nums1){\n            ans.push_back(umap[x]);\n        }\n        \n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/stack/Online Stock Span.cpp",
    "content": "// https://leetcode.com/problems/online-stock-span/\n\nclass StockSpanner {\npublic:\n    stack<pair<int,int>>st; // price, span\n    StockSpanner() {\n        \n    }\n    \n    int next(int price) {\n        int span = 1;\n        \n        while(!st.empty() && st.top().first <= price){\n            span += st.top().second;\n            st.pop();\n        }\n        \n        st.push({price, span});\n        return span;\n    }\n};\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner* obj = new StockSpanner();\n * int param_1 = obj->next(price);\n */\n"
  },
  {
    "path": "Leetcode/stack/Remove All Adjacent Duplicates In String.cpp",
    "content": "// https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/\n\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        int n = s.size(), i=0;\n        stack<char>st;\n        \n        while(i<n){\n            if(st.empty() || st.top() != s[i])\n                st.push(s[i]);\n            else\n                st.pop();\n            \n            i++;\n        }\n        \n        string ans = \"\";\n        while(!st.empty()){\n            char ele = st.top();\n            st.pop();\n            \n            ans += ele;\n        }\n        \n        reverse(ans.begin(), ans.end());\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/stack/Remove All Adjacent Duplicates in String II.cpp",
    "content": "// https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/\n\nclass Solution {\npublic:\n    string removeDuplicates(string s, int k) {\n        \n        vector<pair<char, int>>st;\n        for(auto c : s){\n            if(st.size() == 0 || st.back().first != c ){\n                st.push_back({c, 1});\n            }\n            else{\n                st.back().second++;\n            }\n            \n            if(st.back().second == k){\n                st.pop_back();\n            }\n        }\n        \n        string res ;\n        for(auto x: st){\n            res.append(x.second, x.first);\n        }\n            \n        return res;\n    }\n};\n"
  },
  {
    "path": "Leetcode/stack/Reverse First K elements of Queue.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/reverse-first-k-elements-of-queue/1/\n\n// { Driver Code Starts\n// Initial Template for C++\n\n#include <bits/stdc++.h>\nusing namespace std;\nqueue<int> modifyQueue(queue<int> q, int k);\nint main() {\n    int t;\n    cin >> t;\n    while (t-- > 0) {\n        int n, k;\n        cin >> n >> k;\n        queue<int> q;\n        while (n-- > 0) {\n            int a;\n            cin >> a;\n            q.push(a);\n        }\n        queue<int> ans = modifyQueue(q, k);\n        while (!ans.empty()) {\n            int a = ans.front();\n            ans.pop();\n            cout << a << \" \";\n        }\n        cout << endl;\n    }\n}// } Driver Code Ends\n\n\n// User function Template for C++\n\n// Function to reverse first k elements of a queue.\nqueue<int> modifyQueue(queue<int> q, int k) {\n    // add code here.\n    \n    queue<int> ans;\n    stack<int>st;\n    \n    while(k--){\n        st.push(q.front());\n        q.pop();\n    }\n    \n    while(!st.empty()){\n        ans.push(st.top());\n        st.pop();\n    }\n    \n    while(!q.empty()){\n        ans.push(q.front());\n        q.pop();\n    }\n    \n    return ans;\n}\n"
  },
  {
    "path": "Leetcode/stack/Valid Parentheses.cpp",
    "content": "// https://leetcode.com/problems/valid-parentheses/\n\nclass Solution {\npublic:\n    bool isValid(string s) {\n        stack<char>st;\n        for(auto c : s){\n            if(st.empty()){\n                st.push(c);\n            }\n            else if( (st.top() == '(' && c == ')') || \n                     (st.top() == '[' && c == ']') || \n                     (st.top() == '{' && c == '}') ){\n                st.pop();\n            }\n            else{\n                st.push(c);\n            }\n        }\n        \n        if(st.size() == 0)\n            return true;\n        \n        return false;\n    }\n};\n"
  },
  {
    "path": "Leetcode/string/Find the Index of the First Occurrence in a String.cpp",
    "content": "// https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/\n// Pattern Matching Algorithm by using KMP Algorithm\n\nclass Solution {\npublic:\n    \n    vector<int> fillLPS(string str){\n        int n = str.size();\n        vector<int>lps(n,0);\n        int len =0, i = 1;\n        lps[0]=0;\n        while(i<n){\n            if(str[len] == str[i]){\n                len++;\n                lps[i] = len;\n                i++;\n            }else{\n                if(len == 0){\n                    lps[i]=0;\n                    i++;\n                }else{\n                    len = lps[len-1];\n                }\n            }\n        }\n        return lps;\n    }\n    \n    int strStr(string haystack, string needle) {\n        int n = haystack.size();\n        int m = needle.size();\n        vector<int>lps = fillLPS(needle);\n        int i=0, j=0;\n        while(i<n){\n            if(haystack[i] == needle[j]){\n                i++;\n                j++;\n                if(j==m){\n                    return i-j;\n                }\n            }\n            else if(i<n && haystack[i] != needle[j]){\n                if(j==0)\n                    i++;\n                else{\n                    j = lps[j-1];\n                }\n            }\n        }\n        return -1;\n    }\n    \n    \n};\n\n\n\n/* SOLUTION NAIVE APPROACH */\n\nclass Solution {\npublic:\n    int strStr(string haystack, string needle) {\n        int i=0, j=0, n= haystack.size(), m = needle.size();\n        if(haystack == needle) return 0;\n        while(i<n){\n            if(haystack[i] == needle[j]){\n                int index = i;\n                string temp = \"\";\n                while(i<n && j<m && haystack[i] == needle[j]){\n                    temp += haystack[i];\n                    i++;\n                    j++;\n                }\n                if(temp == needle){\n                    return index;\n                }else{\n                    i=index+1;\n                    j = 0;\n                }\n\n            }else{\n                i++;\n            }\n        }\n        return -1;\n    }\n};\n"
  },
  {
    "path": "Leetcode/string/Gas Station.cpp",
    "content": "// https://leetcode.com/problems/gas-station/\n\nSolution {\npublic:\n    int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n        int totalDiff =0, n = gas.size(), fuel =0, index =0;\n        for(int i=0; i<n; i++){\n            int diff = gas[i] - cost[i];\n            totalDiff += diff;\n            fuel += diff;\n            if(fuel < 0){\n                index = i+1;\n                fuel = 0;\n            }\n        }\n        return (totalDiff < 0) ? -1 : index;\n    }\n};\n"
  },
  {
    "path": "Leetcode/string/Maximum Ice Cream Bars.cpp",
    "content": "// https://leetcode.com/problems/maximum-ice-cream-bars/\n\nclass Solution {\npublic:\n    int maxIceCream(vector<int>& costs, int coins) {\n        int ans = 0;\n        sort(costs.begin(), costs.end());\n        for(auto x: costs){\n            if(coins >= x){\n                ans++; coins-=x;\n            }\n        }\n        return ans;\n    }\n};\n"
  },
  {
    "path": "Leetcode/sum of numbers in string.cpp",
    "content": "// https://practice.geeksforgeeks.org/problems/sum-of-numbers-in-string/0\n\n#include <iostream>\nusing namespace std;\n\nint findSum(string s)\n{\n\t// Your code here\n\tint n = (int)s.size();\n\tint num=0;\n\tint sum=0;\n\tfor(int i=0;i<n;i++){\n\t    \n\t    if(s[i]>='0' && s[i]<='9')\n\t        num = num*10 + (s[i]-'0');\n\t    else{\n\t        sum += num;\n\t        num = 0;\n\t    }\n\t}\n\t\n\treturn sum+num;\n}\n\nint main()\n{\n\tint t;\n\tcin>>t;\n\twhile(t--)\n\t{\n\t    string str;\n\t    cin>>str;\n\t    cout << findSum(str);\n        cout<<endl;\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "README.md",
    "content": "# Competitive Programming by </ <a href=\"https://www.youtube.com/channel/UCbW63uLlDnsL7l992Z9nF_Q/\" target=\"_blank\">HELLO WORLD </a> >\n\n[Hello World](https://www.youtube.com/channel/UCbW63uLlDnsL7l992Z9nF_Q/)\n\nThis section will provide you the pdf of my lecture and codes.\n\nI have Youtube channel named - \"Hello World\" \n\n\nMy channel contains Courses on \n\n* Competitive Programming\n* Data Structure\n* Algorithms like sorting , searching , graph etc\n* C++ Language\n* And lots of stuffs \n\nYou can contact me on my Email ID : Helloworldbyprince@gmail.com\n"
  },
  {
    "path": "STL/Array_Algorithms_in_stl.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 26/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n//                  all_of | any_of | none_of | copy_n | iota\n\n\n#include <iostream>\n#include <algorithm>\n#include <numeric>\nusing namespace std;\nint main(){\n    int a[6] = {2, 5 , -6, 7, 9,100};\n//    int count=0;\n//    for(int i=0;i<6;i++){\n//        if(a[i]>=0){\n//            count++;\n//        }\n//    }\n    \n    all_of(a, a+6, [](int x){ return x>0;}) ? cout<<\"all elements of array is +ve\"<<endl : cout<<\"All elements of array is not necessary to be +ve\"<<endl;\n    \n    any_of(a, a+6, [](int x){return x<0;}) ? cout<<\"we have atleast one -ve element\"<<endl : cout<<\"All elements are +ve\"<<endl;\n    \n    none_of(a, a+6, [](int x){return x==100;}) ? cout<<\"we have none of element exactly is equal to 100 \"<<endl : cout<<\"It means we have atleast one element  = 100\"<<endl;\n    \n    \n    int arr1[6];\n    copy_n(a, 6 , arr1);  // aaray  size  new_array\n    for(int i=0;i<6;i++){cout<<arr1[i]<<\" \";} //\n    \n    cout<<endl;\n    int arr2[6]; // 2 3 4 5 6 7\n    iota(arr2, arr2+6 , 20);\n    for(int i=0;i<6;i++){cout<<arr2[i]<<\" \";} //\n    cout<<endl;\n\n}\n"
  },
  {
    "path": "STL/Binary search in STL.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 28/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <algorithm>\nusing namespace std;\nvoid show(int a[], int asize){\n    for(int i=0;i<asize;i++){\n        cout<<a[i]<<\" \";\n    }\n    cout<<endl;\n}\nint main(){\n    int a[] = { 2, 3, 0 , 9, 5, 6, 8, 1, 4};\n    int size = sizeof(a)/sizeof(a[0]);\n    \n    show(a, size);\n    \n    cout<<\"array after sorting\"<<endl;\n    sort(a, a+size);//\n    show(a, size);\n    \n    if(binary_search(a, a+size, 18)){\n        cout<<\"Yes our element is present in the array\"<<endl;\n    }else{\n        cout<<\"Our element is not present in the array\"<<endl;\n    }\n}\n\n"
  },
  {
    "path": "STL/List_in_STL.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 8/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <list>\nusing namespace std;\n\nvoid show(list<int> l){\n    list<int> :: iterator it;\n    for(it = l.begin(); it!=l.end(); it++){\n        cout<<*it<<\" \";\n    }\n    cout<<endl;\n}\n\nint main(){\n    list<int> list1;\n    list<int> :: iterator it;\n    list1.push_back(9);\n    list1.push_back(2);\n    list1.push_back(-7);\n    list1.push_back(3);\n\n    \n    it = list1.begin();\n    cout<<*it<<endl;\n    \n    show(list1);\n    \n    //list1.pop_back();\n    //show(list1);\n    \n    cout<<\"front : \"<<list1.front()<<endl;\n    cout<<\"back : \"<<list1.back()<<endl;\n    \n    //list1.clear();\n    cout<<\"empty or not : \"<<list1.empty()<<endl;\n    \n    list1.erase(list1.begin());\n    show(list1);\n\n\n}\n\n\n"
  },
  {
    "path": "STL/Queue_in_STL.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 8/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <queue>\nusing namespace std;\n\nvoid show(queue<int> QUEUE){\n    queue<int> q = QUEUE;\n    while(!q.empty()){\n        cout<<q.front()<<\" \";\n        q.pop();\n    }\n    cout<<endl;\n}\n\nint main(){\n    queue<int> q;\n    q.push(10);\n    q.push(11);\n    q.push(-3);\n    q.push(2);\n    \n    show(q);\n    \n    cout<<\"size : \"<<q.size()<<endl;\n    cout<<\"front : \"<<q.front()<<endl;\n    cout<<\"back : \"<<q.back()<<endl;\n    \n    q.pop();\n    show(q);\n}\n"
  },
  {
    "path": "STL/Vectors_Functions_in_STL.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 29/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <algorithm>\n#include <vector>\n#include <numeric>\nusing namespace std;\nvoid show(vector<int>v){\n    for(int i=0;i<(int)v.size();i++){\n        cout<<v[i]<<\" \";\n    }\n    cout<<endl;\n}\nint main(){\n    vector<int> v;\n    v.push_back(3);\n    v.push_back(0);\n    v.push_back(-4);\n    v.push_back(7);\n    v.push_back(13);\n    v.push_back(8);\n    v.push_back(2);\n\n    show(v);\n    //sort(v.begin(), v.end());\n    //show(v);\n    reverse(v.begin(), v.end());\n    show(v);\n    cout<<*max_element(v.begin(), v.end())<<endl;\n    \n    int x;\n    x = *min_element(v.begin(), v.end());\n    cout<<\"Minimum element : \"<<x<<endl;\n    \n    //cout<<accumulate(v.begin(), v.end(),0 )<<endl;\n    \n    //2  3  4 5\n    int sum=0;\n    sum = accumulate(v.begin(), v.end(),sum);\n    cout<<sum<<endl;\n\n    \n}\n"
  },
  {
    "path": "STL/What is STL.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 31/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <algorithm>\nusing namespace std;\nint main(){\n    int a[10]= {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};\n    sort(a,a+10);\n    for(int i=0;i<10;i++){\n        cout<<a[i]<<\" \";\n    }\n    cout<<endl;\n}\n"
  },
  {
    "path": "STL/deque_in_STL.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 13/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <deque>\nusing namespace std;\n\nvoid showDeque(deque<int> q){\n    deque<int> :: iterator it;\n    for(it = q.begin(); it!=q.end() ;it++){\n        cout<<*it<<\" \";\n    }\n    cout<<endl;\n}\n\nint main(){\n    deque<int> dq;\n    dq.push_back(10);     //   7  10     -3  8\n    dq.push_front(-3);\n    dq.push_back(7);\n    dq.push_front(8);\n    \n    showDeque(dq);\n    cout<<\"size of deque : \"<<dq.size()<<endl;\n    cout<<\"max size : \"<<dq.max_size()<<endl;\n    \n    cout<<dq.at(1)<<endl;\n    cout<<dq.front()<<endl;\n    cout<<dq.back()<<endl;\n    \n    //dq.pop_back();\n    //showDeque(dq);\n    \n    dq.pop_front();\n    showDeque(dq);\n}\n"
  },
  {
    "path": "STL/pair_in_STL.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 19/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <utility>\nusing namespace std;\nint main(){\n    pair<int, char> PAIR1;\n    PAIR1.first = 100;\n    PAIR1.second = 'G';\n    \n    cout<<PAIR1.first<<\" \"<<PAIR1.second<<endl;\n    \n    pair<string, double>PAIR2 (\"prince\" , 78.8);\n    cout<<PAIR2.first<<\" \"<<PAIR2.second<<endl;\n    \n    pair<string, double>PAIR3;\n    PAIR3 = make_pair(\"krishna\", 90.3);\n    cout<<PAIR3.first<<\" \"<<PAIR3.second<<endl;\n\n    pair<int, int> pair1 = make_pair(1, 19);\n    pair<int, int> pair2 = make_pair(2, 7);\n    pair<int, int> pair3(pair2);  // we copied pair2 data in the pair3\n    cout<<pair1.first<<\" \"<<pair1.second<<endl;\n    cout<<pair3.first<<\" \"<<pair3.second<<endl;\n    \n    cout<<(pair1==pair2)<<endl;\n    cout<<(pair1!=pair2)<<endl;\n    cout<<(pair1 >= pair2)<<endl;\n    cout<<(pair1 <= pair2)<<endl;\n\n    // swapping of data in between pairs\n    pair1.swap(pair2);\n    cout<<pair1.first<<\" \"<<pair1.second<<endl;\n    cout<<pair2.first<<\" \"<<pair2.second<<endl;\n\n    \n\n}\n\n"
  },
  {
    "path": "STL/priority Queue in STL.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 14/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <queue>\nusing namespace std;\n\nvoid showPriorityQueue(priority_queue<int> pq){\n    priority_queue<int> q = pq;\n    while(!q.empty()){\n        cout<<q.top()<<\" \";\n        q.pop();\n    }\n    cout<<endl;\n}\n\nint main(){\n    priority_queue<int> q;\n    q.push(10);\n    q.push(-3);\n    q.push(7);\n    q.push(8);\n    \n    showPriorityQueue(q);\n    cout<<q.size()<<endl;\n    \n    q.pop();\n    q.pop();\n    cout<<q.empty()<<endl;\n    showPriorityQueue(q);\n\n}\n"
  },
  {
    "path": "STL/sort_in_STL.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 25/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <algorithm>\n#include <vector>\nusing namespace std;\nvoid showArray(int a[]){\n    for(int i=0;i<10;i++){\n        cout<<a[i]<<\" \";\n    }\n    cout<<endl;\n}\nint main(){\n    int a[10]={9, 8, 1, 2, 7 , 4, 0, 5, 3, 5};\n    showArray(a);\n    \n    sort(a, a+10);\n    showArray(a);\n    \n    vector<int> v;\n    v.push_back(10);\n    v.push_back(-3);\n    v.push_back(2);\n    v.push_back(91);\n    v.push_back(5);\n    v.push_back(7);\n    \n    sort(v.begin(), v.end());\n    for(int i=0;i<(int)v.size();i++){\n        cout<<v[i]<<\" \";\n    }\n    cout<<endl;\n\n    \n}\n"
  },
  {
    "path": "STL/stack in STL data structure.cpp",
    "content": "//\n//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 6/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <stack>\nusing namespace std;\n\nvoid printElementOfStack(stack<int> s){\n    while(!s.empty()){\n        cout<<s.top()<<endl;\n        s.pop();\n    }\n}\n\nint main(){\n    stack<int> s;\n    s.push(3);\n    s.push(10);\n    s.push(-3);\n    s.push(9);\n    \n    cout<<s.empty()<<endl;\n    cout<<s.size()<<endl;\n    \n    printElementOfStack(s);\n}\n\n\n\n\n\n"
  },
  {
    "path": "Templates_in_c++.cpp",
    "content": "//\n//  main.cpp\n//\n//  Created by Prince  Kumar on 03/05/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** TEMPLATES in C++ **---\n\n#include <iostream>\nusing namespace std;\ntemplate <typename T>\n//template <class T>\n\nT MAX ( T a , T b){\n    return a>b ? a : b;\n}\n\ntemplate <class Y>\nclass boy {\npublic:\n    Y name;\n};\nint main(){\n    //cout<<add(3,4)<<endl;\n    auto x = MAX<char>('a', 'c');\n    cout<<x<<endl;\n    \n    boy<string> person;\n    person.name=\"prince\";\n    cout<<(person.name)<<endl;\n    \n}\n"
  },
  {
    "path": "Tree/Binary seacrh tree",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 26/07/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                      ---** TREE DATA STRUCTURE in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nstruct node{\n    int data;\n    node* left;\n    node* right;\n};\n\nnode* newNode(int data){\n    node* temp = new node();\n    temp->data = data;\n    temp->left = NULL;\n    temp->right = NULL;\n\n    return temp;\n}\n\nnode * search(node * root, int key){\n    if(root==NULL || root->data == key)\n        return root;\n    \n    // if key is greater than root\n    if( root->data < key){\n        return search(root->right, key);\n    }\n    \n    return search(root->left, key);\n}\n\nint main(){\n    node * root = newNode(4);\n    root->left = newNode(2);\n    root->right = newNode(5);\n    root->left->left = newNode(1);\n    root->left->right = newNode(3);\n    \n    /*\n                   4\n                 /   \\\n                2     5\n               / \\\n              1   3\n        \n        */\n    \n    node* address = search(root, 5);\n    cout<<address->data<<endl;\n}\n"
  },
  {
    "path": "Tree/Binary_tree.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 05/07/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nstruct node{\n    int data;\n    node* left;\n    node* right;\n};\nnode* newNode(int data){\n    node* element = new node();\n    element->data = data;\n    element->left = NULL;\n    element->right = NULL;\n\n    return element;\n}\n//node* newNode(int data){\n//    node* node = new struct node();\n//    node->data = data;\n//    node->left = NULL;\n//    node->right = NULL;\n//\n//    return node;\n//}\n\nvoid printNode(node *n){\n    while( n!=NULL){\n        cout<<n->data<<\" \";\n        n = n->left;\n    }\n    cout<<endl;\n}\nint main(){\n    // make root node\n    node* root  = newNode(1);\n    \n    /*\n            1\n          /   \\\n        NULL  NULL\n     \n     */\n    \n    root->left = newNode(2);\n    /*\n           1\n         /   \\\n       2      NULL\n      /  \\\n    NULL  NULL\n     \n    \n    */\n    root->right = newNode(3);\n    root->left->left = newNode(4);\n    \n    printNode(root);\n}\n\n// 1 2 3 4 5 6 7\n"
  },
  {
    "path": "Tree/Code of Deletion of Node in BST.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 04/08/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                      ---** TREE DATA STRUCTURE in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nstruct node{\n    int data;\n    node* left ,* right;\n};\n\nnode* newNode(int data){\n    node* temp = new node();\n    temp->data = data;\n    temp->left = NULL;\n    temp->right = NULL;\n\n    return temp;\n}\n\nvoid inorder(node* root){\n    if(root!=NULL){\n        inorder(root->left);\n        cout<<(root->data)<<\" \";\n        inorder(root->right);\n    }\n}\n\nnode *insert(node * node, int key){\n    \n    // tree empty\n    if(node == NULL) return newNode(key);\n    \n    // key is smaller than node->data\n    if(key < (node->data)){\n        node->left = insert(node->left, key);\n    }\n    else if( key > (node->data)){\n        node->right = insert(node->right, key);\n    }\n    \n    // else\n    return node;\n}\n\n/* Given a non-empty binary search tree, return the node with minimum\nkey value found in that tree. Note that the entire tree does not\nneed to be searched. */\n\nnode * minValueNode(node * node){\n    struct  node *current = node;\n    \n    /* loop down to find the leftmost leaf */\n    while(current && current->left != NULL )\n        current = current->left;\n    \n    return current;\n}\n\n\n/* Given a binary search tree and a key, this function deletes the key\nand returns the new root */\nnode * deleteNode(node * root, int key){\n    // base case\n    if(root == NULL) return root;\n    \n    // If the key to be deleted is smaller than the root's key, then it lies in left subtree\n    if(key < root->data){\n        root->left  = deleteNode(root->left, key);\n    }\n    \n    // If the key to be deleted is greater than the root's key, then it lies in right subtree\n    else if(key > root->data){\n        root->right  = deleteNode(root->right, key);\n    }\n    \n    // if key is same as root's key, then This is the node to be deleted\n    else{\n        // node with only one child or no child\n        if(root->left == NULL){\n            node * temp = root->right;\n            free(root);\n            return temp;\n        }\n        else if(root->right == NULL){\n            node * temp = root->left;\n            free(root);\n            return temp;\n        }\n        \n        // node with two children: Get the inorder successor (smallest in the right subtree)\n        \n        node * temp = minValueNode(root->right);\n        \n        // Copy the inorder successor's content to this node\n        root->data = temp->data;\n        \n        // Delete the inorder successor\n        root->right = deleteNode(root->right, temp->data);\n        \n    }\n    \n    return root;\n\n}\n\n\nint main(){\n    /* Let us create following BST\n              50\n           /     \\\n          30      70\n         /  \\    /  \\\n       20   40  60   80 */\n    \n    node *root = NULL;\n    root = insert(root, 50);\n    root = insert(root, 30);\n    root = insert(root, 20);\n    root = insert(root, 40);\n    root = insert(root, 70);\n    root = insert(root, 60);\n    root = insert(root, 80);\n    \n    root = deleteNode(root, 20);\n    inorder(root);\n    cout<<endl;\n    root = deleteNode(root, 30);\n    inorder(root);\n    cout<<endl;\n    root = deleteNode(root, 50);\n    inorder(root);\n}\n"
  },
  {
    "path": "Tree/Code of Inorder Traversal.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 21/07/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nstruct node{\n    int data;\n    node* left;\n    node* right;\n};\n\nnode* newNode(int data){\n    node* temp = new node();\n    temp->data = data;\n    temp->left = NULL;\n    temp->right = NULL;\n\n    return temp;\n}\n\nvoid printInorder(node *node){\n    if(node == NULL)\n        return;\n    \n    /* first traverse left part of tree */\n    printInorder(node->left);\n    \n    /* then print data  */\n    cout<<node->data<<\" \";\n    \n    /* and last  traverse right part of tree */\n    printInorder(node->right);\n}\n\n\nint main(){\n    node * root = newNode(1);\n    root->left = newNode(2);\n    root->right = newNode(3);\n    root->left->left = newNode(4);\n    root->left->right = newNode(5);\n    \n    /*\n                   1\n                 /   \\\n                2     3\n               / \\\n              4   5\n        \n        */\n    cout<<\"Inorder Traversl of Tree : \"<<endl;\n    printInorder(root);\n}\n"
  },
  {
    "path": "Tree/Insertion in BST.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 29/07/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                      ---** TREE DATA STRUCTURE in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nstruct node{\n    int data;\n    node* left ,* right;\n};\n\nnode* newNode(int data){\n    node* temp = new node();\n    temp->data = data;\n    temp->left = NULL;\n    temp->right = NULL;\n\n    return temp;\n}\n\nvoid inorder(node* root){\n    if(root!=NULL){\n        inorder(root->left);\n        cout<<(root->data)<<\" \";\n        inorder(root->right);\n    }\n}\n\nnode *insert(node * node, int key){\n    \n    // tree empty\n    if(node == NULL) return newNode(key);\n    \n    // key is smaller than node->data\n    if(key < (node->data)){\n        node->left = insert(node->left, key);\n    }\n    else if( key > (node->data)){\n        node->right = insert(node->right, key);\n    }\n    \n    // else\n    return node;\n}\n\nint main(){\n    /*     50\n        /     \\\n       30      70\n      /  \\    /  \\\n    20   40  60   80  */\n    \n    node *root = NULL;\n    root = insert(root, 50);\n    insert(root, 30);\n    insert(root, 70);\n    insert(root, 20);\n    insert(root, 40);\n    insert(root, 60);\n    insert(root, 80);\n\n    inorder(root);\n    cout<<endl;\n\n}\n"
  },
  {
    "path": "Tree/code of Hashing in C++.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 14/08/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                      ---** TREE DATA STRUCTURE in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\n#include <math.h>\nusing namespace std;\n#define MAX 1000\n\nbool hashTable[MAX+1][2];\n\nbool search(int x){\n    if(x>=0){\n        if(hashTable[x][0] == 1 ){\n            return true;\n        }else{\n            return false;\n        }\n    }else{\n        x = abs(x);\n        if(hashTable[x][1] == 1 ){\n            return true;\n        }else{\n            return false;\n        }\n    }\n}\n\nvoid insert(int a[], int n){\n    for(int i=0;i<n;i++ ){\n        if(a[i]>=0){\n            hashTable[a[i]][0] = 1;\n        }\n        else{\n            hashTable[abs(a[i])][1] = 1;\n        }\n    }\n}\n\nint main(){\n    int arr[] = {-1, 9, 2, -5, 3, 1};\n    int n = sizeof(arr)/sizeof(arr[0]);\n    insert(arr, n);\n    \n    int find  = -1;\n    if(search(find)){\n        cout<<\"Element is present\"<<endl;\n    }else{\n        cout<<\"Element is not present \"<<endl;\n    }\n    \n}\n"
  },
  {
    "path": "Tree/code of preorer and Postorder traversal.cpp",
    "content": "//  DATA STRUCTURES.cpp\n//\n//  Created by Prince  Kumar on 23/07/2020.\n//  Copyright © 2020 Prince Kumar. All rights reserved.\n//\n//                 ---** STANDARD TEMPLATE LIBRARY (STL) in C++ **---\n//                         ---** PRACTICE CODING SKILLS **---\n\n\n#include <iostream>\nusing namespace std;\nstruct node{\n    int data;\n    node* left;\n    node* right;\n};\n\nnode* newNode(int data){\n    node* temp = new node();\n    temp->data = data;\n    temp->left = NULL;\n    temp->right = NULL;\n\n    return temp;\n}\n\nvoid printInorder(node *node){\n    if(node == NULL)\n        return;\n    \n    /* first traverse left part of tree */\n    printInorder(node->left);\n    \n    /* then print data  */\n    cout<<node->data<<\" \";\n    \n    /* and last  traverse right part of tree */\n    printInorder(node->right);\n}\n\nvoid printPreorder(node *node){\n    if(node == NULL)\n        return;\n    \n    /* then print data  */\n    cout<<node->data<<\" \";\n    \n    \n    /* first traverse left part of tree */\n    printPreorder(node->left);\n    \n    \n    /* and last  traverse right part of tree */\n    printPreorder(node->right);\n}\n\n\nvoid printPostorder(node *node){\n    if(node == NULL)\n        return;\n    \n    /* first traverse left part of tree */\n    printPostorder(node->left);\n    \n    \n    /* and last  traverse right part of tree */\n    printPostorder(node->right);\n    \n    /* then print data  */\n    cout<<node->data<<\" \";\n}\n\n\nint main(){\n    node * root = newNode(1);\n    root->left = newNode(2);\n    root->right = newNode(3);\n    root->left->left = newNode(4);\n    root->left->right = newNode(5);\n    \n    /*\n                   1\n                 /   \\\n                2     3\n               / \\\n              4   5\n        \n        */\n    cout<<\"Inorder Traversl of Tree : \"<<endl;\n    printInorder(root);\n    cout<<\"preorder Traversl of Tree : \"<<endl;\n    printPreorder(root);\n    cout<<\"postorder Traversl of Tree : \"<<endl;\n    printPostorder(root);\n\n}\n"
  },
  {
    "path": "chef and Icecream.cpp",
    "content": "//\n//  COMPETITIVE PROGRAMMING .cpp\n//\n//  Created by Prince  Kumar on 15/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                       ---** COMPETITIVE PROGRAMMING in C++ **---\n//                            ---** PRACTICE CODING SKILLS **---\n//                               ---** CHEF AND ICECREAM **---\n\n\n#include <iostream>\nusing namespace std;\nint main(){\n    int T; cin>>T;\n    while(T--){\n        int n; cin>>n;\n        int a[3]= {0,0,0};  // 5 10 15\n        int check=0;\n        for(int i=0;i<n;i++){\n            int x; cin>>x;\n            \n            if(x==5){\n                a[0]+=1;\n            }else if(x==10){\n                if(a[0]>=1){\n                    a[1]+=1;\n                    a[0]-=1;\n                }else{\n                    check++;\n                }\n            }else{\n                if(a[1]>=1){\n                    a[2]+=1;\n                    a[1]-=1;\n                }else if(a[0]>=2){\n                    a[2]+=1;\n                    a[0]-=2;\n                }else{\n                    check++;\n                }\n            }\n        }\n        if(check==0){\n            cout<<\"YES\"<<endl;\n        }else{\n            cout<<\"NO\"<<endl;\n        }\n    }\n}\n"
  },
  {
    "path": "chef and string.cpp",
    "content": "//\n//  COMPETITIVE PROGRAMMING .cpp\n//\n//  Created by Prince  Kumar on 15/06/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                       ---** COMPETITIVE PROGRAMMING in C++ **---\n//                            ---** PRACTICE CODING SKILLS **---\n//                                   ---** CHEF AND STRING **---\n\n\n#include <iostream>\nusing namespace std;\nint main(){\n    int T; cin>>T;\n    while(T--){\n        string s; cin>>s;\n        int n = (int)s.size();\n        int i=0;\n        int count=0;\n        // 0 1 2 3 4 5    i=5\n        while(i<n){\n            if(s[i]!=s[i+1] && (i+1)<n){\n                count++;\n                i+=2;\n            }else{\n                i++;\n            }\n        }\n        cout<<count<<endl;\n    }\n}\n"
  },
  {
    "path": "map_in_c++",
    "content": "//\n//  main.cpp\n//\n//  Created by Prince  Kumar on 30/04/2020.\n//  Copyright © 2020 Prince  Kumar. All rights reserved.\n//\n//                      ---** MAP in C++ **---\n\n#include <iostream>\n#include <map>\nusing namespace std;\nint main(){\n    // roll_num   weight of student\n    map < int , int > person;\n    \n    // Insert the values in map\n    person.insert(pair<int, int>(1,35));\n    person.insert({2, 40});\n    person.insert({3,50});\n    person.insert({5, 10});\n    \n    \n//    auto it = person.find(3);\n//    person.erase(it);\n    \n    //person.erase(5);\n    \n    \n    // print\n    for(auto itr = person.begin() ; itr!=person.end() ; ++itr){\n        cout<<itr->first <<\"  \" <<itr->second<<endl;\n    }\n    \n    // .begin()  --> return iterator\n    //auto var  = person.begin();\n    //cout<<\"By var iterator  \" <<var->first <<\" \"<<var->second<<endl;\n    \n    // .end()  --> return iterator\n    //auto var  = person.end();   // Not actual map\n    //cout<<\"By var iterator  \" <<var->first <<\" \"<<var->second<<endl;\n    \n    //cout<<person.size()<<endl;\n    //cout<<person.max_size()<<endl;\n    \n    // .erase()\n    \n    // .empty()  -->whether map is empty or not\n    // 0 --> map is not empty\n    // 1 --> map is empty\n    \n    \n    person.clear();   // delete all the values in map\n    cout<<\"map is empty or not ?  \"<<person.empty()<<endl;\n    \n    \n    \n   \n}\n"
  }
]