#Code Challenge #10: June 14, 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 Google:
###Basic Difficulty
Given an array of integers, write a function,
maxProductFinder
, that finds the largest product that can be obtained from any 3 integers in the array.
- Function Name:
maxProductFinder
- Input:
int[]
- an array of integers - Output: an
integer
– the maximum product found from any three integers in the array - Example:
maxProductFinder([-8, 6, -7, 3, 2, 1, -9]) => 432
- You may assume that the array contains at least three integers
- Please run the following array as a test:
[-6, -8, 4, 2, 5, 3, -1, 9, 10]
#####Find out more about basic challenges.
###Intermediate difficulty
Given an array of integers, write a function,
maxProductFinderK
, that can be obtained from anyk
integers in the array.
- Function Name:
maxProductFinderK
- Input:
int[]
- an array of integers and aninteger k
where k is the number of ints that can be used - Output: an
integer
– the maximum product found from anyk
integers in the array - Example:
maxProductFinderK([-8, 6, -7, 3, 2, 1, -9], 2) => 72
- You may presume that the length of the array of integers is greater or equal to
k
#####Find out more about intermediate challenges.
###Hard Difficulty
Write
maxProductFinder
andmaxProductFinderK
as efficiently as possible.
#####Find out more about hard challenges and Big O
####As always solutions using imports to do all the heavy lifting such as itertools
will not be considered for the winner.
Reply
to this thread with a link to your code on repl.it 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.
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