Created
March 4, 2023 14:21
-
-
Save Shaddyjr/63a72414b071aa3ae64a6ae4739eb51b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://www.hackerrank.com/challenges/service-lane/problem | |
// video: https://youtu.be/1nLHUwp_k80 | |
function serviceLane(n, width, cases) { | |
const output = [] | |
for(const [start, end] of cases){ // O(c); c = number of cases | |
let min = Infinity | |
for(let i = start; i <= end; i++){ // O(n); n = number of widths | |
min = Math.min(min, width[i]) | |
} | |
output.push(min) | |
} | |
return output | |
// TOTOL TIME COMPLEXITY: O(c) * O(n) = O(c*n) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment