Skip to content

Instantly share code, notes, and snippets.

@manuelgeek
Last active September 15, 2022 18:07
Show Gist options
  • Save manuelgeek/9955eb3b6b4900ff2ddfeefd08fe0142 to your computer and use it in GitHub Desktop.
Save manuelgeek/9955eb3b6b4900ff2ddfeefd08fe0142 to your computer and use it in GitHub Desktop.
Disk Space Analysis
// solution([1,12,121,15,67])
function solution(A) {
const newArr = A.sort(function (a, b) { return a - b; });
for (let i = 0; i < newArr.length - 1; i++) {
console.log(Math.abs(newArr[i] - newArr[i + 1]))
if (Math.abs(newArr[i] - newArr[i + 1]) === 1) {
console.log(true)
return true
}
}
console.log(false)
return false
}
function segment(x, space) {
// Write your code here
let list = []
// console.log({space})
// console.log({x})
for(let i = 0; i < space.length; i++){
if((i+x) <= space.length){
let li = []
for(let j = 0; j < x; j++ ){
li.push(space[i+j])
}
list.push(li)
}
}
// console.log(list)
let mins = []
if(list.length === 0) {
mins = space
} else {
let min = Number.POSITIVE_INFINITY
let z = 0;
while(z < list.length){
if(list[z]) {
min = Math.min( ...list[z] )
}
mins.push(min)
z++
}
}
// console.log(mins)
return Math.max(...mins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment