Find median of a circular set
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.
Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.
E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.
It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.
I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.
Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?
calculus linear-algebra
add a comment |Â
up vote
0
down vote
favorite
Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.
Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.
E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.
It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.
I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.
Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?
calculus linear-algebra
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.
Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.
E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.
It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.
I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.
Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?
calculus linear-algebra
Given a set of elements and a number $k$, each element is as a disc has a number from $0$ to $k-1$ written around its circumference. Consecutive numbers are adjacent to each other, i.e., $1$ is between $0$ and $2$, and because the discs are circular, $0$ is between $k-1$ and $1$.
Discs can rotate freely in either direction, we can only rotate one disc at a time, and it takes $1$ second to rotate it by one position) find the smallest number we should choose to make all elements equal and that number costs minimum steps.
E.g.: set = $[2,7,1]$, $k = 10$; the output should be $1$.
It takes $1$ step for the first element to reach $1$ $(2 to 1)$.
It takes $4$ steps for the second element to reach $1$ $(7 to 8 to 9 to 0 to 1)$. The third element is already at $1$.
I tried to find the median but it do not work out (or may be i find it wrong) and although sometime the steps is minimum but the number is not.
Is finding median of a circle is answer for this problem, if it is not, what should anothor approach should I consider?
calculus linear-algebra
edited Jul 24 at 13:30
Rodrigo de Azevedo
12.6k41751
12.6k41751
asked Jul 24 at 13:00
Zac Jonathan
545
545
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2861309%2ffind-median-of-a-circular-set%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password