DEV Community

Somuya Khandelwal
Somuya Khandelwal

Posted on • Edited on

DAY 53 Sliding Window Meets Prefix Sum: Elevating Problem Solving

Hello Everyone!

On the third day of the Week 11, learners were exposed to some of the Sliding Window and Prefix Sum strategies, which are useful for handling most array problems. Today’s activities involved totalizing and using the totals that accrue in ongoing processes to support decision making. At times it was like maneuvering in a process environment pushing for continuous improvement.


How the Day Unfolded

  1. Highest Altitude Exercise (Easy Level)

    – Improve mathematical skills and determine the maximum height attained during a trip depending on an array of gain values.

    • The Strategy: Used one more technique called a prefix sum technique in order to maintain the cumulative altitude at each step of the algorithm. Kept a running minimum to find out the lowest altitude.
    • The Fun Part: It was as if it were possible to watch the altitude change and increase or decrease dynamically as each gain value changed.
  2. Pivot Index (Easy Difficulty)

    Identify the index of rotation for an array in which the left side of the array adds up to the same number as the right side of the array.

    • The Strategy: Found the total sum of the array by iterating through it and stored the left sum just keeping track with it. For every index, checked whether left sum is equal to total sum – total sum’s current component and left sum.
    • The Fun Part: It was a somewhat challenging endeavor to seek finding the equilibrium point as it is much like level the seesaw: there is satisfaction in seeing that a concrete logic has been applied.

Part IV: What Made Today Special

  1. Prefix Sum Power:

    Both problems was demonstrating the efficiency of the prefix sums for computation of cumulative values for efficient further usage.

  2. Optimization Through Clarity:

    I noticed that tasks such as Find Pivot Index aimed to make students aware of the fact that the problems were separable into logical and beautiful sub-problems.

  3. Visualizing Dynamics:

    Altering altitude or finding out the equilibrium points made the problems look natural and fun, brought in additional perspective.


Key Takeaways

  • Prefix Sum Simplifies Calculations:

    For instance, in the Find the Highest Altitude problem, it becomes clear why using prefix sums lowers the amount of necessary nested iterations.

  • Iterative Problem-Solving Works:

    Find Pivot Index demonstrated that even though some repetitive calculations and thus recursion are needed, prefix sums make the selection of significant indices efficient.

  • Dynamic Updates Matter:

    It stays accurate to continuously keep running totals in which solutions are efficient and clear as seen from the two tasks.


Reflections

The Find the Highest Altitude problem was easy to consider from the point of view of data analysis but still brought some joy from solving once you notice that it can be solved with prefix sums The Find Pivot Index problem required additional efforts due to the equilibrium condition. Combined, they explained how the progress of respective array issues relied on the conceptions of carrying data increments and partitioning tasks as comprehensible sub-problems.


What’s Next?

The breakdown of problems for the following day is as follows: Hash Map/Set Problems:Find the Difference of Two Arrays, Unique Number of Occurrences. These tasks will build up my application of hash-based structures as well as how to manage data in an efficient manner.

End of part one! I hope that you enjoyed following along with me! So let’s continue on with solving, learning and development as one programmers community.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay