Microsoft Online Test for Core Technical Positions 4: Most Frequent Logs

Time Limit:10000ms
Case Time Limit:3000ms
Memory Limit:256MB

Description

In a running system, there are many logs produced within a short period of time, we’d like to know the count of the most frequent logs.

Logs are produced by a few non-empty format strings, the number of logs is N(1<=N<=20000), the maximum length of each log is 256.

Here we consider a log same with another when their edit distance (see note) is <= 5.

Also we have a) logs are all the same with each other produced by a certain format string b) format strings have edit distance  5 of each other.

Your program will be dealing with lots of logs, so please try to keep the time cost close to O(nl), where n is the number of logs, and l is the average log length.

Note edit distance is the minimum number of operations (insertdeletereplace a character) required to transform one string into the other, please refer to

http://en.wikipedia.orgwikiEdit_distance for more details.
Continue Reading…

Microsoft Online Test for Core Technical Positions 3: Reduce inversion count

Time Limit:10000ms
Case Time Limit:1000ms
Memory Limit:256MB

Description

Find a pair in an integer array that swapping them would maximally decrease the inversion count of the array. If such a pair exists, return the new inversion count; otherwise returns the original inversion count.

Definition of Inversion: Let (A[0], A[1] … A[n], n <= 50) be a sequence of n numbers. If i < j and A[i] > A[j], then the pair (i, j) is called inversion of A.

Example:
Count(Inversion({3, 1, 2})) = Count({3, 1}, {3, 2}) = 2
InversionCountOfSwap({3, 1, 2})=>
{
InversionCount({1, 3, 2}) = 1 <– swapping 1 with 3, decreases inversion count by 1
InversionCount({2, 1, 3}) = 1 <– swapping 2 with 3, decreases inversion count by 1
InversionCount({3, 2, 1}) = 3 <– swapping 1 with 2 , increases inversion count by 1
}
Continue Reading…

Microsoft Online Test for Core Technical Positions 2: K-th string

Time Limit:10000ms
Case Time Limit:1000ms
Memory Limit:256MB

Description

Consider a string set that each of them consists of {0, 1} only. All strings in the set have the same number of 0s and 1s. Write a program to find and output the K-th string according to the dictionary order. If such a string doesn’t exist, or the input is not valid, please output “Impossible”. For example, if we have two ‘0’s and two ‘1’s, we will have a set with 6 different strings, {0011, 0101, 0110, 1001, 1010, 1100}, and the 4th string is 1001.
Continue Reading…