-
Notifications
You must be signed in to change notification settings - Fork 0
/
question_29.cpp
43 lines (30 loc) · 983 Bytes
/
question_29.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
==> Fighting the darkness <==
Question Link:- https://practice.geeksforgeeks.org/problems/fighting-the-darkness3949/1?page=2&difficulty[]=-1&category[]=Arrays&sortBy=submissions
Given an array arr[] of size N representing the size of candles which reduce by 1 unit each day.
The room is illuminated using the given N candles. Find the maximum number of days the room is
without darkness.
Example 1:
Input: N = 3, arr[] = {1,1,2}
Output: 2
Explanation: The candles' length reduce
by 1 in 1 day. So, at the end of day 1:
Sizes would be 0 0 1, So, at end of
day 2: Sizes would be 0 0 0. This means
the room was illuminated for 2 days.
Example 2:
Input: N = 5, arr[] = {2,3,4,2,1}
Output: 4
*/
#include <iostream>
#include <algorithm>
using namespace std;
int maxDays(int arr[],int n){
sort(arr, arr+n);
return arr[n-1];
}
int main () {
int arr[] = {2,3,4,2,1};
cout << maxDays(arr, 5);
return 0;
}