Google 面经
1. 給你兩個string
if function(s1) == function(s2) return true
else return false. 1point3acres.com/bbs
function做的事情 遇到b 就刪除前面一個字元 其他就不管 當b太多的時候 return ""
for example
accc => accc
accb => ac
abdd => dd
. visit 1point3acres.com for more.
如果string 非常大
無法fit memory 怎麼辦
. 鐣欏鐢宠璁哄潧-涓€浜╀笁鍒嗗湴
答案:
用iterator 然後從後面開始讀
2. 给三个function
String hash(String s).
String encrypt(String message)
String decrypt(String secret)
eg.
encrypt("secret") = "12345"
decrypt("12345") = "secret"
要设计一个信息加密serve,其实是写一个class 完成这两个function
void sendMessage(String id, String message).
String getMessage(String id)
eg.
sendMessage('Bob', 'Hi')
getMessage('Bob') // 'Hi'
3. Robot Clearner
Givena robot cleaner in a room modeled as a grid. Each cell in the grid can be emptyor blocked. The robot cleaner can move forward, turn left or turn right. Whenit tries to move into a blocked cell, its bumper sensor detects the obstacleand it stays on the current cell.
Thecontrol API:
interfaceRobot {
//returns true if next cell is open and robot moves into the cell.
//returns false if next cell is obstacle and robot stays on the current cell.
booleanMove();
//Robot will stay on the same cell after calling Turn*. k indicates how
//many turns to perform.
voidTurnLeft(int k);
voidTurnRight(int k);
//Clean the current cell.
voidClean();more.
booleanMove(Direction d);
}
Sampleinput
++++++++++
+........+
+...^....+
+.+......+
++++.+++++
+.....+
+++++++
. 1point 3acres 璁哄潧
要求用给定的API打扫完所有empty格子。Timecomplexity, linear in term of room space.