Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suma de las diferencias absolutas en un array ordenado #10

Open
dpalmasan opened this issue Sep 24, 2021 · 0 comments
Open

Suma de las diferencias absolutas en un array ordenado #10

dpalmasan opened this issue Sep 24, 2021 · 0 comments
Labels

Comments

@dpalmasan
Copy link
Owner

dpalmasan commented Sep 24, 2021

Se tiene un array nums ordenado de forma no decreciente.

Construya y retorne un array de enteros de la misma longitud que nums, de tal forma que cada elemento result[i] es igual a la suma de las diferencias absolutas entre nums[i] y el resto de los elementos de nums.

En otras palabras, result[i] se calcula como sum(|nums[i]-nums[j]|) donde 0 <= j < nums.length && j != i (indexado desde 0).

Input: nums = [2,3,5]
Output: [4,3,5]

Explicación:

result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.
dpalmasan added a commit that referenced this issue Sep 25, 2021
Agregar sol a sum diferencias absolutas (#10)
dpalmasan pushed a commit that referenced this issue Sep 26, 2021
dpalmasan added a commit that referenced this issue Sep 26, 2021
Optimizar en memoria sum abs diff (#10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant