Job interviewer - If you have only 1 question

Featured image

tldr; If you had only one question to judge the quality of the technical candidate for your startup, what would that question be?

This is the choice of a question of Asen who I chatted to some minutes ago.

We have two numbers - 36 and 48. Write a function which receives as an input one of these numbers, and returns the other. Important: You are not allowed to use any of these - if clauses, loops and data structures.

Here are 3 example solutions

Input

Input: 36, Output: 48.

Input: 48, Output: 36.

1. Use sum

2. Use a string

3. Use text files

Here is the logic and pseudo code for the threee solutions :arrow_down:

Use sum

two_num_sum = 36 + 48

def return_the_other_number(this_number, two_num_sum):
  return two_num_sum - this_number

Use a string

def return_the_other_number(this_number):
    this_str_number = str(this_number)
    num_string = "3648"
    
    return int(num_string.replace(this_str_number, ""))

Use text files

# 36.txt
48
def return_the_other_number(this_number):
    filename = str(this_number) + ".txt"
    
    with open(filename, "r") as fin:
        output = fin.read()

    return int(output)

Photo Credit

Unsplash/Jac Alexandru