Skip to main content
changed answer from C++ to C#.
Source Link
John Deters
  • 924
  • 7
  • 12

I think it's important to go back to the context that this was an interview question.

When I interview people, I try to ask questions that don't have one "right" answer - that's more like a trivia test, which is actually fairly useless to me. Instead, I'll ask a question that requires more of an opinion response, watch the candidate, and look for them to apply logical thinking to the problem.

If you can justify that it should be a for loop, and your code is readable, good answer. If you can justify that it should be a while loop, and your code is readable, that's also a good answer. But if you say "it should be a for loop because that's the right way," that's just spewing out dogma and doesn't demonstrate independent thought. It's a less mature answer. Not that it's wrong, but if I'm trying to figure out if you're a starting programmer or an experienced engineer, it's a clue.

By the way, another really good answer is to say "In my code I'd use std::reverseReverse() on the array, because it's already tested." An employer generally does not want to pay you to reinvent the wheel, and as an interviewer I'd appreciate the depth of your experience that shows.

I think it's important to go back to the context that this was an interview question.

When I interview people, I try to ask questions that don't have one "right" answer - that's more like a trivia test, which is actually fairly useless to me. Instead, I'll ask a question that requires more of an opinion response, watch the candidate, and look for them to apply logical thinking to the problem.

If you can justify that it should be a for loop, and your code is readable, good answer. If you can justify that it should be a while loop, and your code is readable, that's also a good answer. But if you say "it should be a for loop because that's the right way," that's just spewing out dogma and doesn't demonstrate independent thought. It's a less mature answer. Not that it's wrong, but if I'm trying to figure out if you're a starting programmer or an experienced engineer, it's a clue.

By the way, another really good answer is to say "In my code I'd use std::reverse(), because it's already tested." An employer generally does not want to pay you to reinvent the wheel, and as an interviewer I'd appreciate the depth of your experience that shows.

I think it's important to go back to the context that this was an interview question.

When I interview people, I try to ask questions that don't have one "right" answer - that's more like a trivia test, which is actually fairly useless to me. Instead, I'll ask a question that requires more of an opinion response, watch the candidate, and look for them to apply logical thinking to the problem.

If you can justify that it should be a for loop, and your code is readable, good answer. If you can justify that it should be a while loop, and your code is readable, that's also a good answer. But if you say "it should be a for loop because that's the right way," that's just spewing out dogma and doesn't demonstrate independent thought. It's a less mature answer. Not that it's wrong, but if I'm trying to figure out if you're a starting programmer or an experienced engineer, it's a clue.

By the way, another really good answer is to say "In my code I'd use Reverse() on the array, because it's already tested." An employer generally does not want to pay you to reinvent the wheel, and as an interviewer I'd appreciate the depth of your experience that shows.

Source Link
John Deters
  • 924
  • 7
  • 12

I think it's important to go back to the context that this was an interview question.

When I interview people, I try to ask questions that don't have one "right" answer - that's more like a trivia test, which is actually fairly useless to me. Instead, I'll ask a question that requires more of an opinion response, watch the candidate, and look for them to apply logical thinking to the problem.

If you can justify that it should be a for loop, and your code is readable, good answer. If you can justify that it should be a while loop, and your code is readable, that's also a good answer. But if you say "it should be a for loop because that's the right way," that's just spewing out dogma and doesn't demonstrate independent thought. It's a less mature answer. Not that it's wrong, but if I'm trying to figure out if you're a starting programmer or an experienced engineer, it's a clue.

By the way, another really good answer is to say "In my code I'd use std::reverse(), because it's already tested." An employer generally does not want to pay you to reinvent the wheel, and as an interviewer I'd appreciate the depth of your experience that shows.