#Code Challenge #14: July 12, 2017
Every week, we feature the type of brain-teasing question that might be asked in a full-stack developer’s job interview at places such as Google and Facebook.
This week’s challenge was reported to have been asked in interviews at Amazon:
Write a function,
getMedian, that will return the median value of a list of numbers.
Input: An unsorted
integerwhich is the median value of the input list.
getMedian([6,10,2,5,9,3,10,12,18,-3]) => 7.5(average of the middle two values)
getMedian([5,10,-3,7,9]) => 7
#####Find out more about basic challenges.
Write a function,
getX, that given an integer
xand a list returns the
Xthnumber if the list was in sorted order.
integer, x, and an unsorted
list of integers
integercorresponding to the
Xthnumber in the sorted list
getX(2, [5,10,-3,7,9]) => 5
getX(4, [5,10,-3,7,9]) => 9
- Note that this assumes the first number is position
#####Find out more about intermediate challenges.
getXso that the list is not simply sorted and then the
Xthelement picked out. It is possible to solve this problem in linear time,
Reply to this thread with a link to your code on repl.it and paste your properly formatted code to participate! Don’t just submit your code, remember to
explain your solution, too! If you want to be considered as the winner, your function
must have the
correct name and provide
output in the format specified above, you also need to abide by our other simple rules.
As always solutions using imports to do all the heavy lifting such as
itertools will not be considered for the winner.
The fine print:
Click the links to find out more about:
- the rules & how to participate in challenges
- how challenges are used as job interview questions
- why Codecademy runs challenges (and why they are formatted this way)
- more details about the challenges and why we think they are useful.
- find previous challenges (and see the past winners) in our Challenge Index