We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Very elegant, point_to_null! Nothing short of brilliant, in fact. A couple of questions:
(1) Why does this still pass all tests, given that it completely ignores the first input (the first input is a number which specifies how many total add/find operations will be done)
(2) Why is this time- and space-wise more efficient than simply creating a string of names (for creating the contact list) and, for searching, merely counting grep matches, like this:
read numops
contactlist=""for((i=0; i < numops; i++));doread operation name
[[$operation== add ]]&&contactlist="$contactlist$name"[[$operation== find ]]&&echo$contactlist| tr " ""\n"| grep -c ^$namedone
I believe this code also will pass all tests, but hackerrank systems give me a timeout error on all but three tests! Is this happening because of the for loop I'm running?
Cookie support is required to access HackerRank
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 →
Very elegant, point_to_null! Nothing short of brilliant, in fact. A couple of questions:
(1) Why does this still pass all tests, given that it completely ignores the first input (the first input is a number which specifies how many total add/find operations will be done)
(2) Why is this time- and space-wise more efficient than simply creating a string of names (for creating the contact list) and, for searching, merely counting grep matches, like this:
I believe this code also will pass all tests, but hackerrank systems give me a timeout error on all but three tests! Is this happening because of the for loop I'm running?