🚀 DSA Series #1 — Closest Target in Circular Array Today I solved an interesting problem involving circular arrays + shortest distance logic. 🧠 Key Insight: Instead of simulating movement, we can compute distance using modulo. 👉 Forward distance: (i - start + n) % n 👉 Backward distance: (start - i + n) % n Take the minimum of both — done in O(n) time ⚡ 📌 Complexity: O(n) time | O(1) space 💡 Learning: Circular problems often look tricky, but math simplifies everything. 🔥 Building consistency with: #DSA #Java #Coding #PlacementPreparation #100DaysOfCode If you’re on the same path, let’s connect and grow 🤝
Shubham Kumar Singh’s Post
More Relevant Posts
-
🚀 Day 61 of my DSA Journey Today’s problem: Reverse Linked List 🔁 This is one of those classic problems that really tests your understanding of pointers and how data structures work internally. 💡 What I learned: How to reverse links instead of values Importance of using prev, curr, and next pointers How in-place algorithms help optimize space ⚡ Approach in short: Traverse the list once, and keep reversing the direction of each node step by step. 📊 Complexity: Time: O(n) Space: O(1) 🧠 Takeaway: DSA is not about memorizing solutions, it’s about understanding patterns. Every problem adds a new piece to the puzzle. Consistency > Motivation 💯 #DSAJourney #100DaysOfCode #Java #LeetCode #Coding #ProblemSolving #LinkedList #KeepLearning
To view or add a comment, sign in
-
-
🚀 DSA Practice — Getting Better Step by Step! 📅 Today’s Problem: Find Square Root of a Number (Floor Value) Solved using TakeUForward platform 💻 Today’s problem was a great example of applying Binary Search beyond just searching elements. 🔹 Approach Used: Binary Search on Answer Instead of checking every number, I used binary search to efficiently find the square root by narrowing down the range. ⏱ Time Complexity: O(log n) 💾 Space Complexity: O(1) 💡 Key Learning: Binary Search is not limited to sorted arrays — it can be applied to optimize problems where the answer lies within a range. This problem helped me understand how to reduce time complexity from O(n) to O(log n) by thinking in terms of search space rather than brute force. 🔥 Consistency continues — learning something new every day! takeUforward Striver #BinarySearch #takeUforwardtakeUforward #DSA #Algorithms #Coding #Java #ProblemSolving #SoftwareEngineering #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved an interesting Array traversal problem by iterating from right to left. Learned how to efficiently track the maximum element on the right side without extra space 🔥 🧠 Problem 🔎 Replace Elements with Greatest Element on Right Side Given an array arr, replace every element with the greatest element among the elements to its right. 👉 The last element should be replaced with -1 (since no elements exist on its right). 👉 Return the modified array. Example Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Input: arr = [400] Output: [-1] ⚡ Key Learning 📌 Traverse from right to left to keep track of maximum 📌 Update elements in-place for better efficiency 📌 Avoid extra arrays by maintaining a running max 📌 Time Complexity: O(n) → single pass through the array 📌 Space Complexity: O(1) → no extra space used (in-place update) Improving DSA with smart array techniques 🚀 #DSA #LeetCode #Arrays #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 12 of #50DaysOfLeetCode Challenge Today, I dived deep into one of the most fundamental yet tricky operations in a Binary Search Tree: Deleting a Node. At first glance, it seems simple, but the real challenge lies in re-connecting the nodes correctly so the BST property remains intact. Using a pen and paper to dry run the logic made a huge difference in understanding how the tree "heals" itself after a node is removed. The 3 Scenarios I explored: 1. The Leaf Node: Simple! Just remove it (set parent's child to null). 2. One Child: The node’s child simply "steps up" and takes its place. 3. Two Children (The Tricky Part): To keep the tree valid, we find the Inorder Successor (the smallest value in the right subtree), swap it with the target node, and then delete the successor. DSA isn't just about writing code; it’s about visualizing the structure and understanding the "why" behind every pointer change. #DataStructures #Algorithms #Java #LeetCode #CodingJourney #BST #ProblemSolving #ContinuousLearning
To view or add a comment, sign in
-
-
🚀 Day 46 of My DSA Journey Today I solved a problem that looked simple but had an interesting twist — constrained swapping in strings. 🔍 Problem: Check if two strings can be made equal using swaps where the index difference is exactly 2. 💡 Key Learning: Instead of actually performing swaps, I understood that: Only specific indices can interact (0↔2 and 1↔3) This divides the string into independent groups We just need to compare characters within these groups ✨ This problem reinforced an important concept: 👉 When operations are restricted, think in terms of groups rather than brute-force simulation. #DSA #ProblemSolving #Java #CodingJourney #Consistency #LeetCode
To view or add a comment, sign in
-
-
Day 13/90 DSA Journey Today I worked on an interesting problem where each bulb toggles between ON and OFF based on its occurrences in the input list. ->Key Idea: If a number appears odd number of times → bulb remains ON If it appears even number of times → bulb turns OFF -> Approach: Used a List-based toggle logic Add element if not present Remove element if already present Finally, sort the result -> Time Complexity: O(n²) using List (due to contains & remove) -> Optimized Insight: This problem can be solved more efficiently using a HashSet in O(n) time. -> Takeaway: Understanding frequency and toggling patterns is very useful in solving real-world and DSA problems. #LeetCode #DSA #Java #Coding #ProblemSolving #Learning #TechJourney
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 119/360 🚀 📌 Topic: Recursion / Math 🧩 Problem: Pow(x, n) Problem Statement: Find x raised to the power n (xⁿ) efficiently, even for large values of n. 🔍 Example: Input: x = 2, n = 5 Output: 32 💡 Approach: Optimized (Binary Exponentiation) 1️⃣ Step 1 – If n is negative, convert → x = 1/x and n = -n 2️⃣ Step 2 – Recursively calculate half = power(x, n/2) 3️⃣ Step 3 – • If n is even → return half × half • If n is odd → return half × half × x ⏱ Complexity: Time: O(log n) Space: O(log n) 📚 Key Learning: Breaking a problem into halves can drastically improve performance 🚀 #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #119DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
=> Day 20/90 DSA Journey Solved: Count Odd Numbers in an Interval (LeetCode 1523) Instead of using loops, I applied a simple mathematical formula to achieve an O(1) solution. 🔹 Key Idea: Count of odd numbers between low and high can be calculated directly using: -> ((high + 1) / 2) - (low / 2) 🔹 Why this works: -> It efficiently counts odds up to high and subtracts odds before low. 🔹 Example: Input: low = 3, high = 7 Output: 3 (Odd numbers → 3, 5, 7) -> Time Complexity: O(1) -> Space Complexity: O(1) #Java #DSA #LeetCode #ProblemSolving #Coding #Optimization
To view or add a comment, sign in
-
-
🚀 Day 18 of My DSA Journey Today I worked on a basic math problem: 👉 Greatest Common Divisor (GCD) 💡 Problem: Find the largest number that divides both given numbers perfectly. 🧠 Approach: Iterate from 1 to min(a, b) Check which number divides both values Keep updating the maximum divisor ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Key Learning: Understanding basic number theory concepts is important for solving many optimization problems. Next step: exploring more efficient approaches like Euclid’s Algorithm 🚀 Consistency matters 💪 #DSA #Java #CodingJourney #100DaysOfCode #Math #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 89 – DSA Journey | Invert Binary Tree Continuing my daily DSA practice, today I worked on a classic problem that builds strong intuition around tree manipulation. 📌 Problem Practiced: Invert Binary Tree (LeetCode 226) 🔍 Problem Idea: Given a binary tree, invert it by swapping the left and right children of every node. 💡 Key Insight: At each node, simply swap its left and right subtrees. Recursively applying this across the tree results in a complete mirror of the original tree. 📌 Approach Used: • If the node is null → return null • Swap left and right children • Recursively apply the same operation on both subtrees • Return the root after inversion 📌 Concepts Strengthened: • Tree traversal • Recursion • Tree manipulation • Mirror transformation ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(h) (recursion stack) 🔥 Today’s takeaway: Simple operations applied recursively can transform complex structures like trees efficiently. On to Day 90! 🚀 #Day89 #DSAJourney #LeetCode #BinaryTree #Recursion #Java #ProblemSolving #Coding #LearningInPublic #Consistency
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