🚀 Day 88 of #100DaysOfCode Solved 2058. Find the Minimum and Maximum Number of Nodes Between Critical Points 🔗 🧠 Key Insight: A node is a critical point if: 🔺 It is a local maxima → greater than both neighbors 🔻 It is a local minima → smaller than both neighbors ⚙️ Approach (Single Pass + Index Tracking): 1️⃣ Traverse the linked list while keeping track of: • prev, curr, next • current index i 2️⃣ Identify critical points: ✔️ curr > prev && curr > next ✔️ curr < prev && curr < next 3️⃣ Store their indices 4️⃣ If total critical points < 2 → return [-1, -1] 5️⃣ Otherwise compute: ✅ Minimum distance → between consecutive critical points ✅ Maximum distance → between first & last critical point ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) (critical points count) #100DaysOfCode #LeetCode #DSA #LinkedList #ProblemSolving #CodingJourney
Solved 2058 Find Min Max Nodes Between Critical Points in Linked List
More Relevant Posts
-
Day 90/150 🚀 LeetCode 637: Average of Levels in Binary Tree 🧠 Problem Return the average value of nodes on each level in a binary tree. 💡 Approach • Use BFS (level order traversal) • For each level, calculate sum of nodes • Divide sum by number of nodes in that level • Store result in a vector ⏱ Time Complexity O(n) 📦 Space Complexity O(n) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day90 #LeetCode #BinaryTree #BFS #LevelOrder #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 36/60 – Reflected Binary Logic: Mastering Gray Code Generation! The final stretch of the #geekstreak60 is officially in sight! Today's challenge was all about Gray Codes—a sequence where each step only changes a single bit. The Technical Deep Dive: The Pattern: I used the Reflective Method. To generate an $n$-bit code, you take the $(n-1)$ code, mirror it, and append "0"s and "1"s as prefixes. Why it matters: Gray codes are essential in digital communications and error correction (like in rotary encoders) because they prevent "spurious" intermediate states during bit transitions. The Efficiency: This recursive approach builds the $2^n$ sequence in $O(2^n)$ time, which is optimal given the output size.
To view or add a comment, sign in
-
-
Day 70/150 🚀 LeetCode 86: Partition List 🧠 Problem Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. 📌 Example Input → head = [1,4,3,2,5,2], x = 3 Output → [1,2,2,4,3,5] 💡 Approach • Create two lists (smaller & greater) • Traverse original list • Add nodes based on condition • Merge both lists ⏱ Time Complexity O(n) 📦 Space Complexity O(1) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day70 #LeetCode #DSA #LinkedList #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 83 of #100DaysOfCode Today, I solved LeetCode 1391 – Check if There is a Valid Path in a Grid, a problem that combines grid traversal with constraint-based movement. 💡 Problem Overview: Given a grid where each cell represents a type of street, the task is to determine whether there exists a valid path from the top-left cell to the bottom-right cell. 🧠 Approach: ✔️ Modeled the grid as a graph with directional constraints ✔️ Used BFS/DFS traversal to explore valid paths ✔️ Ensured movement is allowed only if both adjacent cells have compatible connections ✔️ Checked reachability of the destination cell ⚡ Key Takeaways: Grid problems often require validating movement constraints Not all neighbors are valid — direction compatibility matters BFS/DFS help in solving reachability problems efficiently 📊 Complexity Analysis: Time Complexity: O(n × m) Space Complexity: O(n × m) Improving logical thinking with every problem 🚀 #LeetCode #100DaysOfCode #DSA #Graphs #GridProblems #BFS #DFS #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
🚀 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
To view or add a comment, sign in
-
-
Day 82/150 🚀 LeetCode 112: Path Sum 🧠 Problem Given a binary tree and a targetSum, return true if there exists a root-to-leaf path where the sum of node values equals targetSum. 💡 Approach • Use DFS (Recursion) • Keep adding node values while traversing • Check at leaf node if sum equals target • Return true if any path matches ⏱ Time Complexity O(n) 📦 Space Complexity O(h) (recursion stack) ✅ Result: Accepted ⚡ Runtime: 3 ms 💾 Memory Beats: 94.93% #Day82 #LeetCode #BinaryTree #DFS #Recursion #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
𝗣𝗿𝗲𝗽𝗮𝗿𝗲 𝗳𝗼𝗿 𝘁𝗵𝗲 𝘀𝘁𝗼𝗿𝗺 𝘁𝗵𝗮𝘁’𝘀 𝗮𝗹𝗿𝗲𝗮𝗱𝘆 𝗳𝗼𝗿𝗺𝗶𝗻𝗴. 𝗜𝗳 𝗲𝘃𝗲𝗿𝘆𝘁𝗵𝗶𝗻𝗴 𝗳𝗮𝗶𝗹𝘀 𝘁𝗼𝗺𝗼𝗿𝗿𝗼𝘄, 𝗰𝗮𝗻 𝘆𝗼𝘂 𝗲𝘃𝗲𝗻 𝗲𝘅𝗽𝗹𝗮𝗶𝗻 𝘆𝗼𝘂𝗿 𝗹𝗲𝗴𝗮𝗰𝘆 𝘀𝘆𝘀𝘁𝗲𝗺𝘀? Efficiency is the only real trend in 2026. From your source code alone: zAbsolute generates 100% of all components—along with their connections, dependencies, CRUD operations, arguments, parameters, variables, and their values. Every day. With no human intervention. zConatus allows your staff to search for anything recorded in your inventory, using filters that make sense to them. It also presents results graphically—no UML whatsoever—using node-and-edge diagrams that anyone can understand. No PhD required.
To view or add a comment, sign in
-
-
Day 5 of #100Days 💻 Solved LeetCode 1391 – Check if There is a Valid Path in a Grid 🔍 Intuition: The problem looks like a grid traversal, but the key twist is direction compatibility. Each cell (street type) allows movement only in certain directions, and a move is valid only if both the current cell and the next cell agree on the connection (i.e., bidirectional connectivity). So, the idea is to treat the grid as a graph and perform BFS/DFS, while ensuring: The current cell allows movement in a direction The next cell allows movement back (reverse direction) This guarantees we only follow valid “pipes” and avoid invalid paths. ⏱ Time Complexity: O(m × n) — each cell is visited at most once #DSA #LeetCode #Graphs #BFS #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 57 / 100 – #100DaysLeetCode Challenge 🚀 Problem: Transformed Array Today’s problem focused on circular array traversal and index manipulation. We are given an integer array that behaves like a circular array. For each element, we move left or right based on its value and place the value from the landing index into the result array. The idea: Treat the array as circular and calculate the new index using modulo arithmetic. This ensures movement wraps around the array correctly when reaching the ends. Example: nums = [3, -2, 1, 1] Each element moves steps equal to its value, and the result array stores the value at the new index. Approach: • Iterate through each index of the array • Compute the new index using modulo to handle circular movement • Assign the value from the computed index to the result array Time Complexity: O(n) Space Complexity: O(n) Performance: ⚡ Runtime: 0 ms Clean and efficient circular array logic ✔ Problems like this strengthen understanding of modulo operations and circular traversal patterns. On to Day 58 🔥 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving #Arrays #CPlusPlus #Consistency
To view or add a comment, sign in
-
-
Leetcode POTD : Rotate Function Approch : These are the kind of problems where you need to calculate the answer of one index in O(n) and then use this precomputed answer to construct the rest answers in O(1) like here i calculated the answer for index 0 (considering 1 based indexing) and then used this value to calculate the answers for each value. Time Complexity : O(2n) Space Complexity : O(1)
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