AlgoDaily: Contiguous subarray sum
Today's AlgoDaily problem was to find whether there are contiguous subarrays (of any length) in an array that sum up to a particular target.
I wrote a quadratic solution using cumsum. You do a double for loop over the cumsum array, subtracting off the element in one index from the element in another index. This corresponds to iterating over all possible contiguous sub arrays and the method returns True if there are any matches to the target.
The code is here: https://github.com/mariakesa/Algorithms/blob/master/AlgoDaily/AlgorithmsPractice.ipynb
Kommentaarid
Postita kommentaar