Day 56/100 | #100DaysOfDSA 🧠⚡ Today’s problem: String Compression A clean in-place array manipulation problem. Core idea: Compress consecutive repeating characters and store the result in the same array. Approach: • Traverse the array using a pointer • Count consecutive occurrences of each character • Write the character to the array • If count > 1 → write its digits one by one • Move forward and repeat Key insight: We don’t need extra space — just carefully manage read & write pointers. Time Complexity: O(n) Space Complexity: O(1) Big takeaway: In-place algorithms require precise pointer control but give optimal space efficiency. Mastering these improves real-world memory optimization skills. 🔥 Day 56 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Strings #TwoPointers #InPlace #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
Yogesh ..’s Post
More Relevant Posts
-
Day 58/100 | #100DaysOfDSA 🔄🔍 Today’s problem: Search in Rotated Sorted Array A twist on Binary Search with a rotated array. Key idea: Even though the array is rotated, one half is always sorted. Approach: • Use binary search • Find mid element • Check which half is sorted (left or right) • Decide if target lies in the sorted half • Narrow the search accordingly Why it works: At every step, we eliminate half of the search space just like standard binary search. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Understanding the structure of the problem helps adapt classic algorithms like binary search. Rotation doesn’t break order — it just shifts it. 🔥 Day 58 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
✨ Day 42 of 90 – Pattern Mastery Journey 🧠 Pattern : Alphabet Hash Pattern 💡 Approach: ✔ Created an n × n matrix using nested loops ✔ Printed alphabets only when row index equals column index (i == j) ✔ Filled all other positions with `#` ✔ Used ASCII logic `(char)('A' + i - 1)` to generate characters 🚀 This problem helped me understand how **diagonal conditions work in matrices** and how simple conditions can create clean structured patterns. #PatternMasteryJourney #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 57/100 | #100DaysOfDSA ⛰️🔍 Today’s problem: Peak Index in a Mountain Array A perfect use-case of Binary Search on a pattern. Key observation: The array increases → reaches a peak → then decreases. Approach: • Use binary search on the index • Compare mid with mid + 1 • If arr[mid] > arr[mid + 1] → we are on the decreasing side → move left • Else → we are on the increasing side → move right This guarantees we always move toward the peak. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Binary search isn’t just for sorted arrays — it works on patterns too. Recognizing these patterns is a game changer. 🔥 Day 57 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 59/100 | #100DaysOfDSA 🔍⚡ Today’s problem: Single Element in a Sorted Array A clever Binary Search problem with a twist. Key observation: In a sorted array where every element appears twice except one, pairs follow a pattern. Before the single element: • First occurrence → even index • Second occurrence → odd index After the single element: • Pattern breaks Approach: • Use binary search • Check mid with its pair using index trick (mid ^ 1) • If nums[mid] == nums[mid ^ 1] → move right • Else → move left This helps pinpoint where the pattern breaks. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Bit manipulation + pattern observation can simplify binary search problems significantly. Small tricks → big optimizations. 🔥 Day 59 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #BitManipulation #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🧠 Day 41 / 100 – DSA Practice Solved Count and Say on LeetCode 🔢🗣️✅ 🔹 Problem: Generate the nth term of the count-and-say sequence, where each term is derived by describing the previous term. 🔹 Approach: Used an iterative + string building approach: Start with base case "1" For each iteration, read the previous string Count consecutive characters Append count + character to form next term 🔍 Key Insight: This problem is essentially Run-Length Encoding (RLE) applied repeatedly on strings 🔹 Complexity: ⏱ Time → O(n × m) (m = length of generated string) 📦 Space → O(m) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 8 ms (Beats 62%) Great problem to improve string manipulation & pattern recognition 🚀 #Day41 #100DaysOfCode #LeetCode #Java #DSA #Strings #RLE #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 364 – Daily DSA Challenge! 🔥 Problem: 🎯 Find K Closest Elements Given a sorted array arr, an integer k, and a target x, return the k closest elements to x in ascending order. 💡 Key Insight — Binary Search on Window Instead of checking each element, we binary search the starting index of a window of size k. Search space: Possible windows → [0 ... n - k] 🧠 Decision Logic At index mid, compare: Distance of left boundary → x - arr[mid] Distance of right boundary → arr[mid + k] - x We choose direction based on: ⚡ Algorithm Steps ✅ Initialize: left = 0, right = n - k ✅ Binary search: If left side is farther → shift right Else → move left ✅ Final window starts at left ✅ Collect k elements ⚙️ Complexity ✅ Time Complexity: O(log(n - k) + k) (binary search + result building) ✅ Space Complexity: O(k) 💬 Challenge for you 1️⃣ Why do we search on window positions instead of elements? 2️⃣ Can you solve this using a heap approach? 3️⃣ What if array was unsorted? #DSA #Day364 #LeetCode #BinarySearch #SlidingWindow #Arrays #Java #ProblemSolving #KeepCoding
To view or add a comment, sign in
-
-
Day 63/75 — Rotate Array Today’s problem was about rotating an array to the right by k steps. Approach: • Use reversal algorithm for optimal in-place rotation • Reverse entire array • Reverse first k elements • Reverse remaining elements Key logic: k = k % n; reverse(nums, 0, n - 1); reverse(nums, 0, k - 1); reverse(nums, k, n - 1); Time Complexity: O(n) Space Complexity: O(1) A classic array problem that reinforces in-place manipulation techniques. 63/75 🚀 #Day63 #DSA #Arrays #InPlace #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 2 Today I worked on a DSA problem based on arrays: Check if an array is sorted and rotated 🔍 Approach: Instead of finding the exact rotation point, I focused on identifying a pattern: In a sorted and rotated array, the order should break at most once. So, I checked how many times an element is greater than the next element while traversing the array in a circular manner. ✔️ If the count of such breaks is 0 or 1 → valid ❌ If it’s more than 1 → not a sorted rotated array 🧠 Key Takeaway: This problem taught me how pattern observation can simplify logic and avoid unnecessary complexity. Sometimes the best solution is not the most obvious one! 📈 Staying consistent and improving step by step 💪 #100DaysOfCode #DSA #DataStructures #Algorithms #Java #CodingJourney #ProblemSolving #LeetCode #Consistency
To view or add a comment, sign in
-
-
🧠 Day 37 / 100 – DSA Practice Solved Multiply Strings on LeetCode ✖️🔢✅ 🔹 Problem: Multiply two non-negative numbers given as strings without using built-in big integer libraries. 🔹 Approach: Simulated the manual multiplication method: Multiply each digit of num1 with each digit of num2 Store results in an array Handle carry properly Build final string while skipping leading zeros 🔍 Key Insight: Using an array of size m + n helps manage positions just like pen-and-paper multiplication 🔹 Complexity: ⏱ Time → O(m × n) 📦 Space → O(m + n) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 3 ms (Beats 85%) Loved implementing this classic math-based approach without using built-in shortcuts 🚀 #Day37 #100DaysOfCode #LeetCode #Java #DSA #Strings #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 79/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Flatten Binary Tree to Linked List A powerful tree transformation problem using pointer manipulation. Problem idea: Convert a binary tree into a linked list in-place following preorder traversal. Key idea: Iterative traversal + rewiring (similar to Morris traversal idea). Why? • We need preorder sequence (Root → Left → Right) • Instead of extra space, we modify pointers in-place • Efficient and avoids recursion stack How it works: • Traverse using a pointer curr • If left child exists: → Find rightmost node of left subtree → Connect it to current’s right subtree → Move left subtree to right → Set left = null • Move to next node (curr.right) Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Tree problems can often be optimized using in-place pointer rewiring, avoiding extra space. 🔥 This pattern is very useful for tree flattening and traversal optimizations. Day 79 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinaryTree #MorrisTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
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