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
+ 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 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 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 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 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; }
Load more conversations
Sort 1184 Discussions, By:
Please Login in order to post a comment