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.
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;
}"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Service Lane
You are viewing a single comment's thread. Return to all 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; }"