DEV Community

Posted on

Day 20/366

🚀 Today's Learning:


  • Find the middle of a linked list
  • Delete last occurrence of an item in a linked list

🌟 Dev

  • JSX in react

🔍 Some Key Highlights:


To find the middle of a linked list, you start by having two pointers, one slow and one fast, both initially pointing to the head of the list. While advancing through the list, the slow pointer moves one step at a time, while the fast pointer moves two steps at a time. When the fast pointer reaches the end of the list or null, the slow pointer will be at the middle node. This works because the fast pointer covers twice the distance in the same time as the slow pointer, effectively splitting the list into two halves, with the slow pointer at the midpoint.

To delete the last occurrence of an item from a linked list, you traverse the list while keeping track of the last occurrence of the target item and its previous node. If the target item is found again later in the list, you update the pointers to keep track of the last occurrence. Once the end of the list is reached, if the target item has been found at least once, you delete the node corresponding to the last occurrence by updating the previous node's pointer to skip the last occurrence node, effectively removing it from the list.


JSX in React is a syntax extension that allows you to write HTML-like code directly in your JavaScript files. It provides a more readable and intuitive way to create UI components. JSX gets transpiled into regular JavaScript by tools like Babel before being executed by the browser. JSX elements resemble HTML elements but are actually JavaScript objects representing React components. This allows you to seamlessly mix JavaScript logic and HTML-like syntax, making it easier to build and maintain complex UIs in React applications.

#100daysofcode #1percentplusplus #coding #dsa

Top comments (0)