- #1
Jamin2112
- 986
- 12
During my in-person interview yesterday, the interviewer asked me to write a function that takes a string and replaces all As with three As
Ex. "Abraham"--->"AAAbraaahaaam"
I did it, but it took me a while to get it right using the replace function (http://www.cplusplus.com/reference/string/string/replace/), because the documentation (which I was allowed to use) doesn't say how the string is re-indexed after using the function. I found it difficult to write the function by iterating through it with an iterator.
Anyways, I was wondering whether someone here could show me their most elegant solution, just so I can see what I could've improved on.
Ex. "Abraham"--->"AAAbraaahaaam"
I did it, but it took me a while to get it right using the replace function (http://www.cplusplus.com/reference/string/string/replace/), because the documentation (which I was allowed to use) doesn't say how the string is re-indexed after using the function. I found it difficult to write the function by iterating through it with an iterator.
Anyways, I was wondering whether someone here could show me their most elegant solution, just so I can see what I could've improved on.