Skip to content

Prepare for successful interviews with Big Tech companies using ChatGPT

Big Tech companies like to ask questions which are not quite relevant to the actual work of a developer, like

Given a staircase with N number of steps and provided you can only climb 1 or 2 steps at a time, write a function that returns the number of unique ways to climb the staircase.
Source

Several years ago I had an “interview marathon” and I got this question 3 times. Of course, the first time I had no idea how to deal with this thing.

Even now, I don’t understand what these guys are trying to understand about a candidate when asking such “smart” questions. Perhaps it’s, how long a candidate spent reading guides like “How to succeed in Big Tech company Interview”. I don’t think it’s possible to understand anything else.

ChatGPT

ChatGPT is a large language model trained by OpenAI, its purpose is to assist with answering questions and providing information on a wide range of topics. ChatGPT is able to understand and process natural language, so it can communicate with users in a way that is similar to how humans converse with each other. It is constantly learning and improving its knowledge and ability to assist users.

I asked ChatGPT to solve the “staircase problem” for me. I’ve added a small request for an explanation:

Given a staircase with N number of steps and provided you can only climb 1 or 2 steps at a time, write a function that returns the number of unique ways to climb the staircase and explain how it works.

The answer was astonishing:


Here is a possible solution using dynamic programming:

def staircase(n):
    if n == 1:
        return 1
    if n == 2:
        return 2

    ways = [0] * n
    ways[0] = 1
    ways[1] = 2

    for i in range(2, n):
        ways[i] = ways[i-1] + ways[i-2]

    return ways[n-1]

This function uses an array ways to keep track of the number of ways to climb the staircase at each step. We initialize the first two elements of this array to 1 and 2, since there is only 1 way to climb a staircase with 1 step, and there are two ways to climb a staircase with 2 steps (you can either take 1 step twice or take 2 steps at once).

For each subsequent step, we find the number of ways to reach that step by adding the number of ways to reach the previous step and the number of ways to reach the step before that. This is because, at each step, you can either take 1 step from the previous step or 2 steps from the step before that.

For example, if the staircase has 4 steps, then the ways array would look like this:

ways: [1, 2, 3, 5]

This is because there is only 1 way to climb a staircase with 1 step, 2 ways to climb a staircase with 2 steps, 3 ways to climb a staircase with 3 steps (1+2), and 5 ways to climb a staircase with 4 steps (2+3).

The function returns the last element of the ways array, which is the number of ways to climb the staircase with n steps.


I didn’t ask for Python, and though I didn’t ask for a specific language, I totally agree with the choice. Python is the best for solving such kinds of interview problems – simple and readable.

P.S. Yes, I used ChatGPT to help me write this article (besides the highlighted answer)