微软笔试
时间限制:C/C++ 1秒,其他语言 2秒
空间限制:C/C++262144K,其他语言524288K
64bit IO Format:%lld
本题可使用本地IDE编码,不能使用本地已有代码,无跳出限制,
编码后请点击”保存并调试“按钮进行代码提交。
■ 题目描述
【微软笔试第二道】
题目:
1.Given S =”WRRWWR”,your function should return 2.We can move the last ball two positions to the left: ·”WRRWRW””WRRRWW”
2.Given S=”WWRWWWRWR”your function should return 4.We can move first and last red ball towards the middle one: “WWWRWWRWR”。”WWWWRWRWR””WWWWWRRWR” WWWWWRRRW’
3.Given S =”WWW”,your function should return 0.There are no red balls to arrange into a segment.
4.Given S is “RW”repeated 100,000 times,your function should return -1. The minimum needed number of swaps is greater than 109.
Write an efficient algorithm for the following assumptions
N is an integer within the range[1.200,000]
string S consists only of the characters”R” and/or “W”.
Golang
package Microsoft // you can also use imports, for example: // import "fmt" // import "os" // you can write to stdout for debugging purposes, e.g. // fmt.Println("this is a debug message") const MAX = 1e9
剩余50%内容,订阅会员后查看
此处内容需要权限查看
会员免费查看