You are viewing a single comment's thread. Return to all comments →
My solution is pretty simple but it times out on half the tests, so I guess it's no good.
function main() { var n = parseInt(readLine()); var contacts = []; for(var a0 = 0; a0 < n; a0++){ var op_temp = readLine().split(' '); var op = op_temp[0]; var contact = op_temp[1]; if (op === 'add') { contacts.push(contact); } else if (op === 'find') { var matches = contacts.filter(el => el.indexOf(contact) == 0); console.log(matches.length); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
My solution is pretty simple but it times out on half the tests, so I guess it's no good.