0% found this document useful (0 votes)
11 views

Coding Interview Prep Net Eng

Uploaded by

lohithcs76
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Coding Interview Prep Net Eng

Uploaded by

lohithcs76
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Interview: Coding Exercise

This interview will assess the coding skills you’ll use every day.

Coding environment Prepare to code on Coderpad (virtual whiteboard).


Language selection We’ve hired candidates who have done their coding interview in virtually every modern programming
language, including Python, PHP, Perl, Ruby, Java, C++, Go, C#, and Haskell. Choose the one you’re most comfortable with.
What we’re looking for
As you’re coding, among the things we’re looking for is to see how you:
• Obtain an overall working solution to each problem in a reasonable amount of time.
• Ask questions and plan your solution rather than jumping right into implementation.
• Defensive coding is important, but don’t focus on details (such as error handling and corner cases) to the detriment of the
overall solution. If you’re not sure if a given error handling or edge case is important, ask the interviewer.
• If you can’t remember the order or arguments to a function or its name, just say so, leave a placeholder and move on.
Don’t get hung up on syntax.
• Explain your decisions to the interviewer and be open to feedback. It’s totally fine to present a rough solution in the
beginning and iterate as you go along.
• Be open to changing your mind if you think you’ve started your solution in the wrong way, and pay attention to whether the
interviewer is trying to guide you to a better approach.
• Resist the temptation to look things up on the internet during your interview. We’d rather have you get a function name
incorrect or the order of arguments wrong than have you looking things up during the interview.

Page 8
Additional Resources: Coding
Here is a sample coding question + solution

Climbing Stairs
Source: https://leetcode.com/problems/climbing-stairs/
You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many
distinct ways can you climb to the top?

Example 1:
Input: 2
Output: 2
Explanation: There are two ways to climb to the top
• 1 step + 1 step
• 2 steps

Example 2:
Input: 3
Output: 3
Explanation: There are 3 ways to climb to the top.
• (1) 1 step + 1 step + 1 step
• (2) 1 step + 2 step
• (3) 2 step + 1 step
Page 9
Additional Resources: Coding – cont.
Problem walkthrough

If you can climb 1 or 2 steps then you must climb to step n via step n-1 or n-2 (or both). The reason is you can’t climb 3 steps
(or more) at once.

1. Scenario #1 - assuming you are already at step n-1, there is only one option to climb to step n (climb one step).
Therefore, if there are X distinct ways to get to step n-1, and we just established there is only one option to climb to
step n, then the distinct ways to get to step n from n-1 is also X. This is idenfied in example 2 (previous slide) in way
(1) and (3).

1. Scenario #2 - assuming you are already at step (n-2), there are two options to climb to step n (climb 2 steps at once,
or climb one step and then another step). But, one of the ways (one step followed by another step) overlaps with
scenario #1 above. Therefore there is only one new distinct way not covered in scenario #1 to get to step n from step
n-2. Assuming there are Y distinct ways to get to step n-2, and we just established there is one new distinct way to
climb to step n, the new distinct ways to get to step n from n-2 is Y.

Therefore the number of distinct ways for step n are (1) the number of distinct ways from step n-1 (X) plus (2) the number of
distinct ways from step n-2 (Y) = X+Y

Page 10
Additional Resources: Coding – cont.
Bad solution

We can solve this with a recursion. We know that for n=1 there is just one distinct way.
We know that for n=2 there is also only 1 new distinct way.

The above solution is not an optimized solution, and therefore falls short of our hiring bar. Try for example running
count_steps(400) and see that it will take a while to get a response.
In particular, for every number, we will make 2 calls to count_steps, which in turn each of them would make 2 calls (4 calls
total), each of them making 2 calls (8 calls total) until n=1. This is aligned with a runtime complexity of O(2^n).
We would need to think of a way to optimize it.

Page 11
Additional Resources: Coding – cont.
Good solution #1

Good solution #2

Page 11
Additional Resources: Coding – cont.
Both approaches are good because the big O is now O(n). The space complexity for count_steps1 is worse than
count_steps2, but will be useful in case we want to run the function more than once.
You will not be asked a more complex question than the above during your interview.

Good solution #3
Candidates may observe that this is fibonacci sequence and implement their solution using the below formula (n might need
to be adjusted)
This is not a requirement to pass our bar, and solutions #1 or #2 above are more than sufficient.

Page 11

You might also like