Skip to content

Instantly share code, notes, and snippets.

@chmllr
Created October 3, 2015 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmllr/df1dcfdc59577c9d9481 to your computer and use it in GitHub Desktop.
Save chmllr/df1dcfdc59577c9d9481 to your computer and use it in GitHub Desktop.
var n = readline();
var houses = readline().split(" ");
var max = -1, L = houses.length, result = new Array(n);
for (var i = L-1; i>=0; --i) {
var T = houses[i];
result[i] = T > max ? 0 : max - T + 1;
max = Math.max(T, max);
}
print(result.join(" "));
readline();
var houses = readline().split(" ");
var max = -1, L = houses.length, result = [];
for (var i = L-1; i>=0; --i) {
var T = houses[i];
result.push(T > max ? 0 : max - T + 1);
max = Math.max(T, max);
}
result.reverse();
print(result.join(" "));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment