{"id":140,"date":"2010-03-04T18:06:59","date_gmt":"2010-03-04T18:06:59","guid":{"rendered":"http:\/\/psyphi.net\/blog\/?p=140"},"modified":"2010-03-04T20:14:33","modified_gmt":"2010-03-04T20:14:33","slug":"an-interview-question","status":"publish","type":"post","link":"https:\/\/psyphi.net\/blog\/2010\/03\/an-interview-question\/","title":{"rendered":"An Interview Question"},"content":{"rendered":"<p>I&#8217;d like to share a basic interview question I&#8217;ve used in the past. I&#8217;ve used this in a number of different guises over the years, both at Sanger and at ONT but the (very small!) core remains the same. It still seems to be able to trip up a lot of people who sell themselves as senior developers on their CVs and demand \u00c2\u00a335k+ salaries.<\/p>\n<p>You have a list of characters.<\/p>\n<ol>\n<li>Remove duplicates<\/li>\n<\/ol>\n<p>The time taken for the interviewee to scratch their head determines whether they&#8217;re a Perl programmer, or at least think like one &#8211; this is an idomatic question in Perl. It&#8217;s a fairly standard solution to anyone who uses hashes, maps or associative arrays in any language. It&#8217;s certainly a lot harder without them.<\/p>\n<p>The answer I would expect to see would run something like this:<\/p>\n<pre><code>#########\r\n# pass in an array ref of characters, e.g.\r\n# remove_dupes([qw(a e r o i g n o s e w f e r g e r i g e o n k)]);\r\n#\r\nsub remove_dupes {\r\n  my $chars_in  = shift;\r\n  my $seen      = {};\r\n  my $chars_out = [];\r\n\r\n  for my $char (@{$chars_in}) {\r\n    if(!$seen-&gt;{$char}++) {\r\n      push @{$chars_out}, $char;\r\n    }\r\n  }\r\n\r\n  return $chars_out;\r\n}<\/code><\/pre>\n<p>Or for the more adventurous, using a string rather than an array:<\/p>\n<pre><code>#########\r\n# pass in a string of characters, e.g.\r\n# remove_dupes(q[uyavubnopwemgnisudhjopwenfbuihrpgbwogpnskbjugisjb]);\r\n#\r\nsub remove_dupes {\r\n  my $str  = shift;\r\n  my $seen = {};\r\n  $str     =~ s\/(.)\/( !$seen-&gt;{$1}++ ) ? $1 : q[]\/smegx;\r\n  return $str;\r\n}<\/code><\/pre>\n<p>The natural progression from Q1 then follows. It should be immediately obvious to the interviewee if they answered Q1 inappropriately.<\/p>\n<ol start=\"2\">\n<li>List duplicates<\/li>\n<\/ol>\n<pre><code>#########\r\n# pass in an array ref of characters, e.g.\r\n# list_dupes([qw(a e r o i g n o s e w f e r g e r i g e o n k)]);\r\n#\r\nsub list_dupes {\r\n  my $chars_in  = shift;\r\n  my $seen      = {};\r\n<del datetime=\"2010-03-04T20:12:13+00:00\">  my $chars_out = [];<\/del>\r\n\r\n  for my $char (@{$chars_in}) {\r\n    $seen-&gt;{$char}++;\r\n  }\r\n\r\n  return [ grep { $seen-&gt;{$_} &gt; 1 } keys %{$seen} ];\r\n}<\/code><\/pre>\n<p>and with a string<\/p>\n<pre><code>#########\r\n# pass in a string of characters, e.g.\r\n# list_dupes(q[uyavubnopwemgnisudhjopwenfbuihrpgbwogpnskbjugisjb]);\r\n#\r\nsub list_dupes {\r\n  my $str  = shift;\r\n  my $seen = {};\r\n  $str     =~ s\/(.)\/( $seen-&gt;{$1}++ &gt; 1) ? $1 : q[]\/smegx;\r\n  return $str;\r\n}<\/code><\/pre>\n<p>The standard follow-up is then &#8220;Given more time, what would you do to improve this?&#8221;. Well? What would <em>you<\/em> do? I know what I would do before I even started &#8211; <strong>WRITE SOME TESTS<\/strong>!<\/p>\n<p>It&#8217;s pretty safe to assume that any communicative, personable candidate who starts off writing a test on the board will probably be head and shoulders above any other.<\/p>\n<p>If I&#8217;m interviewing you tomorrow and you&#8217;re reading this now, it&#8217;s also safe to mention it. Interest in the subject and a working knowledge of the intertubes generally comes in handy for a web developer. I&#8217;m hiring you as an independent thinker!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;d like to share a basic interview question I&#8217;ve used in the past. I&#8217;ve used this in a number of different guises over the years, both at Sanger and at ONT but the (very small!) core remains the same. It still seems to be able to trip up a lot of people who sell themselves &hellip; <a href=\"https:\/\/psyphi.net\/blog\/2010\/03\/an-interview-question\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;An Interview Question&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[11],"tags":[13,227,21,229,228],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-programming","tag-code","tag-interviews","tag-perl","tag-simple","tag-tests"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":17,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/140\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}