🚀 Day 52 of #100DaysOfCode 🚀 Today I solved LeetCode Problem #389 – Find the Difference 🧩 This problem is a great example of using ASCII value manipulation to solve what seems like a string comparison challenge. 💡 Key Learnings: Strengthened understanding of character encoding (ASCII values) and how they can simplify logic. Learned how summing character values can help detect differences efficiently without extra data structures. Reinforced the value of O(n) solutions for string-based problems. 💻 Language: Java ⚡ Runtime: 1 ms — Beats 99.32% 🚀 📉 Memory: 41.9 MB — Beats 65.84% 🧠 Approach: 1️⃣ Convert both strings to character arrays. 2️⃣ Compute the sum of ASCII values of both. 3️⃣ The difference between sums gives the ASCII value of the extra character in t. Simple, elegant, and efficient! ⚙️ Sometimes, a clever use of ASCII arithmetic can replace complex logic — efficiency lies in simplicity. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingChallenge #Algorithms #DataStructures #SoftwareDevelopment #LearningEveryday #CleanCode
Solved LeetCode Problem #389 using ASCII value manipulation in Java
More Relevant Posts
-
🚀 Day 58 of #100DaysOfCode 🚀 Today, I solved LeetCode Problem #852 – Peak Index in a Mountain Array 🏔️ 📘 Problem Statement: Given an integer array that first increases and then decreases (a “mountain array”), find the index of the peak element — the point where the sequence changes from increasing to decreasing. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100.00% ⚡ 📉 Memory: 56.29 MB — Beats 60.76% 🧠 Concept Used: 🔹 Binary Search Optimization – Instead of linearly scanning the array, I applied binary search to achieve O(log n) time complexity. 🔹 This approach identifies the peak by checking midpoints and adjusting the search range efficiently. 🧩 Approach: 1️⃣ Initialize low = 0 and high = arr.length - 1. 2️⃣ Use binary search: ➡️ If arr[mid] < arr[mid + 1], the peak lies to the right → move low = mid + 1. ➡️ Else, the peak is at mid or to the left → move high = mid. 3️⃣ Return low when low == high — the index of the peak. ✅ Complexity: Time: O(log n) Space: O(1) ✨ Takeaway: Binary Search isn’t just for finding numbers — it’s a pattern for optimizing any “search in sorted behavior” scenario. Learning to spot monotonic trends in problems can turn O(n) solutions into O(log n) ones! #100DaysOfCode #LeetCode #Java #ProblemSolving #Algorithms #BinarySearch #DataStructures #CodingChallenge #CleanCode #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
-
🚀 Day-75 of #100DaysCodeOfChallenge 💡 LeetCode Problem: 1526. Minimum Number of Increments on Subarrays to Form a Target Array (Hard) 🧠 Concepts Practiced: Greedy Algorithms | Array Manipulation | Difference Computation Today’s challenge was a Hard-level problem, focusing on finding the minimum number of operations required to transform an initial array of zeros into a given target array — using only subarray increments. The key insight here was realizing that each increase in value from one element to the next represents a required new operation on LeetCode. Instead of simulating every subarray operation, we can simply sum up the positive differences between consecutive elements — a great example of mathematical optimization through observation 💭 🔹 Intuition: Only when a number increases compared to the previous one, a new increment operation is needed. ⚙️ Language: Java ⚡ Runtime: 3 ms (Beats 100%) 💾 Memory: 56.82 MB (Beats 61.41%) ✅ Result: 129 / 129 test cases passed — Accepted! 🎯 Each “hard” problem solved adds one more layer of confidence — and reminds me that persistence pays off 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #Algorithms #CodingChallenge #GreedyAlgorithm #LearningJourney #TechMindset #KeepCoding #SoftwareEngineering #DeveloperLife #LogicBuilding
To view or add a comment, sign in
-
-
🚀 Day 60 of #100DaysOfCode 🚀 Today, I solved LeetCode Problem #137 – Single Number II 🧩 📘 Problem Statement: Given an integer array where every element appears three times except for one that appears exactly once, find that single element and return it. The challenge: solve it with O(n) time and O(1) space complexity. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100.00% 📉 Memory: 45.54 MB — Beats 56.30% 🧠 Concept Used: 🔹 Bit Manipulation — A powerful yet tricky technique that leverages binary operations to track occurrences of bits efficiently. 🔹 Instead of using extra space or hash maps, we track bits that appear once and twice using two integer variables: ✅ once → bits that appeared once ✅ twice → bits that appeared twice The trick lies in updating them using XOR (^) and NOT (~) to "cancel out" bits appearing three times. 🧩 Approach Summary: 1️⃣ Initialize two variables once = 0 and twice = 0. 2️⃣ For every number in the array: - Update once and twice based on how many times a bit has appeared. 3️⃣ After processing all numbers, once holds the value of the single element. ✅ Complexity: Time: O(n) Space: O(1) ✨ Takeaway: This problem teaches how bitwise logic can replace traditional data structures, achieving the same result with constant space — a crucial optimization in system-level programming and interviews. #100DaysOfCode #LeetCode #Java #BitManipulation #ProblemSolving #CleanCode #DataStructures #Algorithms #TechLearning #CodingChallenge #SoftwareEngineering #InterviewPreparation
To view or add a comment, sign in
-
-
🚩 Problem: 78. Subsets 🔥 Day 56 of #100DaysOfLeetCode 🔍 Problem Summary: Given an integer array nums, return all possible subsets (the power set). The solution set must not contain duplicates, and the order does not matter. 🧠 Intuition: This is one of the simplest and cleanest backtracking problems. At each index, you have only two choices: Include the current element Exclude the current element This naturally builds the entire power set. Alternatively, you can also build subsets by expanding a list from left to right. ✅ Backtracking Approach: Start with an empty subset Recursively explore adding each number After each choice, backtrack and remove it Add all generated combinations into the result Super clean and beginner-friendly. ⚙️ Performance: ⏱️ Runtime: 1 ms 🚀 💪 Beats: 97% of Java solutions 💾 Memory: 43 MB ⚡ (Beats ~90% of users) 📊 Complexity: Time Complexity: O(n × 2ᶰ) Space Complexity: O(n) (recursion + temp list) ✨ Key Takeaway: This problem teaches the classic recursive structure used for: Subsets Combinations Nested choices Decision-tree exploration It's the perfect stepping stone to more advanced backtracking problems. Link:[https://lnkd.in/gfQV_8w4] #100DaysOfLeetCode #Day56 #Problem78 #Subsets #Backtracking #Recursion #Algorithms #DSA #Java #ProblemSolving #LeetCode #CodingChallenge #CodingCommunity #InterviewPreparation #CrackingTheCodingInterview #SoftwareEngineering #DataStructures #ArjunInfoSolution #DeveloperJourney #LearnToCode #TechCareers #CareerGrowth #CodeNewbie #ZeroToHero #CodingIsFun #JavaDeveloper #GameDeveloper #Unity #AI #MachineLearning
To view or add a comment, sign in
-
-
🚀 Day 146 / 180 of #180DaysOfCode ✅ Today’s Highlight: Revisited LeetCode 3234 — “Count the Number of Substrings With Dominant Ones.” 🧩 Problem Summary: Given a binary string s, the task is to count how many of its substrings have dominant ones. A substring is considered dominant if: number of 1s ≥ (number of 0s)² This creates an interesting balance check between zeros and ones, pushing you to think about substring ranges, prefix behavior, and efficient counting techniques. 💡 Core Takeaways: Great exercise in string analysis and prefix-based reasoning Highlights how mathematical conditions influence algorithm design Reinforces handling frequency relationships inside a sliding or expanding window Efficient counting becomes essential due to potential O(n²) substrings 💻 Tech Stack: Java ⏱ Runtime: 115 ms (Beats 84.11%) 💾 Memory: 47 MB 🧠 Learnings: Strengthened understanding of substring behavior under unique constraints Refined thinking around optimizing brute-force patterns A good reminder of how theoretical conditions (like squaring zeros) change practical implementation choices 📈 Progress: Today’s problem significantly improved my intuition around constraint-based substring evaluation—valuable for more advanced algorithmic challenges ahead. #LeetCode #Java #Algorithms #SubstringProblems #DSA #ProblemSolving #CodingJourney #SoftwareEngineering #180DaysOfCode #LogicBuilding #LearningEveryday
To view or add a comment, sign in
-
-
✅Day 42 : Leetcode 154 - Find Minimum in Rotated Sorted Array-2 #60DayOfLeetcodeChallenge 🧩 Problem Statement You are given an array nums that is sorted in ascending order and then rotated between 1 and n times. The array may contain duplicates. Your task is to find and return the minimum element in the rotated sorted array. You must minimize the number of overall operations as much as possible. 💡 My Approach I used a modified binary search technique to handle both rotation and duplicates. Initialize two pointers — low = 0 and high = n - 1. Calculate the middle index mid = low + (high - low) / 2. Update the answer as ans = min(ans, nums[mid]). If nums[low] == nums[mid] && nums[mid] == nums[high], move both low++ and high-- to skip duplicates. If the left half is sorted (nums[low] <= nums[mid]), update the answer and move to the right half (low = mid + 1). Otherwise, move to the left half (high = mid - 1). Continue until low > high. This efficiently finds the minimum even when duplicates exist. ⏱️ Time Complexity Worst Case: O(n) — when many duplicates exist. Average Case: O(log n) — behaves like binary search when duplicates are few. #BinarySearch #LeetCode #RotatedArray #Java #DSA #ProblemSolving #CodingPractice #LeetCodeHard
To view or add a comment, sign in
-
-
💡 LeetCode 2859 – Sum of Values at Indices With K Set Bits 💡 Today, I solved LeetCode Problem #2859, a clever mix of bit manipulation and array traversal that emphasizes how understanding binary representations can simplify computational logic. ⚙️ 🧩 Problem Overview: You are given a list of integers nums and an integer k. Your task is to find the sum of all elements at indices whose binary representation contains exactly k set bits (1s). 👉 Examples: Input → nums = [5,10,1,5,2], k = 1 → Output → 13 (Indices 1 and 2 have one set bit → nums[1] + nums[2] = 10 + 3) 💡 Approach: 1️⃣ Loop through all indices in the list. 2️⃣ Use Integer.bitCount(i) to count the number of set bits in the binary representation of each index. 3️⃣ If it equals k, add nums[i] to the sum. 4️⃣ Return the final total. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Linear scan of the list. ✅ Space Complexity: O(1) — Constant space usage. ✨ Key Takeaways: Strengthened understanding of bit-level operations using Java’s built-in methods. Reinforced how binary logic often leads to elegant and concise solutions. Demonstrated the power of combining mathematical reasoning with simple iteration. 🌱 Reflection: Bit manipulation is one of the most underrated yet powerful tools in problem-solving. This problem shows how thinking in binary can make complex conditions crystal clear — and the solution clean, efficient, and elegant. 🚀 #LeetCode #2859 #Java #BitManipulation #DSA #ProblemSolving #CodingJourney #AlgorithmicThinking #CleanCode #DailyPractice #ConsistencyIsKey
To view or add a comment, sign in
-
-
#Day_27 Today’s problem was an interesting twist on binary search — “Find Peak Element” 🔍 Given an array of numbers, the task is to find an index i such that nums[i] is greater than its neighbors — basically, a peak element. At first glance, it seems like a simple linear scan could solve it in O(n). But I wanted to do better — and that’s where binary search comes in 💡 🧠 Approach We observe that: If nums[mid] > nums[mid + 1], it means we are on a descending slope, so the peak lies on the left side (including mid). Otherwise, we’re on an ascending slope, so the peak lies on the right side (after mid). Using this logic, we can shrink our search space by half in every iteration — a classic divide and conquer move 🔥 ⏱ Complexity Time: O(log n) Space: O(1) This is a great example of how binary search isn’t just for sorted arrays — it can also be applied to problems involving patterns or directional decisions. 💬 Every day of this challenge reinforces that problem-solving isn’t just about writing code — it’s about recognizing patterns, making logical deductions, and applying optimized thinking. #CodingJourney #LeetCode #BinarySearch #ProblemSolving #100DaysOfCode #Java #LearnByDoing
To view or add a comment, sign in
-
-
✅ Just solved LeetCode #654 — Maximum Binary Tree 📘 Problem: Given an integer array without duplicates, the task is to build a maximum binary tree. The construction rules are: 1️⃣ The root is the maximum element in the array. 2️⃣ The left subtree is built recursively from elements to the left of the maximum. 3️⃣ The right subtree is built recursively from elements to the right of the maximum. Example: Input → [3,2,1,6,0,5] Output → [6,3,5,null,2,0,null,null,1] 🧠 My Approach: I solved this problem using a recursive divide-and-conquer approach. 1️⃣ Find the index of the maximum element in the given range — this becomes the root. 2️⃣ Recursively build the left subtree from the subarray before the maximum element. 3️⃣ Recursively build the right subtree from the subarray after the maximum element. 💡 What I Learned: ✅ How recursion naturally fits into tree construction problems ✅ The concept of divide and conquer applied to array-based tree building ✅ How to translate problem definitions into direct recursive structure #LeetCode #Java #DSA #BinaryTree #CodingUpdate #LearningByDoing
To view or add a comment, sign in
-
-
Problem 27 : LeetCode 🎯 LeetCode Problem #645 Solved — Set Mismatch (Cyclic Sort Approach) 🧩 Today, I solved another interesting LeetCode Easy problem — “Set Mismatch”, which deepened my understanding of in-place sorting and index mapping using the Cyclic Sort technique. 🔍 Problem Overview Given an integer array nums where numbers are supposed to be from 1 to n, one number is duplicated, and one number is missing. The task: Find both numbers using O(n) time and O(1) space. 💡 My Approach — Cyclic Sort Technique I treated the array like a self-mapping structure where each number x should ideally be placed at index x - 1. If the current element isn’t in its correct place and its target isn’t already filled, I swap it. After the array is sorted in place, any index i where arr[i] != i + 1 indicates: arr[i] → the duplicate number i + 1 → the missing number ⚙️ Results ✅ Runtime: 3 ms — Beats 79.76% of Java submissions ✅ Memory: 47.45 MB — Beats 6.28% of submissions ✅ Complexity: O(n) time | O(1) space ✅ Status: Accepted ✅ (All 49 test cases passed) 🧩 Tech Stack Java | Cyclic Sort | Array Manipulation | In-Place Algorithm | DSA Another problem that reinforces my confidence in index-based logic and memory-efficient coding patterns — vital skills for backend and system optimization. #LeetCode #Java #ProblemSolving #CyclicSort #DataStructures #Algorithms #InPlaceAlgorithm #BackendDevelopment #SpringBoot #DSA #LearningInPublic #CodingJourney Question Url : https://lnkd.in/dixwjFE3
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