I made a google foobar call, but I did not have enough time for the next call. I am trying to understand what I did wrong.
Call
As a personal assistant to Commander Lambda, you have been assigned the task of configuring the axial orientation devices of the Lomson device. It should be pretty simple - just add gears to create the appropriate rotation ratio. But the problem is that due to the location of the LAMBCHOP and the complex system of beams and pipes supporting it, the bindings that will support the gears are locked in place.
LAMBCHOP engineers have provided you with lists identifying the placement of peg groups along various support beams. You need to put the gear on each pin (otherwise the gears will collide with the unoccupied pins). Engineers have many gears in different sizes, so you can choose gears of any size, starting with a radius of 1 inch. Your goal is to build a system in which the last gear rotates at twice the speed (in revolutions per minute or revolutions) of the first gear, regardless of direction. Each gear (except the last) touches and rotates the gear on the next peg to the right.
Given a list of different natural numbers called pegs representing the location of each peg along the support beam, write a response function (pegs) that, if there is a solution, returns a list of two positive numbers a and b, representing the numerator and denominator of the radius of the first gear in its simplest view to achieve the goal above, such that the radius = a / b. The a / b ratio should be greater than or equal to 1. Not all support configurations will necessarily be able to create the correct rotation coefficient, therefore, if the task is impossible, the response of the function (pegs) should return a list of [-1, -1].
For example, if the pins are located in [4, 30, 50], then the first gear can have a radius of 12, the second gear can have a radius of 14, and the last gear can have a radius of 6. Thus, the last gear will rotate twice as fast as the first. In this case, the bindings will be [4, 30, 50], and the answer (bindings) should return [12, 1].
The list codes will be sorted in ascending order and will contain at least 2 and no more than 20 different positive integers, all between 1 and 10000 inclusive.
Testing
Inputs: (int list) pegs = [4, 30, 50] Output: (int list) [12, 1] Inputs: (int list) pegs = [4, 17, 50] Output: (int list) [-1, -1]
My current solution is as follows
def answer(pegs): n = len(pegs) g = range(n) k = pegs[1] - pegs[0] for i in range(0,k,2): g[0] = i for j in range(1,n): g[j] = (pegs[j] - pegs[j-1]) - g[j-1] if any(b < 1 for b in g): continue if 1.0*g[0]/g[-1] == 2.0: return [g[0],1] return [-1, -1]
I could only get 6 test cases to get through. I'm running out of time now, but I'm curious what the right decision was