Your company is analyzing malware which targets numerical record files.
The malware uses a sliding window over the array of numbers in a file, and tries to match the following pattern:
T, -, -, X, -, -, -, T
Where the position ‘X' is compared to each position 'T'. The window is moved so 'X’ passes through all the values.
The malware has the following rules:
- If any of the ‘T' positions in the pattern are bigger or equal to 'X’ the malware replaces 'X' with 0.
- If the 'X' position in the pattern is near the left or right border and is missing a 'T' position neighbor, only the other side is considered.
- The malware finds all the positions first and only then sets them to 0.
For example, if the values in a record file are the following:
[1, 2, 0, 5, 0, 2, 4, 3, 3, 3]
The expected values after the malware runs are:
[1, 0, 0, 5, 0, 0, 0, 3, 3, 0]
In this example, number 4 was set to 0 because 5 is the bigger number.
Implement the simulate function so that the malware behavior is replicated for further study.
Duration: 20 min
Author: Christian Durán Carvajal
Would you like to see our other questions?
We have 1000+ premium hand-crafted questions for 160+ job skills and 20+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.
On the blog
Since we're all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they've been screening people for many years, so they must know how to do it right?
Not really. I was surprised to discover that many experts...