🚀 Day-65 of #100DaysOfCodeChallenge Today’s problem: 2011. Final Value of Variable After Performing Operations (LeetCode - Easy) This problem was a great reminder that even simple-looking tasks can strengthen our logical reasoning and problem-solving mindset. 🧩 Problem Summary: We’re given a list of operations (++X, X++, --X, X--) that either increment or decrement a variable X. The variable starts at 0, and we need to find its final value after performing all operations on LeetCode. It sounds straightforward — but the beauty of such problems lies in their simplicity. They teach us to: Pay attention to small details. Write clean, efficient logic. Think systematically about every operation in a sequence. 💡 My Approach: I used a simple Java loop to traverse through each operation: If the operation contains '+', increment the value. If it contains '-', decrement it. It’s a one-pass solution — both time and space efficient. ⚙️ Language: Java ⚡ Runtime: 1 ms (Beats 74.53%) 💾 Memory: 42.28 MB (Beats 99.47%) ✅ Status: Accepted (259 / 259 test cases passed) Every solved problem adds one more brick to the wall of consistency and confidence. It’s not just about solving — it’s about understanding, improving, and building the habit of learning every single day. 🔹 Small progress, done daily, creates massive results over time. Onward to Day 66 💪 #100DaysOfCode #LeetCode #CodingJourney #Java #ProblemSolving #TechLearning #DeveloperLife #Consistency #LearningEveryday #ChallengeYourself
Solved LeetCode problem 2011 with Java, improved problem-solving skills
More Relevant Posts
-
#Day 8 of the LeetCode Challenge: Crushing "Power of Two" (Problem 231) with a Bitwise Bang! Today marks Day 8 of my commitment to consistent LeetCode practice, and I tackled an "easy" problem that reveals a deep secret about integers: #Power of Two (Problem 231) of LeetCode. While there are multiple ways to solve this, I went straight for the most efficient technique: Bitwise Manipulation. The trick lies in the expression: n & (n - 1). The Power of Bitwise (&) Any positive power of two (like 8 or 16) has only one bit set to '1' in its binary representation. Subtracting 1 from it flips that single '1' to '0' and all trailing '0's to '1's. When you perform a bitwise AND (&) between n and n-1, the result is {0} if, and only if, n was a power of two. The result? An elegant, O(1) time complexity solution that's often faster than looping or using logarithms! Code Snippet (Java): Java public boolean isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; } Seeing that 1ms runtime on the platform makes the small investment in learning bitwise operators totally worth it. These small optimizations are what separate good code from great code. What's a clever bitwise trick you rely on? Share your favorite optimization in the comments! 👇 #LeetCode #CodingChallenge #ProblemSolving #Java #BitwiseOperators #TechSkills #Day8 #SoftwareEngineering
To view or add a comment, sign in
-
-
#Day-44) of Problem Solving | LeetCode 2011 – Final Value of Variable After Performing Operations Just solved a fun one! 🚀 This problem tests how well you can interpret simple string-based operations and apply them efficiently. Given a list of operations like "++x", "x--", etc., the goal is to compute the final value of a variable starting from zero. 🔍 My approach (Java): Used String.indexOf("+") to detect increment operations and updated the counter accordingly. Clean, readable, and runs in linear time. #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #PranshuCodes #LinkedInCoding #TechJourney
To view or add a comment, sign in
-
-
This one LeetCode problem taught me more about discipline than syntax..!! Today’s focus: LeetCode 221 — Maximal Square A neat little problem that blends dynamic programming and pattern recognition beautifully. Each time I solve one of these, it’s less about getting the “Accepted” and more about strengthening how I think through problems. A step by step, logically and creatively. As developers, we spend a lot of time debugging, optimizing, and refactoring, but it’s these small daily problem-solving habits that keep our logical muscles in shape. #Java #LeetCode #CodingJourney #ProblemSolving #SoftwareEngineering #LearningMindset
To view or add a comment, sign in
-
-
#Day 2 of My #DSAChallenge•> Problem Statement:Given an integer array, move all zeroes to the right end while maintaining the relative order of non-zero elements. •> Understanding the Problem:This problem tests how efficiently we can perform in-place array manipulation without additional memory.A brute-force solution might involve creating a new array — increasing space complexity and processing overhead .•>Optimized Approach (Two-Pointer Technique):To make the solution efficient, I implemented the two-pointer approach:One pointer (j) tracks the position of the first zero.Another pointer (i) scans the array.Whenever a non-zero element is found, it’s swapped with the element at j, and j moves forward. This achieves:✅ O(N) time complexity✅ O(1) space complexity✅ Maintains element order (stable) ••> Java Implementation:int j = -1; Step 1: Find the first zero for (int i = 0; i < nums.length; i++) { if (nums[i] == 0) { j = i; break; }} Step 2: Swap non-zero elements with zero. for (int i = j + 1; i < nums.length; i++) { if (nums[i] != 0) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; j++; }} •> Example:Input: [0, 1, 0, 3, 12] Output: [1, 3, 12, 0, 0] •> Key Takeaway:Optimization is not just about reducing lines of code—it’s about thinking efficiently and writing with intent.Every line that saves time or space builds a sharper coding mindset.✨ Small steps each day, but consistent progress toward mastering problem-solving .#Day2 #DSAChallenge #CodingJourney #ProblemSolving #TwoPointerApproach #Java #OptimizedSolution #WomenInTech #100DaysOfCode #TechLearning #CodeBetterEveryday #DeveloperMindset #ConsistencyIsKey
To view or add a comment, sign in
-
-
🎯 Day 90 of #100DaysOfCode Today marks another milestone in my coding journey! I explored an interesting concept in Java’s Collection Framework, focusing on one of the most common yet essential data structures -the ArrayList. 💻 Problem Statement: Write a Java program to reverse the order of elements in an ArrayList<Integer> without using Collections.reverse(). 🧩 Approach I Followed: Instead of relying on Java’s built-in methods, I implemented a manual reversal logic to deepen my understanding of indexing and data manipulation. Here’s how I approached it: ✅ Step 1: Created an ArrayList and added a few integer elements. ✅ Step 2: Found the size of the list using numbers.size(). ✅ Step 3: Created a new ArrayList called reversedList to store reversed elements. ✅ Step 4: Used a for loop to traverse the list from the last index to the first, adding each element into the new list. ✅ Step 5: Printed both the original and reversed lists for comparison. 🧠 What I Learned Today: ✨ The importance of iteration and index manipulation in lists. ✨ How reversing without helper functions improves logic-building skills. ✨ Strengthened my understanding of ArrayList methods like add(), get(), and size(). ✨ Realized that coding isn’t about shortcuts -it’s about understanding how things work behind the scenes. 🚀 Every day of this challenge pushes me to go beyond syntax -to truly think like a programmer. With each problem solved, I feel more confident in building strong programming logic and clean, efficient code. 💪 The journey continues -consistency, curiosity, and code are my best companions in this 100-day challenge! #Day90 #100DaysOfCode #JavaProgramming #CollectionsFramework #ArrayList #ProblemSolving #CodingChallenge #WomenInTech #SoftwareEngineering #LearningInPublic #CodeEveryday #DeveloperJourney #ConsistencyIsKey
To view or add a comment, sign in
-
-
🚀 Leveling Up My Problem-Solving Skills on LeetCode! 💻 Hey everyone 👋 Recently, I’ve been actively solving problems on LeetCode to sharpen my Data Structures & Algorithms (DSA) skills using Java ☕. Each challenge has helped me think more analytically and write cleaner, optimized logic. Here are a few of my recent problems and how I approached them 👇 🔹 1️⃣ Longest Continuous Increasing Subsequence 🧠 Approach: I iterated through the array while comparing adjacent elements. Whenever the sequence was increasing, I increased the count; if it broke, I reset the counter. In the end, the maximum count represented the longest increasing subsequence length. 👉 Key learning: Use a simple linear scan to identify continuous increasing trends efficiently. 🔹 2️⃣ Degree of an Array 🧠 Approach: First, I calculated the frequency (degree) of each element to find the maximum occurring number(s). Then, I found the first and last occurrence of those elements in the array to calculate the shortest subarray length that maintains the same degree. 👉 Key learning: Combining frequency maps with index tracking gives powerful insights for subarray problems. 🔹 3️⃣ Design HashSet 🧠 Approach: I explored how a set structure works internally by implementing the basic operations — add, remove, and contains. This helped me understand the concept of hashing and how elements are stored uniquely without duplication. 👉 Key learning: HashSet ensures O(1) average-time complexity and is ideal for uniqueness checks. 🔹 4️⃣ Design HashMap 🧠 Approach: I implemented a simplified version of a HashMap that supports put, get, and remove operations. This gave me a better understanding of how key-value pairs are managed under the hood using hashing functions. 👉 Key learning: HashMap’s core is about mapping unique keys to their respective values efficiently. 💪 Every problem I solve helps me improve my understanding of data organization, logic flow, and algorithmic thinking. I believe small, consistent efforts make a big difference over time 🌱 👉🔗 Check out my LeetCode progress here: 👉 LeetCode Profile ->https://lnkd.in/gFH_4R9a #LeetCode #Java #ProblemSolving #DSA #LearningEveryday #DeveloperJourney #CodingMindset #GrowthMindset
To view or add a comment, sign in
-
Problem 25 : Leetcode 🚀 LeetCode Problem Solved: Find the Duplicate Number (Cyclic Sort Approach) 🧠 🔍 Problem Overview: Given an array of n+1 integers where each number is between 1 and n (inclusive), at least one duplicate number must exist. The task: Find that duplicate — with O(n) time and O(1) extra space. 💡 My Approach – Cyclic Sort Technique: I applied the Cyclic Sort algorithm to achieve both performance and space efficiency. In-Place Hashing Logic: I treated the array as a hash map where each number x should ideally be placed at index x - 1. Duplicate Detection: If arr[i] != arr[arr[i] - 1], I swapped the elements to place them correctly. If arr[i] == arr[arr[i] - 1], it indicates that arr[i] is the duplicate number — and I immediately returned it. 🏁 Results: ✅ Time Complexity: O(n) – Runtime: 6 ms, beating 50.29% of Java submissions. ✅ Space Complexity: O(1) – Solved entirely in-place. ✅ Memory Usage: 82.82 MB, outperforming 6.05% of other submissions. 🧩 Tech Insight: Cyclic Sort is an elegant in-place sorting strategy ideal for problems involving numbers within a fixed range — making it a powerful tool for efficient duplicate detection and data placement. #LeetCode #Java #DSA #ProblemSolving #CodingJourney #SpringBootDeveloper #BackendDevelopment #CyclicSort #JavaDeveloper #LearningInPublic Link : https://lnkd.in/diWSfAaM
To view or add a comment, sign in
-
-
𝗥𝘂𝗯𝘆’𝘀 𝗠𝗼𝗱𝘂𝗹𝗲𝘀: 𝗔 𝗗𝗲𝗲𝗽 𝗗𝗶𝘃𝗲 𝗕𝗲𝘆𝗼𝗻𝗱 𝘁𝗵𝗲 𝗕𝗮𝘀𝗶𝗰𝘀 𝗧𝗵𝗮𝘁 𝗧𝗿𝗶𝗽𝗽𝗲𝗱 𝗠𝗲 𝗨𝗽! I recently wrote about something that confused me for a long time in Ruby — Modules. We often 𝘵𝘩𝘪𝘯𝘬 we understand them... but when • extend • include • visibility (public, protected, private) come into play — things can quickly get tricky🌀. In my latest Medium post, I’ve broken down example code to clearly explain • What Modules really are in Ruby • How 𝘮𝘰𝘥𝘶𝘭𝘦_𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 works inside a module • 𝘪𝘯𝘤𝘭𝘶𝘥𝘦 vs. 𝘦𝘹𝘵𝘦𝘯𝘥 - The Core of Mixins • How 𝘈𝘤𝘤𝘦𝘴𝘴 𝘔𝘰𝘥𝘪𝘧𝘪𝘦𝘳𝘴 behave with nested classes • And how 𝘮𝘰𝘥𝘶𝘭𝘦 𝘤𝘭𝘢𝘴𝘴 𝘮𝘦𝘵𝘩𝘰𝘥𝘴 are actually 𝘤𝘢𝘭𝘭𝘦𝘥 If you’ve ever been unsure about where self points or 𝘩𝘰𝘸 𝘮𝘦𝘵𝘩𝘰𝘥𝘴 𝘨𝘦𝘵 𝘴𝘩𝘢𝘳𝘦𝘥 𝘣𝘦𝘵𝘸𝘦𝘦𝘯 𝘮𝘰𝘥𝘶𝘭𝘦𝘴 𝘢𝘯𝘥 𝘤𝘭𝘢𝘴𝘴𝘦𝘴 and above mentioned concepts, you’ll find attached medium post link useful 👇 https://lnkd.in/dRhd2vy5 💬 I’d love to hear from you: 1. 🤔 Have Ruby modules ever confused you? 2. 💡 How do you explain them to juniors or teammates? Drop your thoughts below 👇: and if you have anything to add, I’d love to learn from your perspective too! #Ruby #Programming #SoftwareDevelopment #Coding #Learning
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