Tuesday, September 20, 2022
HomeWordPress DevelopmentGojek Interview Expertise for Internship (On-Campus) 2022

Gojek Interview Expertise for Internship (On-Campus) 2022


View Dialogue

Enhance Article

Save Article

Like Article

View Dialogue

Enhance Article

Save Article

Like Article

This downside was requested within the OA rounds of Gojek throughout my On-campus internship in 2022. The issue assertion goes as follows:

  • There are n processes that should be assigned to m processors such that the kth processor ought to have the utmost variety of processes (the kth processor is probably the most environment friendly one). Additionally, every processor should be assigned at the very least one course of and the variety of processes assigned to the adjoining processors should not exceed 1. You should discover the utmost variety of processes that may be assigned to the kth processor following all of the given constraints.

This downside will not be obtainable anyplace over the web, so once I solved it, I made a decision to contribute it right here in order that others can consult with it and get a glimpse of what sort of questions are requested within the OAs. 

At first, this query regarded a bit difficult, however after giving it a while, I bought the binary search strategy to resolve the issue. 

The C++ code is as follows:

C++

#embrace <bits/stdc++.h>

utilizing namespace std;

  

#outline ll lengthy lengthy

  

bool isPossible(ll x, ll n, ll m, ll ok){

    ll tot = x;

      

    

    

      

    ll temp = x-1; 

    ll ind = k-1; 

    whereas(ind >= 0){

        if(temp < 1){

           tot += 1;

           ind--;

           proceed;

        }

        tot += temp;

        ind--;

        temp--;

    }

      

    

    

      

    temp = x-1;

    ind = ok+1; 

    whereas(ind < m){

        if(temp < 1){

           tot += 1;

           ind++;

           proceed;

        }

        tot += temp;

        ind++;

        temp--;

    }

      

    

    

    

      

    return tot <= n;

}

  

int major(){

    ll n;

    ll m;

    ll ok;

      

    cin >> n >> m >> ok;

      

    ll low = 0, excessive = n;

    whereas(low <= excessive){

        ll mid = low+(high-low)/2;

          

        if(isPossible(mid, n, m, ok)) low = mid+1;

        else excessive = mid-1;

    }

      

    cout << excessive << endl;

  

    return 0;

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments