Skip to main content

malware-analysis

C++

#include <iostream>
#include <vector>

std::vector<int> simulate(const std::vector<int> &entries)
{
int left = 3;
int right = 4;
std::vector<int> result;

for (int i = 0; i < entries.size(); i++) {
int leftIndex = i - left;
int rightIndex = i + right;

bool leftReplace = (leftIndex < 0) ? false : entries[leftIndex] >= entries[i];
bool rightReplace = (rightIndex >= entries.size()) ? false : entries[rightIndex] >= entries[i];
bool replace = leftReplace || rightReplace;

result.push_back(replace ? 0 : entries[i]);
}

return result;
}

#ifndef RunTests
int main()
{
std::vector<int> result = simulate({1, 2, 0, 5, 0, 2, 4, 3, 3, 3});
for (int value : result)
{
std::cout << value << " ";
}
// Expected output
// 1, 0, 0, 5, 0, 0, 0, 3, 3, 0
}
#endif