Amazon Interview Question for Software Developers
- 0of 0 votes
I was asked the following question in an interview recently, which was a lot more vague and after asking clarification questions came down to this:- randomCoder May 13, 2020 in Canada
We have to perform N tests [1, 2, ... N] but in randomized order.
We have access to two functions test(x) and rand(x) which both take an integer.
test(x) returns if the current test was succesful or not and rand(x) returns a random integer
from 1<= rand(x) <= x.
The tests fail because of the sequeunce of tests carried out and we want to figure out which
sequences are bad and which sequences are good.
Basically our task is to generate a sequence of test while carrying them out and return the
sequence either when the test failed or when all tests are done.
I understand that the problem could be simplified by calling rand(N) just once, say x = rand(N) then we get the xth permuation of the seuence (1...N) and then call the test() function on this sequence reutrning only the part of sequence that finished successfully, this is deterministic and can be done in O(N) time.
Is there a better approach / solution in Python?
| Report Duplicate | Flag | PURGE
Amazon Software Developer Python
Interview Type: In-Person
Open Chat in New Window