
On 22/03/2017, at 6:44 AM, Michael Litchard
wrote: I got this idea from looking at glassdoor comments of previous interviewees. The spec was vague, but I imagined that the requirement would need to be efficient and keep contiguous parenthesis unaltered. so balanceParens ")))" == "()()()" would be incorrect.
One parenthesIs two parenthesEs. Perhaps you could link to those glassdoor comments? It really is not obvious to me that "keep[ing] contiguous parenthes[e]s unaltered" even makes sense, let alone being desirable. Entirely by coincidence, I had a parenthesis problem about an hour ago, where I had changed fabs(X-(k-1)) to fabs(d)) and the right repair was to delete one of the right parentheses. The point of the question may well be not the code you come up with but the questions you ask on your way. I'd probably ask questions like these: 1. Do you have a precise specification? 2. Are you looking for an obviously correct solution, a solution with small workspace, a fast solution, or what? 3. What operations am I allowed to perform on a string? Which characters may I insert? Which characters may I delete? Is transposition of adjacent characters allowed? 4. Are you looking for a repair of minimal cost in some sense? If so, how is that cost computed? For example, inserting ( might cost 2 units and deleting ) might cost 3 units. 5. There's been a lot of work done on least cost syntax repair (e.g., Roland Backhouse). Am I allowed to look that up?