← Questions

Backpropagate through sort and divide by the median

0
OpenAICodingLast asked Feb 2019

A function sorts a vector in ascending order and divides every element by the vector's median. Given the input and the upstream gradient of the output, return the gradient with respect to the input. Account for both paths: each element's own position in the sorted output, and the median, which feeds every output element. Aim for about O(n log n).

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding