Skip to content

Commit 98dbb64

Browse files
committed
problem description added
1 parent d8ca0ec commit 98dbb64

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Arrays/max_and_min_element.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
// Problem Description:
2+
// Here, we have an array arr[]. The array contains n integer values.
3+
// We have to find the maximum value and minimum value out of all values of the array.
4+
5+
// Let’s take an example to understand the problem
6+
7+
// Input : n = 5
8+
// a[n] = { 10, 20, 30, 40, 50}
9+
10+
// Output : Maximum element of array is 50
11+
// Minimum element of array is 10
12+
13+
// Explanation :
14+
//
15+
// There can be multiple solution for this problem.
16+
// One solution is to directly compare the elements of array. This can be done by using two different approaches :
17+
// 1.Iterative approach
18+
// 2.Recursive approach
19+
20+
// Here we are using iterative approach to solve this problem.
21+
// initially we will set a[0] as min/max. Then we iterate over each elemnts using loop and compare it with max/min element of array.
22+
23+
// Time Complexity : O(n)
24+
// Space Complexity : O(1)
25+
126
#include <iostream>
227
using namespace std;
328

@@ -39,5 +64,4 @@ int main()
3964

4065
}
4166

42-
// Time Complexity --> O(n)
4367

Arrays/max_and_min_element.exe

-47.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)