diff --git a/dsa-solutions/gfg-solutions/Easy problems/Largest-Element-In-Array.md b/dsa-solutions/gfg-solutions/Easy problems/Largest-Element-In-Array.md new file mode 100644 index 000000000..06e094ba5 --- /dev/null +++ b/dsa-solutions/gfg-solutions/Easy problems/Largest-Element-In-Array.md @@ -0,0 +1,122 @@ +--- +id: largest-element-in-array +title: Largest Element In Array +sidebar_label: Largest-Element-In-Array +tags: + - Arrays + - Data Structure +description: "This tutorial covers the solution to the Largest Element In Array problem from the GeeksforGeeks website, featuring implementations in C++." +--- +## Problem Description +Given an array `arr`, the task is to find the largest element in it. + +## Examples + +**Example 1:** + +``` +Input: arr= [1, 8, 7, 56, 90] +Output: 90 +Explanation: The largest element of given array is 90. +``` + +**Example 2:** + +``` +Input: arr = [5, 5, 5, 5] +Output: 5 +Explanation: The largest element of given array is 5. +``` + +## Your Task + +You don't need to read input anything. Your task is to complete the function `largest()` which takes the array `arr` and an size of array as `n` as input parameters and returns the largest number. + +Expected Time Complexity: O(n) + +Expected Auxiliary Space: O(1) + +## Constraints + +* `1 <= arr.size()<= 10^5` + +## Problem Explanation + +The task is to traverse the whole array and find the largest element of that array. + +## Code Implementation + +### C++ Solution + + +```cpp +class Solution +{ +public: + int largest(vector &arr, int n) + { + int maxi = INT_MIN; + for(int i=0; i