Back to Browse

Conquer the JavaScript Interview: Cumulative Sum [Beginner Skill Level]

348 views
Apr 26, 2023
16:56

Link to this Playlist: https://www.youtube.com/playlist?list=PLp8YCP6EV3eLnzW9Uz-P5jQtIhaYQS_5Y This is a part of my Algorithms and Data Structures playlist series. We cover a lot of common interview questions asked during whiteboards for entry level developers. Learning to master these takes time, practice, and pattern recognition. So I'll be helping you equip a toolbelt and filling it with as many tools as I can to help prepare you crush those interviews! Remember: "Luck is where practice meets opportunity." In this video we go over the cumulative sum algorithm. We declare a function called cumulativeSum that takes an array of integers, arr, as its argument. We initialize an empty array called result to store the cumulative sums. Then we initialize a variable called sum with a value of 0 to keep track of the current cumulative sum. From there, we simply Iterate through the input array, arr, using our good friend the for loop. For each element in the input array, add its value to sum, and then push the updated value of sum to the result array. Return the result array containing the cumulative sums. Nothin' to it! Even as simple as this is, remember it is a building block for more complex algorithms: The cumulative sum algorithm can be a building block for more complex algorithms and tasks, such as calculating running averages, moving averages, or other statistical measures. It can also be used as a preprocessing step for problems related to dynamic programming or data analysis. Don't forget to like this video and subscribe to our channel – we're publishing more videos and walkthroughs every week. Comment below and let us know what you'd like to see next! Join the Covalence community: https://covalence.io Shop Covalence merch: https://covalence.merchntly.com #algorithms #javascript #interview #interviewtips #cumulative

Download

1 formats

Video Formats

360pmp428.2 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Conquer the JavaScript Interview: Cumulative Sum [Beginner Skill Level] | NatokHD