DEV Community

vishal.codes
vishal.codes

Posted on

Day 24/366

πŸš€ Today's Learning:

🌟 DSA

Container With Most Water
Find the Factorial of a large number

🌟 Dev

useEffect and useState hooks

πŸ” Some Key Highlights:

DSA

For the "Container With Most Water" problem, you're essentially finding the maximum area between two lines on a graph, where the lines represent the heights of bars and the distance between them represents the width of the container. You start with the widest container (the two outermost bars) and calculate the area. Then, you progressively narrow down the container by moving the shorter bar inward, as moving the longer bar wouldn't increase the area. You keep track of the maximum area encountered so far and return it once all possible containers are considered.

In the "Find the Factorial of a large number" problem, you're tasked with calculating the factorial of a large number efficiently. You typically use an array to represent large numbers, with each element of the array storing a digit. Then, you perform multiplication digit by digit, carrying over the overflow to the next digit, and so on until you've multiplied the entire number. This approach allows you to handle large factorials without running into overflow issues and efficiently compute the result.

DEV

In React, the useEffect hook allows you to perform side effects in function components. These side effects can include data fetching, subscriptions, or manually changing the DOM. You provide useEffect with a function that contains the code for your side effect. This function will be executed after every render, including the first one. You can also specify dependencies as a second argument to useEffect, which determines when the effect will re-run. If the dependencies change between renders, the effect will run again. This enables you to manage side effects and keep your components in sync with external data or state changes.

On the other hand, the useState hook is used for managing state in functional components. It allows you to add state to functional components without needing to convert them to class components. You call useState with the initial state value, and it returns an array containing the current state value and a function to update that value. When you call the update function returned by useState, React will re-render the component with the new state value. This enables you to create interactive components that respond to user actions or other events by updating their state and re-rendering.

#100daysofcode #1percentplusplus #coding #dsa

Top comments (0)