🚀 Day 41 of #100DaysOfCode Solved 189. Rotate Array on LeetCode 🔄 🧠 Key Insight: Rotating an array by k steps to the right means the last k elements move to the front, while the remaining elements shift to the right. ⚙️ Approach: 1️⃣ Compute effective rotations using k % n 2️⃣ Store the last k elements in a temporary array 3️⃣ Shift the remaining n-k elements to the right 4️⃣ Copy the stored elements back to the beginning of the array This ensures the rotation happens in-place with controlled extra space. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) #100DaysOfCode #LeetCode #DSA #Arrays #Java #ProblemSolving #InterviewPrep #LearningInPublic
Rotating Array on LeetCode with Java
More Relevant Posts
-
Day 16/100 – LeetCode Challenge Problem: Merge Sorted Array Today’s problem involved merging two sorted arrays into one sorted array. Approach: Created a temporary array of size m + n Used two pointers to compare elements from both arrays Inserted the smaller element into the new array Copied remaining elements if any array still had values Finally copied the merged result back into nums1 Complexity: Time: O(m + n) Space: O(m + n) Concepts Practiced: Two-pointer technique Array traversal Merging sorted arrays #100DaysOfCode #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 64 of #100DaysOfCode Solved 222. Count Complete Tree Nodes on LeetCode 🔗 🧠 Key Insight: In a complete binary tree, all levels are fully filled except possibly the last, and nodes are as left as possible. 👉 This property helps us optimize beyond simple traversal ⚙️ Approach (Simple DFS - Your Solution): 1️⃣ If root is null → return 0 2️⃣ Recursively count: 🔹 left = countNodes(root.left) 🔹 right = countNodes(root.right) 3️⃣ Total nodes: 👉 1 + left + right ⏱️ Time Complexity: Current → O(n) Optimized → O(log² n) 📦 Space Complexity: O(h) #100DaysOfCode #LeetCode #DSA #BinaryTree #Recursion #DivideAndConquer #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 67 of #LeetCode Challenge ✅ Problem Solved: Check If Two String Arrays are Equivalent 💡 What I learned today: • Learned how to compare two string arrays without joining them • Understood how to traverse multiple strings using pointers • Improved handling of indices across arrays and strings • Realized the importance of edge cases to avoid runtime errors 🧠 Approach: • Used four pointers to track positions in both arrays and strings • Compared characters one by one • Moved to the next string when current string ends • Ensured both arrays are fully traversed at the end 📊 Key Takeaway: Efficient solutions avoid extra space — comparing character by character is better than building new strings 🔥 Consistency + small improvements every day = big progress #Day67 #LeetCode #CodingJourney #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 78/100 – #100DaysOfCode Today, I solved “𝐒𝐞𝐭 𝐌𝐚𝐭𝐫𝐢𝐱 𝐙𝐞𝐫𝐨𝐞𝐬” problem on LeetCode 🔍 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Given a matrix, if any element is 0, we need to set its 𝐞𝐧𝐭𝐢𝐫𝐞 𝐫𝐨𝐰 𝐚𝐧𝐝 𝐜𝐨𝐥𝐮𝐦𝐧 𝐭𝐨 0 — in-place without using extra space. 💡 𝐖𝐡𝐚𝐭 𝐈 𝐋𝐞𝐚𝐫𝐧𝐞𝐝: How to optimize space complexity to O(1) Using the first row & column as markers Importance of handling edge cases (first row & first column separately) ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Check if 𝐟𝐢𝐫𝐬𝐭 𝐫𝐨𝐰/𝐜𝐨𝐥𝐮𝐦𝐧 𝐧𝐞𝐞𝐝𝐬 𝐭𝐨 𝐛𝐞 𝐳𝐞𝐫𝐨𝐞𝐝 Use first row & column to mark zeros Update the matrix accordingly Finally update first row & column if needed 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: Time: O(m × n) Space: O(1) #Day78 #100DaysOfCode #DSA #Java #LeetCode #CodingJourney #SoftwareDeveloper #KeepLearning
To view or add a comment, sign in
-
🚀 Day 55 of #100DaysOfCode Solved 147. Insertion Sort List on LeetCode 🔗 🧠 Key Insight: We apply the classic Insertion Sort, but on a linked list instead of an array. The challenge is handling pointer manipulation efficiently. ⚙️ Approach: 1️⃣ Create a dummy node to act as the start of the sorted list 2️⃣ Traverse the original list node by node 3️⃣ For each node: Find its correct position in the sorted part Insert it there by updating pointers 🔁 This builds a sorted list incrementally ⏱️ Time Complexity: O(n²) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Sorting #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟔𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on rotating an array to the right by k steps efficiently. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Rotate Array 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐑𝐞𝐯𝐞𝐫𝐬𝐚𝐥 𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞 • First normalized k using k % n • Reversed the entire array • Reversed the first k elements • Reversed the remaining elements This results in the desired rotation. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Reversal technique is a powerful in-place trick • Breaking a problem into steps simplifies logic • Modulo helps handle large values of k • In-place operations reduce space complexity 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Sometimes the best solution is not shifting elements — but rearranging them smartly. 63 days consistent 🚀 On to Day 64. #DSA #Arrays #TwoPointers #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
🔥 Day 83 of my LeetCode Journey 🔥 📘 Problem: 350. Intersection of Two Arrays II 🎯 Difficulty: Easy 🔹 Problem Statement: Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays, and you may return the result in any order. 🔹 Approach Used: Sort both arrays Use two pointers to traverse both arrays Compare elements: If equal → add to result and move both pointers If smaller → move that pointer forward Store results and return the intersection array 🔹 Key Concepts: Two-pointer technique Sorting arrays Efficient traversal Handling duplicates 🔹 Learning: This problem highlights how sorting combined with the two-pointer approach simplifies comparison problems. It also reinforces handling duplicates correctly while maintaining efficiency. #LeetCode #Day80 #Java #Arrays #TwoPointers #Sorting #DSA #ProblemSolving
To view or add a comment, sign in
-
-
Day 59 - Merge Two Sorted Lists Worked on merging two sorted linked lists into one sorted list. Approach: • Used a dummy node to simplify pointer handling • Compared nodes from both lists and attached the smaller one • Appended remaining elements after traversal A classic linked list problem that strengthens pointer manipulation skills. Time Complexity: O(n + m) Space Complexity: O(1) #Day59 #LeetCode #Java #LinkedList #CodingPractice #DSA #TechJourney
To view or add a comment, sign in
-
-
Day 25/100: Finding the "Gap" 🎯 Today's challenge: Search Insert Position. We all know Binary Search finds an element in O(log n), but what if the element isn't there? I learned that by the end of the search, the `left` pointer doesn't just give up—it points exactly to where that missing number *should* be inserted to keep the array sorted. It’s a powerful way to handle dynamic data without breaking the order. Quarter of the way through the challenge! 🚀 #100DaysOfCode #Java #DSA #BinarySearch #ProblemSolving #Unit3 #Day25 #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 22/100 Days of Code Challenge Today’s problem: Find Square Root of a Number (Binary Search Approach) 🔍 What I learned: How to efficiently compute the square root using Binary Search instead of brute force Understanding the concept of floor value of sqrt(n) Avoiding overflow using mid = low + (high - low) / 2 Time complexity improved to O(log n) 💡 🧠 Key Idea: Instead of checking every number, we narrow down the answer by dividing the search space in half — classic binary search optimization ✅ Example: Input: 28 Output: 5 (floor value of √28) Consistency is key 🔑 — showing up every day and improving step by step! #Day22 #100DaysOfCode #DSA #BinarySearch #Java #CodingJourney #ProblemSolving #TechSkills #KeepLearning
To view or add a comment, sign in
-
Explore related topics
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