added extreme case and optimized map by using integer if-else