Created
June 12, 2019 21:07
-
-
Save jasonwaters/563aa8abaabf3b2bf38847b868423c7d to your computer and use it in GitHub Desktop.
Delete Columns to Make Sorted
This file contains 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
// 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