Median string problem solution