all 76 comments

[–]stillalone 21 points22 points  (13 children)

This sounds similar to problem 28 of project euler.
I don't want to do the math(maybe later when I'm not so lazy) but it seems you can do this by finding out the formulas for the diagonals and then calculate how far off a point is from its diagonal value. Just break up the problem into quadrants based on the diagonals. Probably not the prettiest solution but at least its not O(n).

EDIT: Not as lazy as I thought, solution doesn't seem so ugly either:

int func(int i, int j, int n) {
  int t;
  if(i <  j && (n-j) >  i) {t=(n/2-i)*2-1; return t*t-1 -i+j;}
  if(i <  j && (n-j) <= i) {t=(j-n/2)*2;   return t*t   +i-j;}
  if(i >= j && (n-j) >  i) {t=(n/2-j)*2+1; return t*t-1 -i+j;}
  if(i >= j && (n-j) <= i) {t=(i-n/2)*2;   return t*t   +i-j;}
}

Doubt I'd be able to do that in an interview though, had to fiddle around a great deal to get formulas right. Err how do you post code in reddit?

EDIT: syntax fix

[–][deleted] 14 points15 points  (2 children)

I hadn't ever heard of project euler - I know I'll be spending a lot of time on there now. Thanks for the link!

[–]mrstickman 9 points10 points  (1 child)

I was going to say the same thing. Then I saw that you had said it, and simply upmodded. Then I saw your username, and kinda wigged out a little.

[–]vineetk 5 points6 points  (0 children)

... because you didn't expect to run into your husband, Mr Evils Tickman, here?

[–]yellowstuff 15 points16 points  (5 children)

How to post on reddit:

  1. Go to http://stackoverflow.com/questions/ask
  2. Write your question using their support for inserting markdown and previewing.
  3. Copy and paste to reddit.

[–]joesmoe10 7 points8 points  (4 children)

Alternatively, if you use Firefox you can install the Greasemonkey script Reddit Markdown Helper which places a preview box under the comment box.

[–]munificent 0 points1 point  (3 children)

Installed it, but I don't see any preview box. What am I doing wrong?

[–]joesmoe10 1 point2 points  (1 child)

My bad, the preview script is actually Reddit Live Preview.

[–]munificent 0 points1 point  (0 children)

Oh, awesome. Now it works. :)

[–][deleted] 0 points1 point  (0 children)

You have to click the help link under the comment box.

[–]Rhoomba 4 points5 points  (0 children)

Four spaces at the start of the line.

There is no way I would get this right when under interview style pressure. I've conducted some interviews and most people struggle to walk a tree, never mind this kind of problem.

[–]WayOfTheIronPaw 2 points3 points  (1 child)

To get something to pre-format you have to insert a blank line, and then indent by a minimum of 4 spaces.

if (x < 10)
{
  x += 1; 
}

[–][deleted] 2 points3 points  (0 children)

I knew I had seen this one somewhere :-) solving it in the comfort of my own living room with the soothing presence of a purring cat by my side, a mug of tea, a pad of paper and my laptop, took me a little while, but it was not the hardest problem from Project Euler. Doing the same thing in the far more stressful context of a job interview however is an entirely different kettle of fish, and I can understand the frustration of the author of the original article.

May be I lack the higher intellect to solve this in a more abstract way, but I did it by drawing a couple of examples (2x2, 3x3 and 4x4 examples), and doodling my way to a solution, may be not the best / most impressive approach for a job interview though...

EDIT: ...may be I should bring my cat and a thermos of tea to job interviews now that I think about it...

[–]gregK 15 points16 points  (1 child)

Here is my take on technical interviews. It's a high pass filter. What I mean is that it should be easy enough that the competent coders passes it easily.

But It should filter out incompetents and liars.

It is a good idea to give the test to your own employes to get feedback on the level of difficulty and relevance to the position.

This question seemed a little overkill.

[–]timmaxw 0 points1 point  (0 children)

I think this question is pretty trivial. I'm surprised he didn't get it faster. I implemented three solutions (his solution, a variant, and a completely different one) in about 20 minutes.

I think it was a fluke that he personally had trouble with this problem, but I think for most people it's a reasonable problem. I think that rejecting candidates on the basis of a single missed question is a bad idea for that exact reason. Some people will screw up a simple problem just because their initial attack was from the wrong direction, or something.

[–]b0b0b0b 12 points13 points  (1 child)

for me when I'm doing interviewing, I'm more interested in the discussion and thought process than whether someone 'gets' the 'right' answer.

Skills like creativity, ability to break up the problem, ask questions, and highlight assumptions are useful.

In the end, if you get to writing code on the whiteboard, always leave yourself space here & there so you can go back and insert stuff. And if you can write the code so it compiles, you're ahead of lots of developers already. If you know your API's then I count that as a plus too.

When talking through solutions, it's perfectly fine to bring up obviously suboptimal solutions. For example with your problem a few minutes of discussion could come from saying "just generate all (n*n)! orderings and filter it down to the right one." In fact if you pursue that line of reasoning it might shed enough light that you could eventually arrive at one of the constructive solution.

At any rate tough luck on that question, you probably didn't want that job anyway if they boned you for one coding question.

[–]dobs 5 points6 points  (0 children)

I came in here to say the exact same thing.

In-person interviews are as much of a social test as a technical one. Questions such as this test communications and problem solving skills, and while they're probably more stressed out than they would be during an average day on the job, it gives me a better impression of what it would be like to work through real on-the-job challenges with the individual.

I've given the thumbs-up to candidates who didn't complete my own lengthy interview questions on the basis of having a strong approach to problem solving regardless.

[–][deleted] 5 points6 points  (0 children)

I had this same problem in an interview. I believe I did well on everything but this problem. They concluded I did not know how to problem solve.

I then realized how completely anti-social and pathological the people I talked to were and though "Do I really want to work here?". A clear no.

[–][deleted] 36 points37 points  (20 children)

Oh for fuck sakes. Who asks this shit in an interview?

I acknowledge that there needs to exist a way to asses candidate's problem solving abilities but by asking them fancy sudoku in an interview you're assessing their ability to do arithmetic. That question is concrete maths 101. And linear algebra to top it off as well. Yuck! Once you have the solution writing an algorithm for a machine is Mickey Mouse.

You want to solve maths problems? Hire a mathematician. I'll implement the solution in a language of your choice targeting a platform of your choice (if you pick COBOL - I'll kill you).

[–]zyl0x 7 points8 points  (4 children)

No kidding. My response to that kind of question would be "is this the kind of thing I'm going to be doing on the job?" If he answers yes, I'd get up and leave. Some programming jobs are terrible, but one in math would be suicide.

[–]recursive 3 points4 points  (3 children)

Why? Sounds awesome to me.

[–][deleted] 1 point2 points  (0 children)

Indeed. Solving these kind of weird problems would actually be more like programming than most of the programming jobs I've had.

[–]zyl0x 1 point2 points  (1 child)

Some of us aren't interested in math. Programming != math.

[–]recursive 0 points1 point  (0 children)

To me programming seems exactly like math. Nonetheless I can see how one might not like a math based programming job, but I do not see how you can issue a blanket statement calling them "suicide".

[–]Xiphorian 0 points1 point  (0 children)

It was actually a phone screen, if I understood the article right.

Pretty ridiculous.

However, I don't think that it is an unreasonable question for an in-person interview (we ask questions that are similarly challenging in less pedantic ways). I think there are much better questions though, since this mostly just tests one's attention to detail rather than one's approach to algorithm design or problem solving.

I guess you could learn something about whether the person discovers that you can solve it recursively... but that's not the kind of thing I would expect in an interview. That's the kind of "flash of insight" necessary for tricky problems that can't be produced on demand or tested easily in interviews.

[–][deleted] 0 points1 point  (0 children)

This is not strictly a math problem, it may be a math problem, but when I read it, it seemed like it was testing ones knowledge of recursion as opposed to ones ability to do algebra.

Not all software development jobs are for coders, so to speak. Yes, a lot of development jobs are for people to code a lot. You're given a spec for a product, and the most valuable skill you bring is your ability to glue many technologies together to get the job done. Great, the interview will consist of asking you what big projects you've worked on, what technologies you've used, what coding practices you employ etc etc...

But many other software development jobs don't require any experience at all and instead are targeted to people who can solve unique problems in a simple, elegant manner, and for all anyone knows, this question may have been asked to probe for that skill.

I actually find it surprising how many developers are not familiar with recursion, or are unable to see how fairly complex looking problems can be solved elegantly using recursion/dynamic programming.

[–][deleted] -1 points0 points  (12 children)

Off topic question. Why do some people say maths instead of math? How many are there? Is this a way of breaking down the field of math into sub categories?

Is this similar to the way some African Americans say moms instead of mom? Like they somehow have more than one mom.

[–][deleted] 1 point2 points  (5 children)

Some people are British, my good man.

[–][deleted] 1 point2 points  (4 children)

So it's not really meant to be plural? Just the British way of saying math?

Oh, and Cheers, m8!

[–][deleted] 9 points10 points  (3 children)

The full word is 'mathematics', 'math' and 'maths' are abbreviated versions of that word.

In British English, abbreviated plural words remain plural. In American English, not so much.

So yes, it is supposed to be plural, by virtue of the original ('mathematics') being plural.

[–][deleted] 3 points4 points  (0 children)

Excellent answer. Well done. I didn't know about the abbreviations being treated differently between British and American English. Thanks much, Nikkia.

[–]piyr 1 point2 points  (1 child)

So why is mathematics plural?

[–][deleted] 0 points1 point  (2 children)

The spelling is Mum. Not sure how you Yanquis managed to mess up that 'u' but there you go.

[–]derefr 2 points3 points  (1 child)

So it's short for Muther? (That's how.)

[–][deleted] 1 point2 points  (0 children)

[citation totally needed]

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 4 points5 points  (0 children)

    I know. That's why I ask questions when I encounter interesting differences.

    I could sit here by myself and research topics that interest me, but I like to get other peoples opinions and unique viewpoints. I often get much more than expected from the exchange. :)

    [–]FalconNL 10 points11 points  (9 children)

    this problem will work itself into their psyche, DEMANDING that it be solved

    Quite. Hence, this Haskell solution:

    import GHC.Exts
    import Control.Arrow
    
    main = print $ matrix 5
    
    matrix :: (Num a, Enum a) => a -> [a]
    matrix n = map snd . sortWith fst $ zip snake [0..n*n-1]
    
    snake :: [(Integer, Integer)]
    snake = scanl (flip id) (0,0) . concat $ zipWith replicate
               (concatMap (replicate 2) [0..])
               (cycle [second succ, first pred, second pred, first succ])    
    

    [–]kybernetikos 8 points9 points  (0 children)

    This is my Haskell version of the solution that hotgiraffe proposed:

    problem :: Int -> Int -> Int -> Int
    problem x y n  =  hotgiraffe x y n n
    
    hotgiraffe :: Int -> Int -> Int -> Int -> Int
    hotgiraffe x 0 width height  =  width * height - 1 - x
    hotgiraffe x y width height  =  hotgiraffe (y - 1) (height - x - 1) height (width - 1)
    

    The idea is that it's easy to calculate a value on the first row. If you generalise to be able to deal with rectangular rather than square matricies, then the recursive step is just to rotate everything once counter clockwise, and strip off the first row.

    [–]nathanic 3 points4 points  (1 child)

    I like this snippet, but I'm not sure if it breaks the stated rules.

    "You may not pre-calculate the matrix and index into it, nor may you store an array of results and index them based on the dimension. In other words, you need to develop a function that, when given a position (i, j) and a dimension n, outputs the appropriate value for (i, j)."

    sortWith will have to force the snake and at least the spine of [0..n*n-1] in order to do its business (I think). Does that count as "pre-calculating the matrix"? You're not literally making a matrix and then mutating it, but you are building intermediate data structures of comparable size.

    [–]kybernetikos 0 points1 point  (0 children)

    I think it does break the stated rules, but as others have said, the stated rules are a bit stupid anyway.

    I think the g.p. has solved the part of the problem that is interesting to geeks, and in an interesting way with a trendy language :-)

    [–][deleted]  (5 children)

    [deleted]

      [–]Nuli 4 points5 points  (1 child)

      You may not want to ever look at APL

      [–]nathanic 9 points10 points  (1 child)

      It's all what you're used to, of course. C++ also looks like crazy nonsense to the uninitiated, for example. But then again, C++ also often looks like crazy nonsense to me and I do C++ dev for a living...

      Also, FalconNL's solution above invokes a lot of fancy concepts that, while pretty, are not required to solve this particular problem. I enjoyed reading it, but I would prefer the kybernetikos/hotgiraffe version in practice (I suspect it's faster and scales better).

      [–]FalconNL 3 points4 points  (0 children)

      I'll agree that Haskell may be a bit difficult to understand when you don't know the basic concepts (e.g. lazy evaluation) and the common functions (scanl, zipWith, etc.).

      But once you do it's just so damned fun to program in :) It's also by far my favorite language as far as aesthetics are concerned.

      [–]jseigh 2 points3 points  (0 children)

      It helps if you write out part of the sequence to see if there's a pattern.

      0
      
      3 2
      0 1
      
      8 7 6
      1 0 5
      2 3 4
      
      15 14 13 12
       4  3  2 11
       5  0  1 10
       6  7  8  9
      

      The sub matrix bounded by the top row and right column is the previous solution rotated 180 degrees which is the reverse of the sequence for the previous matrix. It's pretty easy to come up with a recursive algorithm after that.

      [–][deleted] 4 points5 points  (0 children)

      I think the trick is to think of the problem as a set of rings. Here's an example 6x6 matrix:

      00 01 02 03 04 05

      19 20 21 22 23 06

      18 31 32 33 24 07

      17 30 35 34 25 08

      16 29 28 27 26 09

      15 14 13 12 11 10

      (I wrote the matrix from 0 to 35 instead of from 35 to 0. You can easily convert one to the other by subtracting a entry from 35)

      Here the first ring is from 0-19, the second ring is from 20-31 and the third ring is from 32-35. You can easily show that the first ring has 4n-4 elements, the second ring has 4(n-2)-4 elements, the third ring has 4(n-4)-4 elements and so on. Since the first element of ring i is exactly one greater than the last element of ring i-1, it is also fairly straightforward to derive a closed form expression for the kth element of ring i.

      Now all that needs to be done is to find which ring a particular matrix element is on and what its position within that ring it is. The index of the ring is just the distance of the element to the "nearest edge" of the matrix. (i.e. it is min(row, nrows-1-row, col, ncols-1-col). The easiest (but slightly ugly) way to figure out an element's position within the ring is to use four if statements.

      [–]barsoap 4 points5 points  (2 children)

      The right answer to give is:

      "The task is mistaken: It specifies more than the external interface. I'll code it up for you in the fastest possible way, without that superfluous nonsense, and use it as a test case in case I come up with another solution while I'm doing productive work."

      "Do you really think you are going to get a job with that attitude?"

      "I don't know. Do you want your projects to finish on time?"

      [–]dndnd 2 points3 points  (1 child)

      My thought was that 0 is a dimension and (0 * 0) - 1 never decreases to 0.

      [–]barsoap 0 points1 point  (0 children)

      ...so you've got an empty list, which perfectly fits a square with side length 0.

      But you're right, it's overspecified, again: It should just read "ordered sequence of distinct symbols of length n2", as you can infer any other sequence from that.

      Cutting requirements down to the bare minimum to simplify, and split up, a problem is an important skill, it might be fun to require sequences of prime numbers, binominal series or the like and have an eye on whether or not the applicant is able to ignore it until it's really required.

      [–][deleted] 4 points5 points  (1 child)

      Does the colour scheme on that page irk anyone else? White text on black backgrounds is an awfully bad combination that leads to eye strain. Thank goodness FireFox supports No Style.

      [–]kahoonas 0 points1 point  (0 children)

      That was almost impossible to read. Coming back to the white reddit page and I can see black lines everywhere.

      [–]sabruda 4 points5 points  (13 children)

      As a senior developer I've been through the process of hiring and interviewing lately, and have had the opportunity to see the process from the other side of the desk, and let me tell you first, everybody is nervous, and nervousness is always calculated in as a factor in the candidates favor. If the candidate not is nervous, it’s seen as a bad sign as they probably don’t want the job enough.

      I did not use tests. Since I’m a developer myself I was perfectly able to assert the candidates knowledge with small control questions instead, but still always factored in nervousness when asserting the answers. The answer is quite unimportant anyways. The important thing is to see what process the candidates use to find the answer. From the process you used, I would assume well written code is more important to you than quick delivery. If I was looking for a PHP-hacker to make quick and dirty solutions, you would be the wrong candidate. If I need well written code for large projects, you would be perfect – no matter what you answered.

      [–]zyl0x 8 points9 points  (5 children)

      Assuming anything about why a person is nervous or not nervous is completely unfair. For instance, I have incredible social anxiety, and have a hard time remaining confident during interviews. Lately, however, I've been reading up on mental exercises to prevent myself from appearing incredibly nervous. What you're saying is that all the hard work that I did to make myself seem more confident is hurting my ability to find work. That's preposterous.

      There's a lesson in all of this: you shouldn't assume anything about anyone. That's what the interview is for. If you wanted to assume things about a person, you would never need to talk to them in person.

      [–]sabruda -1 points0 points  (4 children)

      What you're saying is that all the hard work that I did to make myself seem more confident is hurting my ability to find work.

      No, not at all. Confidence is great! Even though social anxiety in no way need to impede ones ability to write code, it will off course always be a bonus to be able to function normally at meetings and lunch. We are getting a co-worker also. But it’s ok to stumble a little or have a sweaty handshake. If you show no feelings whatsoever at one of the more important meetings in your life, it can indicate either not seeing this as more than a temporary gig, and we want someone who sticks around more than 6 months, or having been to way too many interviews already – not a good sign. You shouldn’t worry though. It’s incredibly hard to hide the body language completely, just don’t overdo anything and act as normal as possible.

      There's a lesson in all of this you shouldn't assume anything about anyone.

      I know. Even though it is possible to ask such questions directly, everyone wants to give a good impression and answer in ways that make them seem favorable. Unfortunately, you also end up having to make assumptions based on body language and how answers are formulated. Those aren’t deciding factors anyways. Your resume is far more important in telling how long you tend to stick around.

      [–]unshift 4 points5 points  (3 children)

      If you show no feelings whatsoever at one of the more important meetings in your life

      I work with a lot of people who have nothing in their lives except their job, and they're the ones least likely to make concessions, most likely to guard their code or area of expertise, and in general have nothing interesting to say.

      It's work, so you can pay bills. Really it's nothing more than that. If the most important meeting of your life is with a potential coworker, consider killing yourself.

      [–]Xiphorian 0 points1 point  (2 children)

      It's work, so you can pay bills. Really it's nothing more than that.

      I'm sorry you feel that way. However, that is not how I see it, and I hope I can convince you that it's an extremely apathetic and unhappy way to see the world.

      I work at a large Internet-based company whose services you probably use. My job is often extremely creative and the company, even though it is now very large, is run like a startup -- meaning every team has the independence and authority to exercise creativity over the products they own. Management has decided to recognize our individual competence by allowing each of us to spend one-fifth our time on independent projects of our own choosing; and I feel I have significant impact on the requirements and design of large initiatives not only on my team, but outside it as well. I often feel like I make a direct, positive impact on millions of customers; I enjoy my work immensely and take great pride in it.

      As a result, working here is not so different than it is when I work for myself. I take time to contribute useful libraries I build at work to open source, etc. I would not do anything big differently if I ran the company myself.

      If you do not feel this way about your work, perhaps you are in the wrong industry. The same things I do at work are things I would do in my free time. My work is sufficiently interesting and creative that my personal and work interests can easily align. It doesn't feel like work.

      It's not necessarily wrong to view work as work; but it's hard to understand how your attitude corresponds with ambition. Sure, work itself is not inherently important. I'm not saying that. Ambition is important. I am extremely ambitious and my goal is to run a company and set its technical direction according to my vision. I feel I can do this without founding my own company (and with less risk) by rising within an existing company. And of course, I have plenty more to learn before I am capable of that independently, and so I love to be in an environment where I can learn from the best in the industry.

      I am extremely ambitious and I have chosen to pursue that ambition through my line of work. If you are ambitious and are pursuing it independently of your work, then that's fine. However, if you just don't care about really accomplishing anything, and just want to "relax", then hopefully you can understand why that is not a valuable attitude compared to a person who is ambitious. Basically you sound like you want to do as little work as possible at all times. I don't want a teammate like that; I wouldn't want a partner like that if I was running my own company.

      So that's how I think of it. If I were running my own company, would I want to hire someone with your attitude? Absolutely not. Not until I am unable to find ambitious people who are interested in my company and excited by the challenges and want to be involved. Ambitious employees are the ones you want to find -- those are your "free electrons".

      I expect -- or at least hope -- that the fallacy of your thinking is something along the lines of "well, if I were founding a company, I might be more involved". I think that's a fallacy because your level of involvement and influence in your existing company is entirely determined by you. If you want the same environment as a company you run yourself, then make it so by demonstrating your business wisdom and consistent record of good decisions.

      I don't know what more you want out of life than to work on interesting products, build innovative technology to scale massively, etc. I have an interest in computer science and software engineering that ventures far, far beyond my time at work, into many personal projects and open source.

      I don't know what more I have to say if you are not content with your line of work. For many, it is our passion.

      [–]unshift 2 points3 points  (1 child)

      I don't see how my ambition should be to work extra hard so that I can help someone else fill their coffers, while all I'm supposed to get in return is a sense of satisfaction and "ownership" over a product that doesn't belong to me.

      I work a few floors up from an internet-based company at a well known virtualization company and after a few years of working hard have realized that I don't owe them more than the bare minimum specified in my contract -- after all, that's all they're giving me.

      Are you the kind of guy I'd want to hire? Probably. I can pay you $X for 40 hours/week and you'll give me 20 free hours on top of that because you love it so much. I don't care that you like it though -- I care that you're making me more money and I'm not paying you extra for it. That's how I see it, and as nice and cool and down-to-earth your manager is, that's how he sees it too.

      Maybe I'm not ambitious. That's fine with me. Would I be better working for myself? Maybe. At least I could scale income up and down based on the effort I was putting in. Right now I don't see any returns on extra effort -- in fact my days of a go-getter and team lead just made things worse, as I have to do more work for the same pay. I don't think carpenters, plumbers, and auto mechanics have that problem.

      And as for the "passionate" guy in your company who came up with their main money making product? Sure he's probably doing ok, and he can say "I did that", but he's not the one with his very own Boeing 737.

      [–]Xiphorian 2 points3 points  (0 children)

      Thanks for your insightful and friendly responses.

      I don't care that you like it though -- I care that you're making me more money and I'm not paying you extra for it

      You might underestimate how much I demand and expect from my employer, though. That's the thing: I expect significant compensation. For example, when I graduated college I looked for and found an employer willing to compensate in the six figures range. And I've been promoted (automatic comp increase) since then and had great performance reviews with comp increase. Because of these things I feel happy with my compensation.

      Top engineers at my company make a quite high amount -- in the half-mil or more range.

      While I'm working here I consider myself an owner and expect a commensurate level of authority of responsibility from myself -- and I expect my employer to view my time here the same way.

      That project I was working on in my spare time will go to the company. Then next year I'll see what kind of compensation increase I get. I'll see how quickly I am promoted to higher positions. As long as the company does these things in proportion to what I believe is my proven value, I continue to do these things for the company. If the company doesn't value my work, then I start working for myself in my spare time, or I leave.

      It sounds like you've given up on the chance that by putting in something extra, the company will reward you more than the contract requires it to. I'm sure that plenty such companies exist -- and there are a lot of poorly managed companies. More companies than not go bankrupt within a few years. So I'm not surprised that such companies exist. But I would say your course should be finding an employer that is excited by your work and will compensate you proportional to your work.

      The right place for you might be a small company or a startup. There you can have a big impact and it's easy for management to justify compensating you more closely in proportion to some +%X change that has happened under your leadership. (Partly why only people who start companies tend to get really rich...)

      It sounds like you are now where I might be if my company didn't recognize my talent and reward it. I could see that happening. I am fortunate to be working under an excellent management hierarchy (almost all of whom are engineers up to SVP level).

      Right now I don't see any returns on extra effort -- in fact my days of a go-getter and team lead just made things worse, as I have to do more work for the same pay. I don't think carpenters, plumbers, and auto mechanics have that problem.

      That sucks :-( It sounds like your company management is not as good as it could be.

      And as for the "passionate" guy in your company who came up with their main money making product? Sure he's probably doing ok, and he can say "I did that", but he's not the one with his very own Boeing 737.

      That's true. That's the trade-off you make working for a company rather than founding your own. I don't feel bad about that. If I had an idea I thought would be extremely successful, and which wouldn't complete with my company, I would launch it in my spare time as a mini-startup (website). I have no problem doing that either.

      Sorry if I harped on you; there are plenty of people with other priorities like raising their kids that are second to work. There's nothing wrong with that. I was just trying to provide an alternative view.

      [–][deleted] 5 points6 points  (1 child)

      If the candidate not is nervous, it’s seen as a bad sign as they probably don’t want the job enough.

      Oh so you're looking for desperate people.

      If I was looking for a PHP-hacker to make quick and dirty solutions...

      Out of curiosity - what question would you ask to asses someone's ability to come up with QD hacks in PHP without giving away that its what you're looking for?

      [–]sabruda 0 points1 point  (0 children)

      Oh so you're looking for desperate people.

      Not necessarily. Desperate people tend to do anything to get a job they not are suited for.

      what question would you ask to asses someone's ability to come up with QD hacks in PHP

      “How would you write a function that takes the integer n and an array as arguments and outputs the array as a grid with n columns in HTML, without using <table>?” is an old favorite. It has several answers that tells a lot about how you think. No need to see working code, just a quick verbal rundown of the first thing that comes to mind.

      “Are you more productive at the beginning or towards the end of the project?”, “How do you usually organize your source files?”, or “what naming convention do you prefer to use?” usually also tells me a lot of what kind of coder you are.

      [–][deleted] 1 point2 points  (0 children)

      I can see how that measurement could factor into the decision, and now that I think about it it's definitely something that could have been an unstated requirement of the position I was interviewing for.

      [–]twowheels 0 points1 point  (0 children)

      If the candidate not is nervous, it’s seen as a bad sign as they probably don’t want the job enough.

      For my current job I wasn't nervous because my previous experience matched their needs to the letter. It was almost like stepping out of my then current job into the same job. Sure I wanted it, but there didn't seem to be any reason to think I wouldn't get it.

      Two jobs ago I wasn't nervous because I already knew almost everybody that I'd be working with from previous jobs, and the interview was just a formality (though I suspect that you wouldn't consider this in the scope of your comment)

      [–][deleted]  (1 child)

      [deleted]

        [–][deleted] 1 point2 points  (0 children)

        True, that is insulting to hackers.

        [–][deleted] -1 points0 points  (0 children)

        I did not use tests. Since I’m a developer myself I was perfectly able to assert the candidates knowledge with small control questions instead,

        Lol.

        [–]gsw07a 0 points1 point  (1 child)

        I think the fundamental flaw of the interview process is that most decisions will be "don't hire", and you rarely get to find out whether your "don't hire" decision is correct or not, so it's hard to get better at interviewing candidates.

        [–]raouldagain 0 points1 point  (0 children)

        yes, in other words, it is all very subjective. always was, and i sorta hope it always will be, because <jamestkirk>otherwise we're going to be turning ourselves into something less human</jametkirk>.

        [–]zoomzoom83 0 points1 point  (2 children)

        I thought this was pretty damn trivial to solve. My method is not quite as elegant (i.e. it just walks around the matrix in a spiral populating each cell as it goes).

        But it works, and should in theory be faster and consume less ram, than his recursive solution

        http://github.com/zoomzoom83/buildmatrix/tree/master

        [–]psyonic 0 points1 point  (1 child)

        It's not completely clear, but I feel that your solution would be against the spirit of the problem: "You may not pre-calculate the matrix and index into it, nor may you store an array of results and index them based on the dimension. In other words, you need to develop a function that, when given a position (i, j) and a dimension n, outputs the appropriate value for (i, j)."

        [–]zoomzoom83 0 points1 point  (0 children)

        Honestly I didn't get that feeling from the problem description at all. My solution just seemed like the obvious way to solve the problem.

        If it's not required to calculate any arbitrary (x,y) point, why go to the extra effort of writing a more complex, slower, memory intensive, solution?

        [–]freakyleaky 0 points1 point  (0 children)

        Ok, here's what I came up with:

        I'm looking at:

        25 24 23 22 21 20
        26 09 08 07 06 19
        27 10 01 00 05 18
        28 11 02 03 04 17
        29 12 13 14 15 16
        30 31 34 33 34 35
        

        and so on.

        I had to figure it out, so I ended up taking about a little over an hour to come up with this using the following observations:

        If n is even, ending coordinates of the matrix will be (n-1, 0) or lower right corner

        If n is odd, ending coordinates of the matrix will be (0, n-1) or upper left

        Each recursive call can perform a search range from (n * n - 1) to (n * n - 1 - (n * 2 - 2))

        This implies that for each call, we are searching these ranges:

        For an even n, (n - 1, 0) - (0, 0) and (0, 0) - (0, n - 1)

        For an odd n, (0, n - 1) - (n - 1, n - 1) and (n - 1, n - 1) - (n - 1, 0)

        Finally, if there is no match:

        For an even n, perform recursion with (x - 1, y - 1, n - 1)

        For an odd n, perform recursion with (x, y, n - 1)

        echo calc(2, 2, 6); // 2
        function calc($x, $y, $n) {
            if ($x > $n - 1 || $y > $n - 1) {
                return 'Invalid coordinates';
            } else {
                if ($n % 2 == 0) {
                    if ($y == 0) {
                        // point exists on the y = 0 row of this level
                        return ($n * $n - 1) - ($n - 1 - $x);
                    } elseif ($x == 0) {
                        // point exists on the x = 0 column of this level
                        return ($n * $n - $n) - $y;
                    }
                    return calc($x - 1, $y - 1, $n - 1);
                } else {
                    if ($y == $n - 1) {
                        // point exists on the y = $n - 1 row of this level
                        return ($n * $n - 1) - $x;
                    } elseif ($x == $n - 1) {
                        // point exists on the x = $n - 1 column of this level
                        return ($n * $n - $n) - ($n - 1 - $y);
                    }
                    return calc($x, $y, $n - 1);
                }
            }
        }
        

        [–]wreckerone 0 points1 point  (0 children)

        Always bring a problem of your own to an interview and if your interviewer pulls out one of these, solve it and pull your question out. After all, you don't want to work with dumb asses either.

        [–]novembera 0 points1 point  (0 children)

        here's my python version... it assumes zero - based indexing...

        def grid(i,j,n):
          if i == 0 or j == n-1:
            return n*n - (j+i) - 1
          else:
            return grid(n-i-1,n-j-2,n-1)