Company: Tech Mahindra_6oct

Difficulty: medium

Problem Statement

Maximum Sales Days Problem Description A travelling salesperson operates across N towns, visiting exactly one town each day to sell products. The town picked on any given day must differ from the one picked the previous day, and no town i may be visited more than c_i times in total. Design an algorithm that determines how many days the salesperson can keep selling under these rules. Input The first line of the input consists of an integer - num , representing the number of towns (N). The next line consists of N space-separated integers - countTown_0, countTown_1, ..., countTown_N-1 , representing how many times each town may be visited. Output Print an integer giving the maximum number of days the salesperson can keep working. Constraints 1 ≤ num ≤ 5 * 10^4 1 ≤ countTown_i ≤ num ∑ countTown_i ≤ 10^5 0 ≤ i < num Examples Example 1: Input: 3 7 2 3 Output: 11 Explanation: The first, second, and third towns can be visited 7, 2, and 3 times respectively. One valid s

More Tech Mahindra_6oct OA questionsInterview experiences