Skip to content

Instantly share code, notes, and snippets.

@nguyenhuumy
Created September 6, 2017 16:07
Show Gist options
  • Select an option

  • Save nguyenhuumy/7645717daa1ff68f81fe3e6138dea116 to your computer and use it in GitHub Desktop.

Select an option

Save nguyenhuumy/7645717daa1ff68f81fe3e6138dea116 to your computer and use it in GitHub Desktop.
//input N, S
N = 1; var S = "";
var Table = {}
var COMBO = ['ABC', 'DEF', 'EFG', 'HJK'];
for (var i = 0; i < N; i++) {
Table[i] = [];
for (var j=0; j < COMBO.length; j++) {
Table[i].push({family: COMBO[j], available: true});
}
}
var seats = S.split(" ");
for (var i=0; i < seats.length; i++) {
var match = seats[i].match(/(\d+)(\w+)/);
if (!match) {
continue;
}
var row = match[1] - 1; // array index start with 0 while row on airplane start with 1
var col = match[2];
for (var j=0; j < Table[row].length; j++) {
if (Table[row][j].family.indexOf(col) > -1) {
Table[row][j].available = false;
}
}
}
var count = 0;
for (var i = 0; i < N; i++) {
for (var j = 0; j < Table[i].length; j++) {
if (Table[i][j].available) {
if(Table[i][j-1] && Table[i][j-1].available && Table[i][j-1].family === "DEF") {
//skip
} else {
count+= 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment