Microsoft Online Assessment
Anonymous User
6406

2 hours to solve these in Codility. Apr/2022.

(1) Given a string of lowercase English, there may be occurrences of consecutive repeated letters. Remove the minimum number of letters so that there will be no occurence of 3 or more repeated consecutive letters. Ex.: For input 'xxxtxxx', output: 'xxtxx'. For input 'aaabbbccc', output 'aabbcc'. For input 'aaaaaaaaa', output 'aa'. Input length can be as long as 200,000 characters.

(2) Given a 2D matrix of size N x M. Where N and M can be at most 500. There will be an assassin (depicted as 'A') somehwere in the matrix, also there will be some obstacles represented by 'X'. Also there will be some guards.

Guards can appear the following way in the matrix: '<' represents a guard that is looking to the left, '>' represents a guard that is looking to the right, '^' looks up, and 'v' is looking down. Their line of sight extends as long as there is an obstacle, edge of the matrix or another guard.

Write a function that calculates whether the assassin can reach the bottom-right corner of the matrix. The assassin can not step in the line of sight of any guard.

Ex.:
For the input

. v .
. . .
A . .

Answer should be false.

For the input

A . . .
. < X X
. . . . 

Answer should be false.

For the input

. . . <
A . . ^
X . . .

Answer should be true.

(3) There are some platforms and there are two frogs sharing the same platform. On their left and on their right, there might be other platforms, some are higher and others as lower. The two frogs had a fight with each other and then decided to go far apart from each other as much as possible. But they can only change platforms under certain conditions: they can only go to adjacent platforms, and they can only jump to platforms that have the same height or greater height than the platform they currently are.

Write a program that finds out the furthest they can be from each other, considering they start on the platform that will make it possible for them to go the furthest apart. The distance is the difference between the platforms positions + 1.

The input is an array of integers, describing the height of the platforms. Maximum length is 100,000.

For input '[5,4,3,2,1,2,3,3,5]'

The best would be for the frogs to start at the platform of height 1, and then one frogs goes as much to the left as possible, and the other one goes to right. They'll be able to reach the ends, since the platforms in those directions are higher or equal. Then the answer is 8 (position of the frog on the right) - 0 (position of the frog on the left) + 1 = 9.

For Input '[1,2,3,4,5,6,5,4,3,2,2,3,4,5,6,7,8]'

The best would be to start at either position 10 or 11. Then one of the frogs can go to the ending right, and the other other can go to the left as far as the position 6. Answer is 17 - 6 + 1 = 12.

Comments (14)