Let's categorize this for PHP only.
Ok so I had an interview yesterday for a Senior Software Developer role. I can't remember the question very well but I try to write it as much as I remember.
Question;
Write a function that takes a string as the input and return true if traversed, false if not.
Requirements; (as much as I remember)
- Only one input (string) type.
- String param must be passed by reference.
- No variable within the function, he means that if the param is called $str manipulation should be done on that, didn't like me to use a second variable to set reverseStr etc.
- No looping every character in the string, he specifically said not to loop thru every character in the string.
- No Built-in PHP function can be used, i think he was fine with (strlen)
My Answer; (nope he didn't like it)
$str = 'this is testing';
$length = strlen($str);
$reverseStr = '';
for($i=$length-1; $i>=0; $i--) {
$reverseStr .= $str[$i];
}
So while this does the job somewhat, he didn't like me to go thru every character to get the reverseStr. I am guessing I needed to think about a recursive solution get the last character of the string and index etc.etc. but I am thinking about these as I am writing this, too late!
What you guys thinking?