The current selected programming language is C++. We compile the submissions of a daily working code over partially correct but efficient code. Once submitted, you cannot review this problem. You can use the 'code saved' button to debug your code. The court may fail to work in case of syntax/runtime error. The version of GCC used is C++14 (GCC 5.4).
Due to the varied geographical conditions, the temperature of Kooth county constantly fluctuates. To forecast the weather, the county's weather department decides to analyze the weather conditions over the previous N days. They collect the daily temperature of these N days and then look for the longest cycle of varying temperatures within these days. This longest cycle (or total duration) of rising and then decreasing temperatures such that the number of days of increasing temperature matches the number of days of decreasing temperature. The consecutive days' temperatures are considered for predicting the longest cycle of varying temperature.
Write an algorithm to calculate the longest cycle for varying temperatures as described above.
The first line of the input consists of an integer 'n' representing the number of days (N). The second line consists of N space-separated integers 'temp[]' representing the temperature of each day.
Print an integer representing the length of the longest cycle of the temperature of the days that are arranged according to the conditions described above.
Input: 11 1 2 3 4 5 6 5 4 3 2 1 Output: 11
Explanation: The longest cycle is 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1. The increasing portion is 1, 2, 3, 4, 5, 6. The decreasing portion is 5, 4, 3, 2, 1. Therefore, the length of the longest cycle of varying temperature is 11.
MyKaarma • Pending