GithubHelp home page GithubHelp logo

coding-discussions-ieeesbm-mrityunjay-shukla's Introduction

Coding-Discussions-IEEESBM-Mrityunjay-Shukla

Question

  • Max Chunks To Make Sorted

    Solution:-

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int maxChunksToSorted(vector<int> &arr)
    {
       int maxi = 0;
       int cnt = 0;
       for (int i = 0; i < arr.size(); i++)
       {
         maxi = max(maxi, arr[i]);
         if (maxi == i)
          {
            cnt++;
          }
        // cout << cnt << endl;
        // cout << maxi << " " << i << endl;
    }
    
    return cnt;
    }
    
    int main()
    {
       int n;
       cin >> n;
       vector<int> v(n);
       for (int i = 0; i < n; i++)
       {
         cin >> v[i];
        }
      cout << maxChunksToSorted(v) << endl;
      return 0;
    }
    
      #include <bits/stdc++.h>
    
      using namespace std;
    
      bool solution(vector<long long int> A, vector<long long int> P, long long int B, long long int E)
      {
        vector<pair<long long int, long long int>> v(A.size());
          for (long long int i = 0; i < P.size(); i++)
      {
          v[i] = make_pair(P[i] - A[i] > 0 ? P[i] - A[i] : 0, P[i] + A[i]);
          cout << "Loop1" << endl;
      }
      // cout<<"Hello"<<endl;
      sort(v.begin(), v.end());
      if (B > E)
      {
          for (long long int i = P.size() - 1; i >= 0; i--)
        {
            cout << "B:- " << B << endl;
            if (v[i].second >= B && v[i].first < B)
            {
                B = v[i].first > E ? v[i].first : E;
            }
            if (B == E)
            {
                cout << "B:- " << B << endl;
                return true;
            }
        }
    }
    else if (B < E)
    {
        for (long long int i = 0; i < P.size(); i++)
        {
            cout << "B:- " << B << endl;
            if (v[i].first <= B && v[i].second > B)
            {
                B = v[i].second < E ? v[i].second : E;
            }
            if (B == E)
            {
                cout << "B:- " << B << endl;
                return true;
            }
        }
    }
    return false;
    }
    
    int main()
    {
        long long int n, b, e;
        cin >> n;
        vector<long long int> A(n);
        vector<long long int> P(n);
        for (long long int i = 0; i < n; i++)
        {
            cin >> A[i];
        }
        for (long long int i = 0; i < n; i++)
        {
            cin >> P[i];
        }
        cin >> b >> e;
        if (solution(A, P, b, e))
        {
            cout << "Works";
        }
        else
            cout << "Doesn't work" << endl;
    
        return 0;
    }
    

coding-discussions-ieeesbm-mrityunjay-shukla's People

Contributors

mrityunjayshukla411 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.