Today I had an interview, we were asked a programming question, and I was asked to solve it using c / C ++ / Java, I solved it in java, and its execution time was 3 seconds (the test was more than 16,000 lines and accompanying us said the running time was reasonable), another person there solved it in c, and the lead time was 0.25 s, so I wondered if the coefficient of 12 is normal?
Edit: As I said, I don’t think that there really were a lot of possibilities for changing the algorithm, with the possible exception of one little thing, in any case, there was this protocol that we had to implement: A (client) and B (server ) exchange data in accordance with some protocol p, before messages are delivered, their validation is checked, the protocol is determined by its state and text messages that can be sent when it is in a certain state, in all states Only one valid message has been compiled, except for one state in which 10 messages were sent, there are 5 states, and the state transition is also determined by the protocol. so what I did with the state from which 10 different messages can be sent is to store their string value in an ArrayList container, and then when I need to check the correctness of the message in the corresponding state, I checked if arrayList.contains (sentMessageStr ); I think this complexity of the operation is O (n), although I think java has a built-in optimization for this operation, although now that I think about it, maybe I should have used a HashSet container. I assume that an implementation of c would store these predefined lexical strings lexicographically in an array and implement a binary search function.
thanks
Noona source share