{"id":21003,"date":"2008-09-02T10:00:00","date_gmt":"2008-09-02T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/09\/02\/tales-from-the-interview-can-you-rotate-this-two-dimensional-array\/"},"modified":"2008-09-02T10:00:00","modified_gmt":"2008-09-02T10:00:00","slug":"tales-from-the-interview-can-you-rotate-this-two-dimensional-array","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080902-00\/?p=21003","title":{"rendered":"Tales from the interview: Can you rotate this two-dimensional array?"},"content":{"rendered":"<p>My colleague <a href=\"http:\/\/blogs.msdn.com\/jeffdav\/\"> jeffdav<\/a> told me about one job interview with a graduating college senior that didn&#8217;t go well because the candidate simply gave up.<\/p>\n<p> He offered a simple programming task: Write a function that takes a 4&times;4 two-dimensional array and <a href=\"http:\/\/geekswithblogs.net\/cwilliams\/archive\/2008\/06\/16\/122906.aspx\"> rotates it clockwise by 90&nbsp;degrees<\/a>. For example, the entry in the upper left corner of the array goes to the upper right corner. <\/p>\n<p> The interview candidate simply gave up without even writing so much as a function prototype. &#8220;I can&#8217;t do it.&#8221; <\/p>\n<p> <i>&mdash; Okay, well, let&#8217;s take it a step at a time. Maybe take a specific example and see what we can learn from it.<\/i> <\/p>\n<p> &#8220;It&#8217;s some sort of matrix multiplication.&#8221; <\/p>\n<p> <i>&mdash; All right, well how would you start working that out?<\/i> <\/p>\n<p> &#8220;I don&#8217;t know. I can&#8217;t do it.&#8221; <\/p>\n<p> That&#8217;s really not a good way to demonstrate your problem-solving skills: By responding to a problem with a simple &#8220;I can&#8217;t do it.&#8221; All of us are faced with things we can&#8217;t do. The important thing is that we are willing to learn what we need in order to be able to do them. <\/p>\n<p> I wonder if this particular person thought that attitude would fly at a real job. If your boss gives you a difficult job, would you just say, &#8220;I can&#8217;t do it&#8221;? Heck, how do you even graduate from college with that attitude? Your professor gives you an assignment, and you just say, &#8220;I can&#8217;t do it&#8221;? <\/p>\n<p> (The punch line for people who actually know matrix algebra: Matrix multiplication doesn&#8217;t solve the problem anyway.) <\/p>\n<p> <b>Bonus commentary<\/b>: I reprint JeffDav&#8217;s comment which he posted <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/09\/02\/8918130.aspx#8920138\"> below<\/a>, since it is after all his story. <\/p>\n<blockquote class=\"q\">\n<p> This was a question reserved for intern candidates and fresh out of college hires. I was usually the first one on the loop and used this as a warm-up question. Once they got it, we&#8217;d move on to something more interesting. This one guy just refused to believe it was even possible. <\/p>\n<p> Also, I would phrase it as &#8220;rotate an N x N matrix where N &gt;= 1, and you are given N along with the matrix A.&#8221; This makes it super easy. If you allow an N x M matrix (i.e. non-square) the question gets much harder. <\/p>\n<p> I don&#8217;t ask this question as often anymore. I get bored with asking the same questions over and over. Furthermore, I think after about the 100th time you ask a question you have lost perspective on it. Once you can write the answer on the whiteboard by heart without even thinking, you get annoyed by anyone who takes more than a few seconds thinking about it. It may not be a conscious annoyance but it&#8217;s there if you think about it, and I think it gives you a bit of a negative bias at times. At least it does for me. It&#8217;s good to find new questions so you have to solve them yourself and you have that feeling of approaching the problem for the first time fresh in your memory. <\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>My colleague jeffdav told me about one job interview with a graduating college senior that didn&#8217;t go well because the candidate simply gave up. He offered a simple programming task: Write a function that takes a 4&times;4 two-dimensional array and rotates it clockwise by 90&nbsp;degrees. For example, the entry in the upper left corner of [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-21003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>My colleague jeffdav told me about one job interview with a graduating college senior that didn&#8217;t go well because the candidate simply gave up. He offered a simple programming task: Write a function that takes a 4&times;4 two-dimensional array and rotates it clockwise by 90&nbsp;degrees. For example, the entry in the upper left corner of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/21003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=21003"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/21003\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=21003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=21003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=21003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}