Sort by

recency

|

1299 Discussions

|

  • + 0 comments
    def serviceLane(n, cases):
        # Write your code here
        result = []
        for i in range(len(cases)):
            width_max = min(width[cases[i][0]:cases[i][1]+1])
            result.append(width_max)
        return result
        
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/iuLCUdG77yQ You will need to update the serviLane function by adding the width vector, since it was forgotten.

    vector<int> serviceLane(int n, vector<vector<int>> cases, vector<int> width) {
        vector<int> result;
        for(auto cas: cases){
            int r = width[cas[0]];
            for(int i = cas[0]; i <= cas[1]; i++){
                r = min(r, width[i]);
            }
            result.push_back(r);
        }
        return result;
    }
    
  • + 0 comments

    The example at the beginning uses 1-based indexing for the width array, whereas the sample later on uses 0-based indexing.

  • + 0 comments

    Typescript minimal solution (I had to fix the function since it missed the width param):

    function serviceLane(cases: number[][], width: number[]): number[] {
        const results = [].constructor(cases.length);
        cases.forEach((c, index) => {
            results[index] = width[c[0]];
            for (let i = c[0]; i <= c[1]; i++) {
                if (results[index] > width[i]) results[index] = width[i];
            }
        });
        return results;
    }
    
  • + 0 comments
    def serviceLane(n, cases):
        l=[]
        for i in cases:
            l.append(min(width[i[0]:i[1]+1]))
        return l