We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Service Lane
  5. Discussions

Service Lane

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Sort 1184 Discussions, By:

recency

Please Login in order to post a comment

  • alban_tyrex
    5 days ago+ 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|
    Permalink
  • germain_ngoune
    2 weeks ago+ 0 comments

    TypeScript Solution

    function serviceLane(n: number, width: number[], cases: number[][]): number[] {
        // Write your code here
        let result = [];
        for (let c of cases){
            result.push(width.slice(c[0], c[1]+1).sort((a,b) => a-b)[0]);
        }
        return result;
    }
    
    0|
    Permalink
  • wildHun7
    2 weeks ago+ 0 comments

    Cpp

    vector<int> serviceLane(int n, vector<vector<int>> cases, vector<int> width) {
        vector<int> res;
        for(auto c: cases){        
            res.push_back(*min_element(width.begin() + c[0], width.begin() + c[1] + 1));
        }
    return res; 
    }
    
    0|
    Permalink
  • wildHun7
    2 weeks ago+ 0 comments

    Cpp

    vector<int> serviceLane(int n, vector<vector<int>> cases, vector<int> width) {
        vector<int> res;
        for(auto c: cases){        
            auto itw1 = next(width.begin(), c[0]);
            auto itw2 = next(width.begin(), c[1] + 1);
            res.push_back(*min_element(itw1, itw2));
        }
    return res; 
    }
    
    0|
    Permalink
  • onurozen1
    2 weeks ago+ 0 comments

    C# Solution

    YOU HAVE TO ADD WIDTH PARAMETER!!!

    public static List<int> serviceLane(int n, List<List<int>> cases, List<int> width)
        {
            List<int> result = new List<int>(cases.Count);
    
            for (int i = 0; i < cases.Count; i++)
            {
                int a = cases[i][0], b = cases[i][1]; //entry and exit
    
                int min = width[a];
                for (int j = a + 1; j <= b; j++) //I found minimum width
                {
                    if (width[j] < min)
                        min = width[j];
                }
    
                result.Add(min);
            }
    
            return result;
        }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy