Spaced Out?

Upasana | October 23, 2019 | 1 min read | 15 views | Python Coding Problems

Given 3 different integer numbers, determine if the difference between the smallest number and the middle number is the same as the difference between the middle number and the largest number.

The numbers can be entered in any order. If the differences are exactly the same the program should indicate the numbers are "Spaced Out" otherwise the numbers are "NOT Spaced Out".

def spaced_out(list_of_num):
    if len(list_of_num) > 3:
        list_of_num = list_of_num[:3]
        print("keeping only first three elements") (1)
    if abs(list_of_num[0]-list_of_num[1]) == abs(list_of_num[1]-list_of_num[2]): (2)
        return "Spaced Out"
        return "NOT Spaced Out"
1 In case, the input is more than three numbers then we will be considering only first three numbers as given in problem statement.
2 We are checking if the array is spaced out or not by using abs function in python
keeping only the first three elements
Spaced Out

Top articles in this category:
  1. Python coding challenges for interviews
  2. Top 100 interview questions on Data Science & Machine Learning
  3. Google Data Scientist interview questions with answers
  4. Flask Interview Questions
  5. Named Entity Recognition using spaCy and Flask
  6. Installing PySpark with Jupyter notebook on Ubuntu 18.04 LTS
  7. Imbalanced classes in classification problem in deep learning with keras

Recommended books for interview preparation:

Find more on this topic:
Buy interview books

Java & Microservices interview refresher for experienced developers.