注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Write a BFS code for the number of islands. Discuss the complexity. What is the algorithm besides BFS and DFS implementation? Do you know how to write an algorithm using union and find?
If you have a string of 0s and 1s. 0 means no illegal characters, 1 means having illegal characters. The goal is to calculate the cost of removing all 1s. There are totally 3 functions: removeLeft() that costs 1, removeAny() meaning removing from anywhere that costs 2, removeRight() that costs 1. What’s the minimum cost of removing all the 1s? For example, 01100001, whose cost is 4. What’s the algorithm to do it?
The algorithm has 3 parts:
1. dynamic programming to get the cost from left/middle: min of 1) cost of the left neighbor of “1” plus 2; 2) the number of elements from leftmost to current position. 2.to two I32 loads. (BTW, I didn’t answer this question properly, because I didn’t know what he’s asking for initially. But this is common sense and we used this trick before at Intel as well.)
A robot dog needs to traverse rooms in 2D. There are only 3 functions: eat() is to eat all the food in the room; turn_left() is to turn left; move() is to move in a certain direction with 1 step. Write this function in C++.
求加米。 |