Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Largest & Smallest Element of an Array

1 topic · 28 Nov 2026
1

Largest & Smallest Element of an Array ★★★★★

Problem Solving
Problem: Find the largest and the smallest element of an array.
Solution 1: Single loop (interview best) · C++
int arr[] = {10, 2, 4, 2, 10, 1};
int len = sizeof(arr) / sizeof(arr[0]);

int lrg = arr[0];
int small = arr[0];
for(int i = 1; i < len; i++){
    if(arr[i] > lrg) lrg = arr[i];
    if(arr[i] < small) small = arr[i];
}
cout << lrg << " " << small;   // 10 1