big O + tweak in median and mode