Find the missing term in an Arithmetic Progression
Description:
An Arithmetic Progression 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.
You have to write a function that receives a list, list size will always be at least 3 numbers. The missing term will never be the first or last one.
Example
find_missing([1, 3, 5, 9, 11]) == 7
PS: This is a sample question of the facebook engineer challenge on interviewstreet. I found it quite fun to solve on paper using math, derive the algo that way. Have fun!
Similar Kata:
Stats:
Created | Jan 21, 2014 |
Published | Jan 21, 2014 |
Warriors Trained | 54464 |
Total Skips | 10418 |
Total Code Submissions | 162206 |
Total Times Completed | 22245 |
JavaScript Completions | 5800 |
Haskell Completions | 285 |
Python Completions | 7031 |
C++ Completions | 3165 |
PHP Completions | 881 |
C# Completions | 1430 |
R Completions | 188 |
Swift Completions | 882 |
Objective-C Completions | 31 |
F# Completions | 121 |
Ruby Completions | 335 |
C Completions | 1309 |
NASM Completions | 31 |
Java Completions | 1000 |
Factor Completions | 9 |
Rust Completions | 264 |
Scala Completions | 20 |
Julia Completions | 8 |
Total Stars | 961 |
% of votes with a positive feedback rating | 90% of 2778 |
Total "Very Satisfied" Votes | 2315 |
Total "Somewhat Satisfied" Votes | 391 |
Total "Not Satisfied" Votes | 72 |