cpp_is_king
Member
I have a question..Are Link-List questions ever asked? Like for optimization?
If you can think of a question, chances are someone somewhere has asked it.
I have a question..Are Link-List questions ever asked? Like for optimization?
Don't go in expecting specific questions... repeating canned answers is silly. But if you find that you don't interview well without a lot of preparation, yes, you should definitely be prepared to be grilled on data structures like linked lists, trees, and graphs in addition to algorithmic questions like the ones we've been talking about for most of this thread and the more open-ended questions about how you work.I have a question..Are Link-List questions ever asked? Like for optimization?
I just want to come back to this one more time. I don't think I was exaggerating, because while your technical answer might be true, I view coding only in the practical sense. If for any reason you need to reverse an array, it would be in no relation to a situation where you need to reverse a string. The methods being used will also be different and the way you handle the end result. I'd like to put more emphasize to the why, why would you need to reverse an array? Why would you need to reverse a string? The answers would be completely different, so therefor the coding, the handling, the input, the output are all completely different.You know strings are arrays of characters right? Reversing a string is reversing an array. Your comment is quite the exaggeration.
I just want to come back to this one more time. I don't think I was exaggerating, because while your technical answer might be true, I view coding only in the practical sense. If for any reason you need to reverse an array, it would be in no relation to a situation where you need to reverse a string. The methods being used will also be different and the way you handle the end result. I'd like to put more emphasize to the why, why would you need to reverse an array? Why would you need to reverse a string? The answers would be completely different, so therefor the coding, the handling, the input, the output are all completely different.
Am I missing a level of complexity here? I could probably write a recursive function to produce the Fibonacci sequence in a handful of lines.
I just want to come back to this one more time. I don't think I was exaggerating, because while your technical answer might be true, I view coding only in the practical sense. If for any reason you need to reverse an array, it would be in no relation to a situation where you need to reverse a string. The methods being used will also be different and the way you handle the end result. I'd like to put more emphasize to the why, why would you need to reverse an array? Why would you need to reverse a string? The answers would be completely different, so therefor the coding, the handling, the input, the output are all completely different.
I did not say that.Just because you can't think of a real word scenario where you would need to reverse a string doesn't mean it doesn't happen.
I did not say that.
This makes no sense. Nothing would be different. The "coding" (what does that even mean?) would not be different. the "handling" would not be different. The inputs and outputs would not be different (the input would be an array, possibly of characters, the output would be an array, possibly of characters).Soneet said:I'd like to put more emphasize to the why, why would you need to reverse an array? Why would you need to reverse a string? The answers would be completely different, so therefor the coding, the handling, the input, the output are all completely different.
string s = "abcde";
array a = {1, 2, 3, 4, 5};
s.reverse();
a.reverse();
reverse(s);
reverse(a);
import java.lang.string.enterprise.operations;
...
try {
StringReverseFactoryUtility lpsrfuFactory = StringReverseFactoryUtilityFactoryUtility.CreateStringReverseFactoryUtility(StringFactoryUtilities.ReverseStringFactory);
try {
StringReverser lpsrStringReverser = lpsrfu.CreateStringReverser("".getClass(), ReverseType.NormalReverse | ReverseType.IgnoreCase | ReverseType.EncodingUTF8 );
try
{
string lpszStr = "aaaa"; // set str to aaaa
string lpszReversedString = lpsrStringReverser.ReverseString(lpszStr);
assert lpszReversedString == "aaaa";
}
catch ( StringReverseException exc )
{
}
}
catch ( StringReverseFactoryGenerationException exc )
{
}
}
catch ( StringReverseFactoryUtilityFactoryGenerationException exc )
{
}
return 1;
What would you do with that reversed array you made and what would you do with that reversed string?
@cpp_is_king:
I'm not sure if you're purposely on denial or not. What would you do with that reversed array you made and what would you do with that reversed string?
Soneet said:Wow, I hope I never have to pass interviews like the OP. I had to google what this fib was and I thought 'reverse string' was some super special function (realized afterwards you just meant reversing a string..)
I'm a super fast learner and I've been called a genius several times, been hired at every place I've done work practice, but I would totally fail the OP's test. And tbh, I don't think it would be my fault. Half of my knowledge is Googling something and learning it in 5 seconds (this splits up the good from the bad, the bad just copy and hope it works) and putting it in practical use, not remembering every snippet of code I've written. I rather have team coders be able to answer "can you make this before the deadline" and simply answer yes, no or in my case "with plenty of time left".
Don't misuse the word "talent", which doesn't stand for "having a huge database in your head".
What? You were saying that I couldn't think of real life scenarios where one would do that. I only came to my conclusions after thinking of several real life scenarios one would reverse a string and one would reverse an array. Hence why I said they were nothing alike.So your beef is real world application of reversing an array or string?
But when I suggested that, you said you're not saying that.
I'm absolutely confused by what you're trying to say here.
OP is asking for web coders, then you better have some skill in creating user scenarios than being a blind puppet coder.Also, if you're asked a question during an interview, you don't ask why. You're being hired as a coder, not a business analyst.
That's kinda like asking "why"...Furthermore, going back to some of the answers given...if I were asked to reverse a string in an interview, I don't think I would give an answer that involved using an external method/library. Or, at the very least, I would ask the interviewer what kind of answer he's looking for.
What? You were saying that I couldn't think of real life scenarios where one would do that. I only came to my conclusions after thinking of several real life scenarios one would reverse a string and one would reverse an array. Hence why I said they were nothing alike.
"Just because you can't think of a real word scenario where you would need to reverse a string doesn't mean it doesn't happen."
Am I reading this wrong?
void Reverse(object[] o) {
for(int i = 0, j=o.Length-1; i < o.Length/2; i++,j-- ) {
object obj = o[i]; o[i]=o[j]; o[j]=obj;
}
}
Also, if you're asked a question during an interview, you don't ask why. You're being hired as a coder, not a business analyst.
OP is asking for web coders, then you better have some skill in creating user scenarios than being a blind puppet coder.
That's kinda like asking "why"...
Follow this advice if you do not like upward mobility in your career.
Listen, I think it's fine to ask why given the right context, but people are implying they'd refuse to answer the question because it does not have an immediate application. If you ask "why?" and the interview says "because I am testing your programming ability", you do it.
I didn't mean it as a straight black/white thing.
Okay, I'm not getting this. Several people have said they don't get what I'm saying, but I myself don't see that whenever a string would be need to be reversed, then use that reversed string (and all the coding that does this), would look the same as an array that needs to be reversed, and being used in a reversed state (and all the coding that does this). Even in cases where I do not know if my variable is a string or object, I make sure I do know so I can handle them differently. I don't see how you would come across a piece of a code that reverses an array and a string in a practical sense. By piece of code, I obviously mean whatever comes before it and after it, in a real world application, not just the function that only reverses.
Yes, but there are quite a few young budding software developers coming to this thread looking for advice and will take your statement as black/white. I'd much more encourage them to be inquisitive in their approach to problem solving situations. I do understand where you are coming from though with all of this weirdness going on about reversing arrays.
Okay, I'm not getting this. Several people have said they don't get what I'm saying, but I myself don't see that whenever a string would be need to be reversed, then use that reversed string (and all the coding that does this), would look the same as an array that needs to be reversed, and being used in a reversed state (and all the coding that does this). Even in cases where I do not know if my variable is a string or array, I make sure I do know so I can handle them differently. I don't see how you would come across a piece of a code that reverses an array and a string in a practical sense. By piece of code, I obviously mean whatever comes before it and after it, in a real world application, not just the function that only reverses.
I have a question..Are Link-List questions ever asked? Like for optimization?
You should be able to formulate basic algorithms. Reversing a string is a very basic one.OP is asking for web coders, then you better have some skill in creating user scenarios than being a blind puppet coder.
Okay, I'm not getting this. Several people have said they don't get what I'm saying, but I myself don't see that whenever a string would be need to be reversed, then use that reversed string (and all the coding that does this), would look the same as an array that needs to be reversed, and being used in a reversed state (and all the coding that does this). Even in cases where I do not know if my variable is a string or array, I make sure I do know so I can handle them differently. I don't see how you would come across a piece of a code that reverses an array and a string in a practical sense. By piece of code, I obviously mean whatever comes before it and after it, in a real world application, not just the function that only reverses.
Eh... I really was hoping not to resort to something like this... (since it's a waste of time T_T)Maybe if you explicitly wrote out the code you're thinking of...
if ($_GET['user_captcha_text']) {
$realtext = whatever::functiongetogetreversedcaptchatext();
if ($realtext == strrev($_GET['user_captcha_text'])) {
echo 'bla';
} else {
echo 'bla2';
}
} else {
die('no user captcha data');
}
$menu = array('Beef' => '2301', 'Chicken' => '2302', 'Fish' => '2401');
$reversed_menu = array_reverse($menu);
foreach ($reversed_menu as $title => $link) {
echo '<h1><a href="http://website.com/menu/'.$link.'.html">'.$title.'</a></h1>';
}
Yes, I'm partially wrong in that regard (my original statement). I'm the type of guy who would first go with his gut instinct and say "What the hell are you smoking!?" if someone says a reversed string is the same as a reversed array, as my first line of thought isn't the object heritage but rather a top-down view starting with the user.Your original statement was that reversing an array is nothing like reversing a string. Now you're saying you only have to do certain things differently when reversing an array of a different type.
Eh... I really was hoping not to resort to something like this... (since it's a waste of time T_T)
Code:if ($_GET['user_captcha_text']) { $realtext = whatever::functiongetogetreversedcaptchatext(); if ($realtext == strrev($_GET['user_captcha_text'])) { echo 'bla'; } else { echo 'bla2'; } } else { die('no user captcha data'); }
Code:$menu = array('Beef' => '2301', 'Chicken' => '2302', 'Fish' => '2401'); $reversed_menu = array_reverse($menu); foreach ($reversed_menu as $title => $link) { echo '<h1><a href="http://website.com/menu/'.$link.'.html">'.$title.'</a></h1>'; }
Just a random untested nonsense code I've written just now based on examples I mentioned earlier. Working with a string and working with arrays, I don't think I ever had written code where I would share usage with those type of objects.
Yes, I'm partially wrong in that regard (my original statement).
You should be able to formulate basic algorithms. Reversing a string is a very basic one.
You need to be able to do more than just architect the system. If you cant't think of how to actually efficiently implement the system, your design might as well come from a managers notes on what the requirements are.
Then there's nothing to argue.Soneet, it looks to me like you are focused on when reversing a string might be used versus when a reversed array might be used. I'd say that you're focusing on the wrong thing. The discussion so far seems to have been about how the logic behind reversing a string is pretty much the same as reversing an array.
I'd just like to say I don't like this way of thinking. I really don't see the use of someone saying it's the same thing, period, when the entire practical use is different. This also means you can't make an extended, advanced, customized reverse function, since string usage and array usage are completely different. Yes, I can't argue the basic function is the same thing. If you think that's the end of the story, then so be it, but I respectfully disagree.The relevant sections are only array_reverse($array) and strrev($string). The rest is just formatting and usage of input and output, which are irrelevant to the question.
In PHP, sure, they'll be different function calls. But from an algorithmic standpoint, they're the same operation.
Besides the function names, and parameter types, what is different between the two operations?
This can't be true, even for a bad student ...Reversing a string.
Do Fib recursively.
I don't think those are jerk questions.
I once had a Columbia Computer Science Master Students that couldn't reverse a string in a language of his choices.
I would iterate only through the first half of the string cause the reverse it's specular, so you switch the "opposite chars".Code:string reverseStr(string original) { string reversed; reversed = original; //Did this to initialize reversed with the same length int i = original.length() - 1; for (int j = 0; i >= 0; i--, j++) { reversed[j] = original[i]; } return reversed; }
It took me 3 seconds to find out the PHP reverse function. I mean, I know it exists, I've used it before, but I don't remember all the functions perfectly (especially if I have to deal with multiple languages). If I had to do such a type of interview, I would fail.This can't be true, even for a bad student ...
It took me 3 seconds to find out the PHP reverse function. I mean, I know it exists, I've used it before, but I don't remember all the functions perfectly (especially if I have to deal with multiple languages). If I had to do such a type of interview, I would fail.
Don't go in expecting specific questions... repeating canned answers is silly. But if you find that you don't interview well without a lot of preparation, yes, you should definitely be prepared to be grilled on data structures like linked lists, trees, and graphs in addition to algorithmic questions like the ones we've been talking about for most of this thread and the more open-ended questions about how you work.
Reversing a string.
Do Fib recursively.
I don't think those are jerk questions.
I once had a Columbia Computer Science Master Students that couldn't reverse a string in a language of his choices.
Not remembering a function name isn't a problem you can always search on internet and when you use it often enough you already remember its name.It took me 3 seconds to find out the PHP reverse function. I mean, I know it exists, I've used it before, but I don't remember all the functions perfectly (especially if I have to deal with multiple languages). If I had to do such a type of interview, I would fail.
Unless I'm 100% certain the code will work, I cannot lie and say that I could. I know what I need, like string position or how to check string length or whatnot, but without being behind a computer with internet access, I wouldn't be able to write it. And if by 'pseudo' you mean fake, then I really can't do it. My mind goes nuts trying to think of fake code. It reminds me of helping other people's coding, then I look at it, see what they try to do, but completely fail at it.I understand that plenty of programming languages these days have libraries that will handle these kinds of things, but the reason you ask a question like that is to see if that particular candidate can come up with a decent solution to a very easy problem.
If I were interviewing you and I asked:
"In pseudo-code, write me a function that can reverse the characters in a string"
You wouldn't be able to do so?
But that's kind of the problem. The OP would interview with those kind of questions. If you just happened to know there's a string reverse function, but don't recall the exact function name, then you would answer that you don't know. No one in their right mind would reverse a string manually if they know about a built-in one.Not remembering a function name isn't a problem you can always search on internet and when you use it often enough you already remember its name.
Point is that you don't really need a pre-made function to reverse a string.
It should be a basic of every programmer to know how do themselves a function like that.
Same apply for the Fibonacci recursion.
You could not know what Fibonacci numbers are but how to do a recursive function to calculate them is very simple ( basically it's the definition of the sequence itself ).
Questions like that are used to understand if you have basic programming skills, not if you know how to resolve the specific task.
Unless I'm 100% certain the code will work, I cannot lie and say that I could. I know what I need, like string position or how to check string length or whatnot, but without being behind a computer with internet access, I wouldn't be able to write it. And if by 'pseudo' you mean fake, then I really can't do it. My mind goes nuts trying to think of fake code. It reminds me of helping other people's coding, then I look at it, see what they try to do, but completely fail at it.
Unless I'm 100% certain the code will work, I cannot lie and say that I could. I know what I need, like string position or how to check string length or whatnot, but without being behind a computer with internet access, I wouldn't be able to write it. And if by 'pseudo' you mean fake, then I really can't do it. My mind goes nuts trying to think of fake code. It reminds me of helping other people's coding, then I look at it, see what they try to do, but completely fail at it.
Unless I'm 100% certain the code will work, I cannot lie and say that I could. I know what I need, like string position or how to check string length or whatnot, but without being behind a computer with internet access, I wouldn't be able to write it. And if by 'pseudo' you mean fake, then I really can't do it. My mind goes nuts trying to think of fake code. It reminds me of helping other people's coding, then I look at it, see what they try to do, but completely fail at it.
It took me 3 seconds to find out the PHP reverse function. I mean, I know it exists, I've used it before, but I don't remember all the functions perfectly (especially if I have to deal with multiple languages). If I had to do such a type of interview, I would fail.
I'm in my last year of CS, aced all projects, most of the group code comes from me (heck, other groups were even copying shit from me), but my knowledge comes mostly from work practice or at home.Are you self-taught? Pseudo-code and algorithmic thinking is literally the first thing they taught us at uni.
I've never been in an interview where I had to code on the spot. That's just weird....
...
...well, first of all, if you replied, "I'd use google to find the built-in function in PHP and just use that," you'd probably get some credit.
But more importantly, you're missing the point. The interviewer isn't expecting you to remember how to use the library function. The interviewer is asking you to perform an extremely basic array manipulation task.
If you can't reverse an array with a for loop, then yeah, you deserve to fail the interview.
I've never been in an interview where I had to code on the spot. That's just weird.
Well, I do always complain about it and how I learn close to nothing for my tuition, so that might be it. However, because of this you could say I would fail OP's interview miserably. But I'd argue that I would probably be a one of the better (or the best, which is what I always aim for) programmer if they hired me. My 1st post in this thread, I mentioned that the term 'talent' shouldn't be misunderstood. Questions like in the OP doesn't scout talent.Something is definitely wrong with your curriculum, in that case. That's not a knock against you, either.
Hell, I went to school as a Computer (Hardware) Engineer and they never taught me how to write a driver. =\
That actually sounds nice. It's the combination of a real-time verbal interview + coding on the spot (without internet) that would completely freak me out.Most software related interviews I've seen/heard about have a pre-screening test, where they'll bring a group of candidates in and have them complete a written test before making it to the verbal interview.
As an engineer, I have been asked the following questions at an interview:
- design a state machine to decode morse code on the white board (success)
- What does "static" mean in C++ (failed - could remember that it had multiple definitions but couldn't think of one)
- Ohm's Law (lol success)
- Kirkov's Current Law (success)
- What is the Fourier transform of an impulse function (success)
But at none of those two separate interviews did I actually get the fucking job. I must be a terrible interviewee.