🚀 Day 73 of #100DaysOfCode Today I solved LeetCode 3346 – Maximum Frequency of an Element After Performing Operations I 🧩 This problem was all about logical range manipulation — figuring out how many elements could be converted into the same number when each element can be modified by ±k, but with a limited number of allowed operations. At first, it felt similar to the “most frequent element” sliding window problem, but the twist here was controlling how many elements can be changed, not just the total cost. After a few failed attempts (and a battle with edge cases 😅), I finally implemented a correct solution using the difference array + prefix sum approach. 💡 Key Takeaways: Think in terms of ranges, not just differences. Prefix-sum (difference map) logic is incredibly powerful for interval counting. Always recheck constraints — “number of operations” vs “total cost” makes a huge difference! Here’s a snippet from my final Java solution: int achievable = Math.min(running, same + numOperations); ans = Math.max(ans, achievable); It’s small details like these that make problem-solving such a rewarding process 💪 #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #DSA #LearningEveryday
Solved LeetCode 3346 with Java and prefix sum approach
More Relevant Posts
-
🚀 Just solved LeetCode 30 – Substring With Concatenation of All Words. 🧩 What was the problem? Given a string and a list of words (all same length), you have to find every starting index where all the words appear together as a continuous substring, in any order. Basically a sliding-window puzzle with fixed word sizes and frequency matching. 🛠️ What was my approach? • Counted all words using a map • Used multiple sliding windows based on word length • Expanded the window word by word • If a word appeared more than needed, I moved the left pointer forward • Added the index when the window matched every word exactly The key was treating the string in equal chunks, not character by character. 📚 What I learned Working with strings becomes much easier when you break the problem into predictable pieces. Managing window boundaries is the real challenge here, and walking through tiny examples helps more than you think. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode 648 – Replace Words. 🟩 What was the problem? You’re given a list of root words and a sentence. For every word in the sentence, you need to replace it with the shortest root that matches its prefix. If multiple roots match, you pick the smallest one. If none match, you leave the word as it is. 🛠️ What was my approach? • Grouped all roots in a HashMap based on their first character • Split the sentence into individual words • For each word, checked only the relevant roots (same starting character) • Picked the shortest matching root if multiple matched • Built the final updated sentence using a StringBuilder This avoided checking every root against every word and kept things pretty efficient. 📚 What I learned Working with strings becomes simpler when you organize the data around predictable patterns. Grouping roots by their first letter saved a lot of unnecessary comparisons. Small structural changes make the whole solution cleaner. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
✨ Day 57 of 100: Rotate List ✨ Today’s challenge was LeetCode 61 – Rotate List 🔄 Problem: Given the head of a linked list, rotate the list to the right by k places. Example: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Key Idea: To rotate the list: 1️⃣ Find the length of the linked list. 2️⃣ Connect the tail to the head to make it circular. 3️⃣ Calculate the new head position as length - (k % length) steps from the start. 4️⃣ Break the circle at the right point to get the rotated list. 💡 Key Takeaways: Strengthened understanding of linked list traversal and manipulation. Learned to handle edge cases like k larger than the list length efficiently using modulo. Practiced converting a circular list back into a normal one at the right node. 💬 Every day of this challenge reinforces how small logical tweaks — like using % to handle rotations — can make code elegant and efficient. #100DaysOfCode #LeetCode #Java #LinkedList #CodingChallenge #DSA #ProblemSolving #WomenWhoCode
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
-
-
💡 LeetCode 3467 – Transform Array 💡 Today, I solved LeetCode Problem #3467: Transform Array, which focuses on array manipulation and the use of conditional logic in Java — a neat problem that strengthens core programming fundamentals. ⚙️ 🧩 Problem Overview: You’re given an integer array nums. Your task is to: Replace even numbers with 0 Replace odd numbers with 1 Then, sort the transformed array in ascending order. 👉 Example: Input → nums = [4, 7, 2, 9] Output → [0, 0, 1, 1] 💡 Approach: 1️⃣ Iterate through the array. 2️⃣ Use a ternary operator to transform each element (even → 0, odd → 1). 3️⃣ Sort the array to arrange all zeros before ones. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n log n) — due to sorting. ✅ Space Complexity: O(1) — in-place transformation. ✨ Key Takeaways: Practiced logical thinking and ternary operations in Java. Strengthened understanding of array transformations and sorting. Reinforced the value of writing clean, concise, and efficient code. 🌱 Reflection: Even simple transformation problems like this one sharpen the habit of thinking algorithmically. Consistency in small challenges leads to big growth in problem-solving skills. 🚀 #LeetCode #3467 #Java #ArrayManipulation #LogicBuilding #ProblemSolving #CodingJourney #DSA #CleanCode #ConsistencyIsKey
To view or add a comment, sign in
-
-
🚀 Day 68 of #100DaysOfChallenge Today's problem: 3461. Check If Digits Are Equal in String After Operations I (LeetCode - Easy) This problem was a fun blend of pattern observation and modular arithmetic — a great reminder that even simple-looking questions can strengthen your logical flow and coding discipline on LeetCode. 🧩 Problem Overview: We’re given a string of digits, and in each step, we repeatedly calculate the sum of every pair of consecutive digits modulo 10, until only two digits remain. Finally, we check whether those two digits are equal. 💡 My Approach: Used a straightforward simulation approach — repeatedly computing new strings of digits using modular arithmetic until only two digits were left. It’s simple, direct, and performs efficiently for short strings. ⚙️ Language: Java ⚡ Runtime: 8 ms (Beats 72.03%) 💾 Memory: 44.67 MB (Beats 69.77%) ✅ Result: Accepted — 706 / 706 test cases passed Every daily problem adds another layer of precision and confidence. Consistency isn’t just about coding every day — it’s about learning something new with every attempt. 🌱 On to the next challenge 💪 #100DaysOfCode #LeetCode #ProblemSolving #Java #CodingChallenge #Programming #DeveloperJourney #LearningEveryday #TechMindset #Consistency
To view or add a comment, sign in
-
-
📌 Day 18/100 - Valid Palindrome (LeetCode 125) 🔹 Problem: Determine whether a string reads the same forward and backward, ignoring case and non-alphanumeric characters. 🔹 Approach: Implemented a two-pointer technique. Skipped all non-alphanumeric characters. Compared characters from both ends in lowercase. Returned true if all matched, otherwise false. 🔹 Key Learning: Two-pointer method keeps logic clean and efficient. Character handling is key when data isn’t uniform. Time complexity: O(n), Space complexity: O(1). Sometimes, solving elegantly is better than solving fast. ✨ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 95 of #100DaysOfCode 🧠 Solved "Fibonacci Number" in Java using a space-optimized iterative approach. 🔹 Problem: Given an integer n (0 ≤ n ≤ 30), compute the nth Fibonacci number where F(0)=0, F(1)=1 and F(n)=F(n-1)+F(n-2) for n>1. 🔹 Approach: • Handle base cases (n=0 or n=1). • Use two variables (prev=0, curr=1) and iterate from i=2 to n. • In each step compute next=prev+curr, then update prev=curr and curr=next. • Return curr as the result. 🔹 Key Learning: • Iterative dynamic programming with constant space is ideal when only the last two states are needed. • Avoid using full arrays when you don’t need all historical values. • Clear, readable, and efficient code works well in interviews and production alike. 🔹 Thanks to: • Dr Bharathi Raja N — Director of Training & Placement, Dhanalakshmi College of Engineering • Sreesairam V Sir — Mentor from Aptitude Guru Hem #DhanalakshmiCollegeOfEngineering #LeetCode #Java #100DaysOfCode #Day95 #DynamicProgramming #CodingJourney
To view or add a comment, sign in
-
-
💡 LeetCode 1929 – Concatenation of Array 💡 Today, I solved LeetCode Problem #1929: Concatenation of Array, a simple yet satisfying problem that tests your understanding of array manipulation and indexing in Java. ⚙️📊 🧩 Problem Overview: You’re given an integer array nums. Your task is to create a new array ans such that ans = nums + nums (i.e., concatenate the array with itself). 👉 Example: Input → nums = [1,2,1] Output → [1,2,1,1,2,1] 💡 Approach: 1️⃣ Find the length n of the given array. 2️⃣ Create a new array of size 2 * n. 3️⃣ Loop through nums once — place each element both at index i and index n + i. 4️⃣ Return the resulting array. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Single traversal of the array. ✅ Space Complexity: O(n) — For the concatenated array. ✨ Key Takeaways: Practiced index manipulation and array construction. Reinforced the importance of efficient iteration. A great warm-up problem that strengthens logical thinking and array fundamentals. 🌱 Reflection: Even the simplest problems build the foundation for solving more complex ones. Every bit of consistent practice helps in mastering problem-solving and clean coding habits. 🚀 #LeetCode #1929 #Java #ArrayManipulation #DSA #CodingJourney #CleanCode #ProblemSolving #AlgorithmicThinking #ConsistencyIsKey
To view or add a comment, sign in
-
-
💻 LeetCode 50 Days Challenge — Day 8: Median of Two Sorted Arrays Day 8 of my #LeetCode50DaysChallenge ✅ Today’s problem was about finding the median of two sorted arrays — Median of Two Sorted Arrays ✨ 🧩 Problem: Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays. The challenge was to merge them efficiently and then determine the middle value(s). 💡 Approach: I used Java 8 Streams to merge both arrays in a single line using IntStream.concat(), followed by Arrays.sort() to sort the combined array. Finally, I calculated the median by checking if the array length is even or odd. ⏱️ Time Complexity: O((m + n) log (m + n)) (due to sorting) 📊 Example: Input: nums1 = [1, 2], nums2 = [3, 4] Output: 2.5 Each day, I’m getting more comfortable with cleaner and modern Java techniques like Streams — small steps toward writing concise and efficient code 🚀 #LeetCode #CodingChallenge #Day8 #ProblemSolving #Java #SoftwareDevelopment #Consistency #50DaysOfCode
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