Largest Element in Array Solution

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
271 B
1
Indexable
Never
#include <bits/stdc++.h> 
int largestElement(vector<int> &arr, int n) {
    // Write your code here.
    int largest = 0;

    for(int i = 1; i< n; i++){
        if(arr[i] > arr[largest]){
            largest = i;
        }
    }

    return arr[largest];
}
Leave a Comment