diff --git a/docusaurus.config.js b/docusaurus.config.js index 3170eed21..238fb3572 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -397,6 +397,24 @@ const config = { }, ], }, + // Add a new section for the LinkedIn newsletter + { + title: "Newsletter", + items: [ + { + html: ` +
+ `, + }, + ], + }, + ], logo: { alt: "Powered by CodeHarborHub | Product Hunt", diff --git a/dsa-solutions/gfg-solutions/Easy problems/square-root.md b/dsa-solutions/gfg-solutions/Easy problems/square-root.md index 9777b7f9e..640a3c101 100644 --- a/dsa-solutions/gfg-solutions/Easy problems/square-root.md +++ b/dsa-solutions/gfg-solutions/Easy problems/square-root.md @@ -1,16 +1,11 @@ --- id: square-root title: Square Root -sidebar_label: 9 Square Root +sidebar_label: Square-Root tags: - Math - Binary Search -- Python -- Java -- C++ -- JavaScript -- TypeScript -description: "This document provides solutions to the problem of finding the square root of a given integer using various programming languages." +description: "This document provides solutions to the problem of finding the Square Root of an integer." --- ## Problem @@ -43,7 +38,7 @@ You don't need to read input or print anything. The task is to complete the func **Expected Auxiliary Space:** $O(1)$ **Constraints** -- $1 ≤ x ≤ 10^7$ +- `1 ≤ x ≤ 10^7` ## Solution @@ -190,11 +185,4 @@ class Solution { The provided solutions efficiently find the floor value of the square root of a given integer `x` using binary search. This approach ensures a time complexity of $ O(log N) and an auxiliary space complexity of $O(1)$. The algorithms are designed to handle large values of `x` up to 10^7 efficiently without relying on built-in square root functions. **Time Complexity:** $O(log N)$ -**Auxiliary Space:** $O(1)$ - ---- - -## References - -- **GeeksforGeeks Problem:** [Square root](https://www.geeksforgeeks.org/problems/square-root/0) -- **Author GeeksforGeeks Profile:** [GeeksforGeeks](https://www.geeksforgeeks.org/user/GeeksforGeeks/) \ No newline at end of file +**Auxiliary Space:** $O(1)$ \ No newline at end of file diff --git a/dsa-solutions/lc-solutions/0100-0199/0138-copy-list-with-random-pointer.md b/dsa-solutions/lc-solutions/0100-0199/0138-copy-list-with-random-pointer.md index c89d28116..af38b51f5 100644 --- a/dsa-solutions/lc-solutions/0100-0199/0138-copy-list-with-random-pointer.md +++ b/dsa-solutions/lc-solutions/0100-0199/0138-copy-list-with-random-pointer.md @@ -1,227 +1,169 @@ --- - id: copy-list-with-random-pointer -title: Copy List With Random Pointer -level: medium -sidebar_label: Copy List With Random Pointer +title: Copy List with Random Pointer +sidebar_label: 0138 Copy List with Random Pointer tags: - - Hash Table - - Linked List - Java - Python - C++ -description: "This document provides solutions for the Copy List With Random Pointer problem on LeetCode." - + - JavaScript + +description: "This is a solution to the Copy List with Random Pointer problem on LeetCode." --- ## Problem Description -A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. +A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or `null`. + +Construct a deep copy of the list. The deep copy should consist of exactly `n` brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the `next` and `random` pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list. -Construct a deep copy of the list. +For example, if there are two nodes `X` and `Y` in the original list, where `X.random --> Y`, then for the corresponding two nodes `x` and `y` in the copied list, `x.random --> y`. ### Examples **Example 1:** + + + ``` Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]] Output: [[7,null],[13,0],[11,4],[10,2],[1,0]] ``` **Example 2:** + + + ``` Input: head = [[1,1],[2,1]] Output: [[1,1],[2,1]] -``` -**Example 3:** ``` -Input: head = [[3,null],[3,0],[3,null]] -Output: [[3,null],[3,0],[3,null]] -``` - -### Constraints: - -- The number of nodes in the list is in the range [0, 1000]. -- `-10000 <= Node.val <= 10000` -- Node.random is null or is pointing to a node in the linked list. --- -## Approach to Solve the Copy List with Random Pointer Problem +## Solution for Copy List with Random Pointer -To create a deep copy of a linked list with an additional random pointer, follow these steps: -### Approach +### Understand the Problem: -1. **Create Clones Adjacent to Original Nodes:** - - Iterate through the original list and create a new node for each original node. Insert this new node right next to the original node. This way, each original node will have its clone right next to it. +Create a deep copy of a linked list where each node has a `next` and a `random` pointer. The new list should be identical in structure to the original, but with all new nodes. Ensure the `random` pointers in the new list accurately reflect the original's `random` pointer relationships. -2. **Assign Random Pointers to Cloned Nodes:** - - Iterate through the list again. For each original node, if it has a random pointer, set the random pointer of the clone node to point to the clone of the node that the original node’s random pointer is pointing to. This can be achieved because the clone of any node `A` is next to `A`. +### Approach -3. **Restore the Original List and Extract the Cloned List:** - - Iterate through the list once more to restore the original list by separating the original nodes from their clones. Extract the cloned list by linking the cloned nodes together. +1. **Interweaving Nodes**: Create and insert new nodes immediately after each original node, forming an interwoven list. +2. **Assigning Random Pointers**: Set the `random` pointers of the new nodes based on the `random` pointers of the original nodes. +3. **Separating Lists**: Restore the original list and extract the copied list by adjusting the `next` pointers of both original and new nodes. #### Code in Different Languages -### C++ -```cpp -class Node { -public: - int val; - Node* next; - Node* random; - - Node(int _val) { - val = _val; - next = NULL; - random = NULL; - } -}; - -class Solution { -public: - Node* copyRandomList(Node* head) { - if (!head) return nullptr; - - // Step 1: Create a new node for each original node and insert it next to the original node. - Node* curr = head; - while (curr) { - Node* newNode = new Node(curr->val); - newNode->next = curr->next; - curr->next = newNode; - curr = newNode->next; - } +$1 \leq n, m \leq 300$
-- $-10^9 \leq \text{matrix[i][j]} \leq 10^9$
-- All the integers in each row are sorted in ascending order.
-- All the integers in each column are sorted in ascending order.
-- $-10^9 \leq target \leq 10^9$
-
----
-
-## Solution for Search a 2D Matrix II
-
-### Intuition and Approach
-
-To search for a value in this matrix efficiently, we can utilize the properties of the matrix. Since the matrix is sorted both row-wise and column-wise, we can start our search from the top-right corner of the matrix. From here, we have two options:
-1. If the target is greater than the current value, move downwards.
-2. If the target is less than the current value, move leftwards.
-
-This approach ensures that we eliminate one row or one column in each step, leading to an efficient search.
-
-- Input: matrix = [ - [1, 4, 7, 11, 15], - [2, 5, 8, 12, 19], - [3, 6, 9, 16, 22], - [10, 13, 14, 17, 24], - [18, 21, 23, 26, 30] - ], target = 5 -
-- Output: {result ? "true" : "false"} -
-