44 \ December 2018 \ http://www.phparch.com
Education Station
Interview Coding Challenges
2017-2018. I was offered the job in
every case; let me share my strategies.
First, come prepared to take a coding
challenge. In my case, that means bring-
ing my laptop with me and the reading
glasses I use for computer screens.
Have a pen/pencil and paper available
for writing down Wi-Fi passwords or
whatever. I typically use an iPad for
notes, but with pencil and paper I can
leave the notes with the interviewer
and not break confidentiality concerns.
Have your laptop battery fully charged
in case you don’t have access to a power
outlet.
Rather than jumping straight to writ-
ing code, check out the environment
and testing structure. Make sure you
can run the tests. Make some change
(such as an echo 'hello world';) and
verify the change worked as expected.
In one challenge, the biggest problem
was the environment. The interviewers
had a Cloud9 environment set up so
they could watch my typing via a shared
screen. The output scrolling didn’t work
correctly—it disappeared. However, I
could see something was wrong. I knew
it wasn’t my code, because I had not
written any code yet!
I could have wasted too much time
figuring out why my code didn’t work.
Instead, I spent the majority of the
“challenge” time figuring out how to
make the environment work for me.
After that, writing the code was trivial,
and we could immediately see it worked.
In the two most recent coding chal-
lenges, the interviewers wanted me
to talk through my thought process
as I’m solving the challenge. I did ask
if it would be okay for me to check
the online documentation for specific
PHP functions; in all cases, the answer
was yes. So, relax and talk it through.
Assuming all goes well, these people
will be your team members. Let them
get to know you!
In all cases, it was crucial to have
plenty of experience using PHPUnit.
For example, in some cases, PHPUnit
“swallows up” the output. That means
print_r() and var_dump() won’t work.
What I do is throw an exception, such as
throw new \Exception(print_r($object,
true));. PHPUnit displays the excep-
tion message for you.
Get what information you can before-
hand. Ask if there is a coding challenge,
how much time it needs, will it be pure
PHP, and so on. Ask if they use a specific
environment such as HackerRank. Ask
if you should be bringing in your laptop.
Are there ways to practice for these
sorts of coding challenges? Certainly!
Here are some places to start:
- Cloud9,
https://aws.amazon.com/cloud9/—
“A cloud IDE for writing, running,
and debugging code”—get a free
account and try things out (one
of my interview challenges used
Cloud9). - HackerRank,
https://www.hackerrank.com—sign
up for a free account and gain
experience points for completing
challenges (some of my interview
challenges used HackerRank). - LeetCode, https://leetcode.com–
though they don’t appear to include
PHP, they do include Bash scripting
php[podcast]
Hosted by Eric van Johnson and John Congdon, each
episode of our new podcast compliments the theme of
each magazine issue with interviews with contributors,
thoughts from the Editor-in-chief, and more.
Available in iTunes, Google Play, and via RSS.
Listen Today