Tips to make code "Production ready". What interviewer really wants.

Guys,

I have gone through this "Production ready" code request from interviewer and I got an explanation and idea of what that would usually mean. That would mean "While answer to this question is very easy, please ask anything now only.. and cover all tests in first attempt.". Finally, I was rejected for not covering 7 test-cases out of 15 in atoi() implementation (I didn't even know of LC that time, so you can forgive me). In the mid of it, when I asked "What to do if I get "123abc", he said, "you should have asked earlier".
The best approach to simple question would be (and check with interviewer if you have doubt, what will be the return value in this case) => Also called Requirement Analysis phase.

Array input (related to sum, diff, product, division of 2 elements: Check whether you are reaching integer boundary by adding/multiplying 2 positives,or by subtracting 2 array elements (INT_MAX - INT_MIN; out of range and/or divide by 0). Always take care that loop does not go beyond boundary. Handle first and last element separately, if needed.
String input: Check for empty string, weird string having spaces (where you won't expect), string with special characters, (suppose you need to check how many characters are repeated.. and you get only "a", what you'd do?)
Linked-list: Check for one of 2 input lists being exhausted. Check for curr==nullptr before just using curr->next or curr->val.
Trees: Check whether is binary tree or BST. Check node before moving left/right. Check whether you'll need to come back. How recursion will work in getting height, counting nodes, and getting sum of these nodes' values.
Stack/Queue: Are you trying to draw water from empty well? Check for size before popping from them.

LC Doctor's prescription:

1 medium LC problem with your breakfast or 2 easy per day (any time but both at a time)
Check yourself after 30 days and switch to hard accordingly.
Keep checking 1 design problem on weekend.
Geeks are for geeks.. and very helpful.

P.S. I think LC tests cover almost everything you could think of. So, go for doctor's prescription and you'll see improvements for sure.

:-)

Comments (1)