6 kyu

Find the missing term in an Arithmetic Progression

5,804 of 22,271Coldberg

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 Trained54520
Total Skips10424
Total Code Submissions162362
Total Times Completed22271
JavaScript Completions5804
Haskell Completions285
Python Completions7041
C++ Completions3169
PHP Completions883
C# Completions1430
R Completions188
Swift Completions884
Objective-C Completions31
F# Completions121
Ruby Completions335
C Completions1311
NASM Completions31
Java Completions1001
Factor Completions9
Rust Completions264
Scala Completions21
Julia Completions8
Total Stars962
% of votes with a positive feedback rating90% of 2780
Total "Very Satisfied" Votes2317
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