Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created March 4, 2023 14:21
Show Gist options
  • Save Shaddyjr/63a72414b071aa3ae64a6ae4739eb51b to your computer and use it in GitHub Desktop.
Save Shaddyjr/63a72414b071aa3ae64a6ae4739eb51b to your computer and use it in GitHub Desktop.
// 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