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.
- Prepare
- Algorithms
- Implementation
- Service Lane
- Discussions
Service Lane
Service Lane
Sort by
recency
|
1320 Discussions
|
Please Login in order to post a comment
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.
RUST (fixed function)
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; }"
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)));
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!