Skip to content

Algorithm Basics

An algorithm is a finite sequence of steps used to solve a problem.

function findMax(arr) {
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}

Time: O(n) Space: O(1)