🚀Day 5️⃣9️⃣of #100DaysOfCode Solved LeetCode 3354 – Make Array Elements Equal to Zero 🧮 ⚡ Runtime: 1 ms (Beats 83.13%) 📊 Memory: 42.10 MB (Beats 69.28%) 🔍 Concept: This problem revolves around array traversal, directional logic, and state transitions. You start from an index where the element is 0 and move left or right while updating values and reversing direction — until all elements reach zero. 🧩 Approach Summary: Identify the initial index containing 0. Traverse left and right, updating values and counting valid selections. Keep it simple, linear, and effective. Some problems test patience as much as skill — but every solved logic strengthens the problem-solving mindset. #LeetCode #Java #ProblemSolving #100DaysOfCode #CodingJourney #SoftwareEngineer #Developer #AlgorithmDesign #Consistency #LearningEveryday
Solved LeetCode 3354 with Java in 1 ms
More Relevant Posts
-
💡 Day 10 of 100 Days of LeetCode 📘 Problem: #26. Remove Duplicates from Sorted Array 💻 Difficulty: Easy 🔍 Concept: The task is to remove duplicates in-place from a sorted array so that each unique element appears only once. The function should return the count of unique elements k. ⚙️ Approach Used: Used two-pointer technique — one pointer (k) tracks the position of the last unique element, and the other (i) scans the array. Whenever a new unique element is found, it’s moved to the next position in the array. 🧠 Key Learnings: Mastered the in-place modification concept in arrays. Learned how to use two-pointer pattern for linear-time solutions. Refined logic building with minimal extra space usage (O(1) space). 💻 Code (Java): class Solution { public int removeDuplicates(int[] nums) { int k = 0; for (int i = 1; i < nums.length; i++) { if (nums[i] != nums[k]) { k++; nums[k] = nums[i]; } } return k + 1; } } 💬 Reflection: A simple-looking problem — but it’s one that trains you to think in space-efficient ways. Sometimes, mastering basics is what builds strong problem-solving intuition! #100DaysOfLeetCode #Day10 #DSA #Java #ProblemSolving #CodingChallenge #LeetCode #LearningEveryday
To view or add a comment, sign in
-
-
🔥 Day 33/100 of #100DaysOfCode - Alternating Positive & Negative! Today's Problem: Rearrange Array Elements by Sign Task: Given an array with equal number of positive and negative integers, rearrange them in alternating positive/negative order (starting with positive). Solution: Used a two-pointer approach with separate indices for positive and negative positions! Created a temp array and placed positives at even indices (0, 2, 4...) and negatives at odd indices (1, 3, 5...). Key Insights: Since the array has equal positives and negatives, we can pre-determine positions O(n) time complexity with O(n) space for the temp array Clean and intuitive - no complex swapping needed Smart Pointer Management: Positive pointer moves by +2 each time Negative pointer moves by +2 each time Single pass through the original array Elegant solution for maintaining relative order while achieving the required alternation! ⚡ #100DaysOfCode #LeetCode #Java #Algorithms #Arrays #TwoPointers #CodingInterview
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 81 Linked List Cycle Problem Given the head of a linked list, determine whether the list contains a cycle meaning a node’s next pointer refers back to a previous node. My Approach Used Floyd’s Cycle Detection Algorithm (Tortoise & Hare Method): Initialized two pointers slow and fast. Moved slow one step and fast two steps in each iteration. If they ever meet → cycle detected. If fast or fast.next becomes null → no cycle exists. Complexity Time: O(n) Space: O(1) Even in problems involving dynamic structures like linked lists, a simple pointer-based approach can lead to an elegant and optimal solution. #100DaysOfCode #LeetCode #Java #ProblemSolving #DataStructures #LinkedList #TortoiseAndHare #takeUforward #CodeNewbie #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
To view or add a comment, sign in
-
-
💻 Enhancing Problem-Solving Skills with LeetCode (Java) Recently solved a couple of fundamental algorithmic problems that helped strengthen my understanding of two-pointer techniques, array manipulation, and writing efficient solutions. 🔹 Container With Most Water Implemented an optimised two-pointer approach to find the maximum water area between vertical lines. Instead of checking every pair (which would be O(n²)), the solution smartly moves the pointer at the shorter height inward to explore potentially larger areas. Approach: Two Pointers, Greedy Time Complexity: O(n) Space Complexity: O(1) 🔹 3Sum Solved the classic triplet-finding challenge by sorting the array and using two pointers to efficiently search for combinations that sum to zero. Also handled duplicates to avoid repeated triplets. Approach: Sorting + Two Pointers Time Complexity: O(n²) Space Complexity: O(1) (excluding output list) These problems helped sharpen my understanding of pointer movement, edge-case management, and designing clean, efficient solutions. #LeetCode #Java #Algorithms #DSA #Coding #ProblemSolving #SoftwareEngineering #LearningJourney
To view or add a comment, sign in
-
Today’s problem: Merge Two Sorted Lists 🔗 Problem: Given two sorted linked lists, merge them into one sorted list and return it. Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Approach I used: ✅ Create a dummy node to simplify pointer operations. ✅ Use a pointer (tail) to build the merged list by comparing the heads of both lists. ✅ Append the smaller node each time and move forward. ✅ When one list ends, attach the remaining nodes of the other. A clean iterative solution that keeps the space usage minimal (O(1) extra space). ⚡
To view or add a comment, sign in
-
-
💻 Strengthening My Algorithmic Skills with LeetCode (Java) Recently solved a few problems focusing on string manipulation and pattern-based logic, which helped me improve both problem decomposition and implementation clarity: 🔹 Zigzag Conversion Implemented a pattern-based traversal to simulate zigzag text arrangement across multiple rows. Approach: Row-by-row traversal Time Complexity: O(n) 🔹 Find the Index of the First Occurrence in a String (strStr) Developed a substring matching solution using a straightforward iterative comparison. Approach: Sliding window Time Complexity: O(n × m) 🔹 Reverse Words in a String Solved by splitting the input string, trimming spaces, and reconstructing it in reverse order. Approach: String split + reverse iteration Time Complexity: O(n) These problems helped strengthen my understanding of string operations, pattern logic, and efficient iteration techniques. #LeetCode #Java #DSA #ProblemSolving #Algorithms #Coding #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 59 of #100DaysOfCode 🚀 🔹 Problem: Check if Digits Are Equal in String After Operations I – LeetCode ✨ Approach: Used an iterative reduction strategy 🔁 — repeatedly combined adjacent digits (mod 10) until only two numbers remained. Finally checked if both digits are equal! Simple yet logical 🧠 ⚡ Complexity Analysis: Time Complexity: O(n²) – iterative pairwise reduction until only two digits remain Space Complexity: O(n) – storing intermediate list of digits 📊 Performance: ✅ Runtime: 10 ms (Beats 35.69%) ✅ Memory: 45.51 MB (Beats 12.86%) 🔑 Key Insight: Sometimes, brute-force reduction problems aren’t about optimization — they’re about translating logic into clean code that mirrors the operation flow perfectly. ✨ #LeetCode #100DaysOfCode #Java #DSA #ProblemSolving #CodingChallenge #LogicBuilding #ProgrammingJourney #DailyCoding
To view or add a comment, sign in
-
-
🔹 Day 39 – LeetCode Practice Problem: Perfect Number (LeetCode #507) 📌 Problem Statement: A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding itself. Return true if the given number is perfect, otherwise return false. ✅ My Approach (Java): Initialize sum = 0. Iterate from 1 to num / 2. For every divisor i such that num % i == 0, add it to sum. After the loop, if sum == num, it’s a perfect number. 📊 Complexity: Time Complexity: O(n/2) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 2108 ms Memory: 41.19 MB 💡 Reflection: This problem reinforced the importance of divisor-based iteration. While this brute-force solution works, optimizing divisor checks using square roots can greatly improve performance — a good next step for refinement! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
To view or add a comment, sign in
-
-
🚀 Day 118 of 120 – #DSAwithJava Challenge Hey LinkedIn fam! 👋 Today’s problem was all about Linked Lists and HashSets — a combination that makes node deletions efficient and elegant ⚡ ✅ Problem: Delete Nodes From Linked List Present in Array (LeetCode #3217 – Medium) 🎯 Objective: Given an array nums and the head of a linked list, remove all nodes whose values exist in nums. 🧠 Key Insight: Store all elements of nums in a HashSet for O(1) lookups. Use a dummy node before the head to handle edge deletions easily. Traverse the list, and if a node’s value exists in the set, skip it by adjusting pointers. The result is a clean linked list containing only valid nodes. 💡 Example: Input → nums = [1,2,3], head = [1,2,3,4,5] Output → [4,5] 🕒 Time Complexity: O(n + m) 📦 Space Complexity: O(m) 🔥 Takeaway: When dealing with linked lists, HashSets simplify membership checks, and dummy nodes simplify pointer logic. A small design tweak can lead to clean and optimal solutions! 💪 #120DaysOfCode #DSAwithJava #LeetCode #Java #LinkedList #HashSet #ProblemSolving #CodingChallenge #TechJourney #Consistency #LearnByDoing
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