Company: Trainocate

Difficulty: medium

Problem Statement

Weather Forecasting Service Implement a weather lookup service for a set of cities. For each query, first locate the city. If it is absent, print `InvalidCityName`. Otherwise, if the query is `temperature`, validate the city's temperature. A temperature outside the inclusive range `[-10, 50]` prints `TemperatureOutOfRange`; otherwise print `The temperature for <city> is <temperature>`. If the query is `forecast`, print `InvalidForecastData` when the forecast is `-`; otherwise print `The forecast for <city> is <forecast>`. Input Format The first line contains an integer `N`, the number of city records. Each of the next `N` lines contains a city name, an integer temperature, and a forecast token. The forecast token is `-` when no forecast is available. The next line contains an integer `Q`, the number of queries. Each of the next `Q` lines contains a city name and one query type: `temperature` or `forecast`. Output Format Print one response for every query, f

More Trainocate OA questionsInterview experiences