Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript function, for loops, linear time complexity


function crossAdd(input) {
    var answer = [];
    for (var i = 0; i < input.length; i++) {
        var goingUp = input[i];
        var goingDown = input[input.length-1-i];
        answer.push(goingUp + goingDown);
    }
    return answer;
}
// O(N) time complexity

                    
Source by btholt.github.io #
 
PREVIOUS NEXT
Tagged: #javascript #linear #time #complexity
ADD COMMENT
Topic
Name
8+4 =