// you’re reading...
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading...

Uncategorized

Facebook hiring sample test – Missing Term in an Arithmetic Progression

Task: Find the missing term in an Arithmetic Progression.

An Arithmetic Progression(AP) is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: Exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.

Input Format

The first line contains an Integer N, which is the number of terms which will be provided as input.
This is followed by N consecutive Integers, with a space between each pair of integers. All of these are on one line, and they are in AP (other than the point where an integer is missing).

Explanation

You are provided with 5 integers. As you can can observe, they have been picked from a series, in which the starting term is 1 and the common difference is 2. The only aberration, i.e. the missing term (7), occurs between 5 and 9. This is the missing element which you need to find.

A1 and An are included and valid.

(n+1)\frac{A_1 + A_n}{2}

Solution

Runs < 0.001 seconds in Python 2.7.
download arrowUse this link to get the Project Euler Solution Python 2.7 source.

Discussion

2 Responses to “Facebook hiring sample test – Missing Term in an Arithmetic Progression”

  1. Hi there Mike, I did a post on this topic and mentioned you and your post, I hope it’s okay with you. Here you can check it out: http://www.coffee-coding.net/ruby/facebook-programming-challenges-sample-test/

    Thanks for your post!

    Posted by Nicolás | March 19, 2014, 2:47 PM

Post a comment