Two CS interview questions# JobHunting - 待字闺中
c*a
1 楼
1. Given a method (public int Rand()) that returns any random integer in the
int range, write a wrapper method that returns a random number within a
specific range [min, max], assuming int.MinValue <= min <= max <= int.
MaxValue.
my solution was: min + (Rand() - int.MinValue) * (max - min + 1) / (int.
MaxValue - int.MinValue + 1), and use long type to account for overflow
issue. is this solution correct?
2. Given a M*N matrix where some cells are blocked and there may or may not
be a cell which contains a target object. A person starts from a random cell
on the matrix and moves to find the object. You are given the below helper
method:
bool MoveUp() // Returns true and the person moves up if the upside adjacent
cell is within the border and is not blocked. Otherwise, returns false and
the person stays in current cell.
bool MoveDown()
bool MoveLeft()
bool MoveRight()
bool PickUp() // Returns true if the current cell contains the object.
Otherwise, returns false.
Describe the algorithm and write down the full code of a method (bool
FindObject(IPerson p)) to determine whether there is a target object on the
matrix or not. Note that the method takes an interface parameter.
int range, write a wrapper method that returns a random number within a
specific range [min, max], assuming int.MinValue <= min <= max <= int.
MaxValue.
my solution was: min + (Rand() - int.MinValue) * (max - min + 1) / (int.
MaxValue - int.MinValue + 1), and use long type to account for overflow
issue. is this solution correct?
2. Given a M*N matrix where some cells are blocked and there may or may not
be a cell which contains a target object. A person starts from a random cell
on the matrix and moves to find the object. You are given the below helper
method:
bool MoveUp() // Returns true and the person moves up if the upside adjacent
cell is within the border and is not blocked. Otherwise, returns false and
the person stays in current cell.
bool MoveDown()
bool MoveLeft()
bool MoveRight()
bool PickUp() // Returns true if the current cell contains the object.
Otherwise, returns false.
Describe the algorithm and write down the full code of a method (bool
FindObject(IPerson p)) to determine whether there is a target object on the
matrix or not. Note that the method takes an interface parameter.