Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Have you, as part of your day job, ever written a function solely for the purpose of swapping two numbers?


Yes, for code in languages that don't have it as a built-in library function. I've also written functions to swap strings, and implementations of various standard library functions.

Also: have you, as part of your day job, ever written code to solve a specific word puzzle? (Based on an actual interview question I've answered.) An interview question is supposed to be representative; that doesn't mean every interview question must come directly from a specific problem encountered in production code. You ask questions to prompt people and see how they think and how they communicate.


There are a couple of reasons why the 'function that swaps numbers' question is, in my opinion, a bad interview question.

1. it's a very simple thing to do, so why bother with a function? It's like asking someone to write a function that takes an integer value and returns an array of that length. 2. if you really do need a function that swaps numbers, then you probably also have some special edge cases that you will have to deal with that the candidate likely won't know about 3. each solution is language dependent

Maybe those aspects are why you consider it a good question, but when I have been asked those types of questions in the past I felt that the interviewer was missing an opportunity.


Would you consider solving an algebraic expression that was a string as a word problem - ie

  “$x * (5/25) + 10 * $y”
Of course it involved variable substitution, converting it to rpn, and then using the “Shunting Yard Algorithm”. I’ve had to do that twice. The second time I was maintaining a proprietary compiler/VM/IDE written in C++ for Windows CE. Yes, that was a dark time in my life.


(Without detracting from the fun anecdote, I think we're firmly astray from the original question or the further questions down-thread. The latter was about interview questions versus real-world problems. And no, I wasn't talking about algebraic expressions; I was talking about word games or puzzles, as given in interview questions.)


It depends on what your “world” is. If I’m being hired to write yet another software as a service CRUD app, then algorithm questions aren’t the “real world”. But, when I was being hired to do low level cross platform C without any third party libraries that we didn’t write ourselves or to maintain a compiler - algorithm type questions were appropriate.

In fact, we were writing custom document creation software and outputting to industrial printers at the first job where we were doing a lot of text processing.


Not being able to use third party libraries in no way prevents you from using third party algorithms.


I have written code that swaps numbers as part of a larger function.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: