Skip to content

Instantly share code, notes, and snippets.

@jasonwaters
Created June 12, 2019 21:07
Show Gist options
  • Save jasonwaters/563aa8abaabf3b2bf38847b868423c7d to your computer and use it in GitHub Desktop.
Save jasonwaters/563aa8abaabf3b2bf38847b868423c7d to your computer and use it in GitHub Desktop.
Delete Columns to Make Sorted
// https://leetcode.com/problems/delete-columns-to-make-sorted/description/
function minDels(arr) {
let count = 0;
const numCols = arr[0].length;
for(let x=numCols-1;x>=0;x--) {
for(let y=1;y<arr.length;y++) {
if(arr[y][x] < arr[y-1][x]) {
count++;
break;
}
}
}
return count;
}
console.log(minDels(["cba","daf","ghi"])); //1
console.log(minDels(["a","b"])); //0
console.log(minDels(["zyx","wvu","tsr"])); //3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment