Sort by

recency

|

1320 Discussions

|

  • + 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

    RUST (fixed function)

    fn serviceLane(width: &[i32], cases: &[Vec<i32>]) -> Vec<i32> {
        let mut result: Vec<i32> = Vec::new();
        for case in cases {
            let first_idx = case[0] as usize;
            let second_idx = case[1] as usize;
            if let Some(min_value) = &width[first_idx..=second_idx].iter().min() {
                result.push(**min_value);
            }
        }
        result
    }
    
  • + 0 comments

    Hello HackerRank Team, I am attempting to solve the "Service Lane" problem, but I noticed that the function signature provided in the problem description is incomplete. The function: vector serviceLane(int n, vector> cases) is missing the width array, which is required to determine the minimum width for each query. Without this array, it is not possible to correctly implement the solution. vector serviceLane(int n, vector width, vector> cases) Could you please confirm if this is an issue with the problem statement or if we are expected to handle width differently? Solution in cpp. " int minWidth(vector width, int st, int ed) { int miniumWidth = width[st]; for (int i = st + 1; i <= ed; i++) { miniumWidth = (miniumWidth < width[i]) ? miniumWidth : width[i]; } return miniumWidth; } vector serviceLane(int n, vector width, vector> cases) { vector result; int totalCases = cases.size(); for (int i = 0; i < totalCases; i++) { int st = cases[i][0]; int ed = cases[i][1]; result.push_back(minWidth(width, st, ed)); } return result; }"

  • + 0 comments

    People have already said this, but to reiterate, in order to write this function propery you need to adjust the call:

    const result = serviceLane(width, cases);

    That is for JS, but it seems like other languages have a similar issue. It also appears (based on the examples given) that the case indexes are 1-based, but in fact they are 0-based. Easy one liner solution once that is fixed:

    const serviceLane = (width, cases) => cases.map(curCase => Math.min(...width.slice(curCase[0], curCase[1] + 1)));

  • + 0 comments

    Service Lane is a game-changer when it comes to convenience! If you’re looking for top-notch home cleaning services, Polar Express Clean has you covered with professional and reliable care. Keeping your space fresh and spotless has never been easier. Highly recommend their services!