This is an interview question. I wanted to know if instead of ‘a’ we want to replace ‘xyz’ does that mean we have to create 2 extra space or can I increase the size at that particular index? What could be the most efficient complexity of it in terms of running time.
Thanks!
Complexity will be
O(strlen(in)), optimization is going to be focused on the constant.I’ve come up with a simple, relatively efficient implementation. Note that since we are told to build the result in-place, we MUST assume that the original buffer is large enough to accommodate the growth.
Going to test it on ideone.
Done: http://ideone.com/nAgej