"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Importance of Data Structures

Importance of Data Structures

Posted on 2025-02-06
Browse:176

Importance of Data Structures

Hi, Folks! Today, I solved three problem on LeetCode : Valid Parentheses, Asteroid collision, and Trapping rain water. All these problems can be solved efficiently using data structures and well thought logics. attempting to solve these problems without data structures implementing any other logic can make them more challenging.

We can assign bracket pairs in the object and use stack data structure to pop the element that no longer required. if required, push the element into stack. In this way we can solve valid parentheses problem.

Similarly, To solve the asteroid collision problem, we can use stack. Depending on positive and negative values, we can pop elements from the stack. In this way we can solve asteroid collision problem.

To solve trapping rain water problem, we need to traverse array from left to right while keeping track of left maximum and right maximum values on left side and right side. Create one variable to keep track of trapped water. As we traverse, we add the trapped water based on left and right values. In this way we can solve trapping rain water problem.

I hope my experience will be helpful to you.

Release Statement This article is reprinted at: https://dev.to/karthika_movva/importance-of-data-structures-20ca?1 If there is any infringement, please contact [email protected] to delete it.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3