Deduce position from logic clues | MathWorks Interview Question