finished implementation of Median problem