6 kyu

Find the missing term in an Arithmetic Progression

7,031 of 22,245Coldberg

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

findMissing([1, 3, 5, 9, 11]) == 7
Kata.FindMissing(new List<int> {1, 3, 5, 9, 11}) => 7
findMissing [| 1; 3; 5; 9; 11 |] = 7
find_missing([1, 3, 5, 9, 11]) == 7
find_missing([1, 3, 5, 9, 11]) == 7
findMissing([1, 3, 5, 9, 11]) == 7
find_missing((const int[]){1,3,5,9,11}, 5)  => 7
nums:  dw  1,3,5,9,11

mov rdi, nums
mov rsi, 5
call find_missing    ; EAX <- 7
{ 1 3 5 9 11 } find-missing ! => 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!

Algorithms
Mathematics

Stats:

CreatedJan 21, 2014
PublishedJan 21, 2014
Warriors Trained54464
Total Skips10418
Total Code Submissions162206
Total Times Completed22245
JavaScript Completions5800
Haskell Completions285
Python Completions7031
C++ Completions3165
PHP Completions881
C# Completions1430
R Completions188
Swift Completions882
Objective-C Completions31
F# Completions121
Ruby Completions335
C Completions1309
NASM Completions31
Java Completions1000
Factor Completions9
Rust Completions264
Scala Completions20
Julia Completions8
Total Stars961
% of votes with a positive feedback rating90% of 2778
Total "Very Satisfied" Votes2315
Total "Somewhat Satisfied" Votes391
Total "Not Satisfied" Votes72
Ad
Contributors
  • Coldberg Avatar
  • jhoffner Avatar
  • dnolan Avatar
  • bkaes Avatar
  • Unnamed Avatar
  • deadem Avatar
  • ChristianECooper Avatar
  • ashencheetah Avatar
  • anter69 Avatar
  • donaldsebleung Avatar
  • Chrono79 Avatar
  • kazk Avatar
  • kleidemos Avatar
  • thefern Avatar
  • user4912975 Avatar
  • Blind4Basics Avatar
  • Firefly2002 Avatar
  • Voile Avatar
  • Souzooka Avatar
  • mentalplex Avatar
  • FArekkusu Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • uniapi Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • Just4FunCoder Avatar
  • razetime Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
  • Smrtypants Avatar
Ad