🚀 Day 73 of #100DaysOfCode Today, I solved LeetCode 1319 – Number of Operations to Make Network Connected, a problem that focuses on graph connectivity and components. 💡 Problem Overview: Given n computers and a list of connections, the task is to determine the minimum number of operations required to connect all computers into a single network. 🧠 Approach: ✔️ Modeled the network as a graph ✔️ Used DFS/BFS to count the number of connected components ✔️ Calculated extra (redundant) connections ✔️ If enough extra cables exist, used them to connect all components ⚡ Key Takeaways: Graph problems often reduce to counting connected components Extra edges can be reused to connect disconnected parts DFS/BFS are fundamental for connectivity problems 📊 Complexity Analysis: Time Complexity: O(V + E) Space Complexity: O(V) Strengthening graph fundamentals step by step 🚀 #LeetCode #100DaysOfCode #DSA #Graphs #DFS #BFS #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
LeetCode 1319 - Minimum Operations to Connect Computers
More Relevant Posts
-
Day 178/365 – DSA Challenge ⚡ Solved Single Number II on LeetCode today. 🔹 Problem: Every element appears three times except one → find that single number. 🔹 Approach Used: Bit Manipulation Steps followed: 1️⃣ Maintain two variables: ones and twos 2️⃣ ones stores bits appearing once 3️⃣ twos stores bits appearing twice 4️⃣ When a bit appears third time → it gets removed from both 🔹 Core Logic: ones = (ones ^ num) & ~twos twos = (twos ^ num) & ~ones 🔹 Key Idea: Track bit frequencies using bitwise states instead of extra space. 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) 💻 Language: C++ Powerful example of how bit manipulation can replace counting arrays 🔥 #Day178 #365DaysOfCode #DSA #LeetCode #BitManipulation #Arrays #Cpp
To view or add a comment, sign in
-
-
Day 88/150 🚀 LeetCode 637: Average of Levels in Binary Tree 🧠 Problem Return the average value of nodes at each level of a binary tree. 💡 Approach • Use level order traversal (BFS) • For each level, calculate sum of nodes • Divide sum by number of nodes in that level • Store result in answer array ⏱ Time Complexity O(n) 📦 Space Complexity O(n) (queue for BFS) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day88 #LeetCode #BinaryTree #BFS #LevelOrder #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 87/150 🚀 LeetCode 199: Binary Tree Right Side View 🧠 Problem Return the values of nodes visible from the right side of a binary tree. 💡 Approach • Use DFS traversal • Traverse right subtree first, then left • If current level equals ans size → push node value • This ensures first node seen at each level is from right side ⏱ Time Complexity O(n) 📦 Space Complexity O(h) (recursion stack) ✅ Result: Accepted ⚡ Runtime: 2 ms #Day87 #LeetCode #BinaryTree #DFS #TreeTraversal #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 179/365 – DSA Challenge 🌳 Solved Flatten Binary Tree to Linked List on LeetCode today. 🔹 Problem: Flatten a binary tree into a linked list in-place following preorder traversal. 🔹 Approach Used: Reverse Preorder (DFS) Steps followed: 1️⃣ Traverse the tree in reverse preorder → right → left 2️⃣ Maintain a prev pointer to track previously processed node 3️⃣ For each node: Set root->right = prev Set root->left = NULL Move prev = root 🔹 Key Idea: Process nodes in reverse order so we can build the linked list from back to front. 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(h) 💻 Language: C++ Elegant example of modifying tree structure using DFS + pointer manipulation 🚀 #Day179 #365DaysOfCode #DSA #LeetCode #BinaryTree #DFS #Pointers #Cpp
To view or add a comment, sign in
-
-
Day 184/365 – DSA Challenge 🔁 Solved Reverse Bits on LeetCode today. 🔹 Problem: Reverse bits of a given 32-bit unsigned integer. 🔹 Approach Used: Bit Manipulation 💡 Key Idea: Extract each bit from the original number and place it in the reverse position. Steps: 1️⃣ Initialize result = 0 2️⃣ Loop for 32 bits: Extract last bit → (n & 1) Shift it to correct position → << (31 - i) Add to result Right shift n 3️⃣ Return result 🔹 Example: Input: 43261596 Output: 964176192 🔹 Time Complexity: O(1) (32 iterations) 🔹 Space Complexity: O(1) 🔹 Concepts Used: Bitwise AND, Shift Operators, Binary Manipulation 🔥 Pattern Recognized: Classic bit manipulation — similar to problems like: Count set bits Power of 2 Single number 💻 Language: C++ Small problem, but great for strengthening low-level thinking 💡 #Day184 #365DaysOfCode #DSA #LeetCode #BitManipulation #Cpp #CodingJourney
To view or add a comment, sign in
-
-
Day 81 / 100 – 100 Days of LeetCode Challenge 🚀 Problem: Absolute Difference Between Maximum and Minimum K Elements (LeetCode #3774) Today I solved the Absolute Difference Between Maximum and Minimum K Elements problem. The task is to select K elements from the array and compute the absolute difference between the maximum and minimum values among those selected elements. Approach I used a sorting-based strategy to organize the elements in ascending order. Once the array was sorted, identifying the minimum and maximum values among the selected K elements became straightforward. Steps followed: • Sort the array in ascending order • Select the required K elements • Identify the minimum and maximum among them • Compute and return their absolute difference This approach simplifies comparisons and ensures accurate results using ordered data. Complexity Time Complexity: O(n log n) Space Complexity: O(1) Result ✔ Accepted ⚡ Efficient runtime 🧠 Sorting and comparison logic A good problem to strengthen understanding of sorting techniques and value comparison in arrays. #100DaysOfCode #100DaysLeetCodeChallenge #LeetCode #DSA #CPlusPlus #ProblemSolving #Sorting #Arrays #regexsoftware
To view or add a comment, sign in
-
-
Day 74/150 🚀 LeetCode 226: Invert Binary Tree 🧠 Problem Given the root of a binary tree, invert the tree and return its root. 📌 Example Input → root = [4,2,7,1,3,6,9] Output → [4,7,2,9,6,3,1] 💡 Approach • Use recursion • Swap left and right child • Recursively invert left subtree • Recursively invert right subtree ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day74 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 75/150 🚀 LeetCode 101: Symmetric Tree 🧠 Problem Given the root of a binary tree, check whether it is a mirror of itself. 📌 Example Input → root = [1,2,2,3,4,4,3] Output → true 💡 Approach • Use recursion • Compare left subtree with right subtree • Check mirror structure • Continue recursively ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day75 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 2️⃣ /15 — Consistency Challenge 🚀 Today’s problem: LeetCode 3488 Closest Equal Element Queries 🔹 Approach: The idea is to efficiently find the nearest same element for each query in a circular array. Using Hashmap For each query q: Find the value → nums[q] Get the list of indices where this value occurs. Edge Case: If the value appears only once → answer is -1. Binary Search: Using Collections.binarySearch to find the position of index q in the list. This allows us to locate the nearest neighbors efficiently. Check Neighbors (Circular): Left neighbor → (pos - 1 + size) % size Right neighbor → (pos + 1) % size These represent the closest occurrences of the same value. Distance Calculation: Since the array is circular: Direct distance → |i - j| Circular distance → n - |i - j| Take the minimum of both. Final Answer: Return the minimum distance among left and right neighbors. 🔹 Time Complexity: O(n + q log k) 👉 Efficient because we avoid scanning the whole array for every query. Still improving. One day at a time. 💯 #DSA #LeetCode #Consistency #DayChallenge #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode Today I solved "Path Sum III" on LeetCode using a DFS + Recursion approach. Key Idea: We need to count all paths where the sum of node values equals the target. The path doesn’t have to start from the root — it can start from any node! Approach: • For every node, treat it as a starting point • Use DFS to explore all downward paths • Reduce the target at each step (target - node->val) • If a node matches the remaining target → count it • Repeat the process for left and right subtrees Why this works: Every node gets a chance to act as the starting point, and DFS ensures we explore all possible paths efficiently. Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Backtracking (implicit) Time Complexity: O(n²) in worst case Space Complexity: O(h) This problem helped me understand how to explore all possible paths in a tree, not just root-based ones — a big step forward in mastering tree problems From single path problems → to handling multiple dynamic paths… growing every day #Day90 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Keep Rocking bro 💯