注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
加拿大,在职跳槽,分数太低,分享个面经,希望对大家有帮助。
/*
--------------------------------------
Write a function that given the following information:
- Square grid of size N
- Initial starting coordinates
- A list of steps (Up, Down, Left, Right)
The function should return
- The destination coordinates by navigating the grid using the list of steps provided.
Notes
- If a step takes the current coordinate out of bounds, then reset that specific dimension to the opposite side of the grid.
- There may be *multiple* obstacles in the grid, if an obstacle is encountered, return the coordinate of the cell just before the obstacle was encountered.
- Available Steps: [U, D, U, R, R, D, L, L, L]
┌───┬─↑─┬───┬───┬───┐
│ X │ S │ X │ │ │
├───┼───┼───┼───┼───┤
│ X │ X │ X │ │ │
├───┼───┼───┼───┼───┤
│ │ │ │ │ │
├───┼───┼───┼───┼───┤
│ │ . → . → . │ │
├───┼─↑─┼───┼─↓─┼───┤
│ X │ . │ X │ D │ │
└───┴───┴───┴───┴───┘
Possible answer: [U, U, R, R, D]
Possible answer: [U, U, L, L, L, D]
--------------------------------------
|