2

Prefix Sums and How They Can be Used to Solve Coding Problems

 2 years ago
source link: https://hackernoon.com/prefix-sums-and-how-they-can-be-used-to-solve-coding-problems
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Prefix Sums and How They Can be Used to Solve Coding Problems

Prefix sums is a simple yet powerful technique that we can use to easily calculate the sum of a segment or an array. It allows us to use a reusable lookup array to look up the sum for the whole array in constant time. The first approach would have been how many times we need to recalculate different array segments. With prefix sums, our time is reduced to O(O(n + m) times we can get the sum in constant O(1) time. In this post, we will look at prefix sums and how they can be used to solve a common coding problem.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK