📌 Day 33/100 – Check If Digits Are Equal in String After Operations (LeetCode 3461) 🔹 Problem: Given a string s consisting of digits, repeatedly replace it by a new string formed by taking the sum (mod 10) of every pair of adjacent digits until only two digits remain. Return true if the final two digits are the same, otherwise false. 🔹 Approach: Iteratively built a new string using adjacent digit sums modulo 10. Repeated the process until the string length reduced to 2, then compared the final digits. Used StringBuilder for efficient construction of intermediate strings. 🔹 Key Learning: Reinforced clean looping and string handling patterns in Java. 🔹 Complexity: Time: O(n²) — Each iteration processes a smaller string. Space: O(n) for intermediate string storage. #100DaysOfCode #LeetCode #Java #StringManipulation #DSA #ProblemSolving #CodingPatterns #Iteration #ModularArithmetic
How to Check if Digits Are Equal in a String After Operations (LeetCode 3461)
More Relevant Posts
-
📌 Day 13/100 - Valid Anagram (LeetCode 242) 🔹 Problem: Given two strings s and t, determine whether t is an anagram of s. An anagram is formed by rearranging the letters of one word to create another word — meaning both strings must have the same characters with the same frequency. 🔹 Approach: First, check if both strings are of equal length — if not, they can’t be anagrams. Convert both strings into character arrays. Sort both arrays and compare them using Arrays.equals(). If both sorted arrays are identical, the strings are anagrams. 🔹 Key Learning: Sorting can simplify comparison-based string problems. Always check base conditions (like length) to avoid unnecessary computation. This approach has a time complexity of O(n log n) due to sorting, which is efficient enough for this problem. Every solved challenge is another letter added to the dictionary of progress! 🚀 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode #2744 — Find Maximum Number of String Pairs 📘 Problem: You’re given an array of distinct strings. We need to count how many pairs (i, j) can be formed such that the string at index i is the reverse of the string at index j. Each string can only belong to one pair. Example: Input → ["cd", "ac", "dc", "ca", "zz"] Output → 2 Explanation → ✅ "cd" ↔ "dc" ✅ "ac" ↔ "ca" 🧠 My Approach: I used a HashSet to efficiently track reversed strings. 1️⃣ For each word, I created its reversed version. 2️⃣ If the reversed version already exists in the set, I counted a valid pair and removed it from the set. 3️⃣ Otherwise, I added the word to the set for future checks. 💡 What I Learned: ✅ How HashSet helps reduce time complexity for lookup and removal ✅ How to reverse strings efficiently using StringBuilder ✅ Strengthened logic-building for string manipulation and pairing problems 💻 Language Used: Java 🔍 Concept: HashSet | String Manipulation | Two-Pointer Logic #LeetCode #Java #DSA #String #HashSet #CodingUpdate #LearningByDoing #Programming
To view or add a comment, sign in
-
-
✅ Day 57/100 — LeetCode Challenge Problem: Transpose Matrix Language: Java Today I worked on a classic matrix operation — transposing a matrix. The goal is to convert rows into columns and vice-versa. This problem reinforced my understanding of 2D arrays and index manipulation in Java. 💡 Key Idea: If matrix has dimensions m x n, the transpose will have dimensions n x m, and each element at (i, j) becomes (j, i). 📌 Approach: Calculate row & column length Create result matrix with swapped dimensions Iterate & swap positions accordingly #100DaysOfCode #LeetCode #Java #DSA #Matrix #TechJourney #CodingChallenge #SoftwareEngineering #LearningEveryday
To view or add a comment, sign in
-
-
🚀#PostLog35 🧩 Problem: Frequency of the Most Frequent Element (LeetCode #1838) 🔹 Topic: Sliding Window 🔹 Language: Java Challenge was about maximizing the frequency of an element after performing at most k increment operations. The key idea was to use a sliding window combined with sorting: Sort the array to align potential targets. Expand the window while the total operations needed ≤ k. If it exceeds k, shrink the window from the left. Track the maximum frequency achievable. 💡 This approach efficiently balances elements using prefix sums and window logic — no need for nested loops or complex math tricks. ✅ Result: Accepted (Runtime: 33 ms) Another problem done — one step closer to mastering array and window patterns! #LeetCode #Java #CodingJourney #ProblemSolving #DSA
To view or add a comment, sign in
-
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
📌 Day 12/100 - Concatenation of Array (LeetCode 1929) 🔹 Problem: Given an integer array nums, create a new array ans such that: ans[i] = nums[i] ans[i + n] = nums[i] where n is the length of nums. In short, we need to concatenate the array with itself to form a new array of size 2n. 🔹 Approach: First, determine the length n of the array. Create a new array newArray of size 2n. Loop through nums once: Assign each element twice — once at position i and once at position i + n. Finally, return the concatenated array. 🔹 Key Learning: Reinforced the concept of array indexing and iteration. Practiced efficient array manipulation in Java. Sometimes, the simplest logic is the cleanest — clarity beats complexity! 💡 Every solved problem adds a layer of confidence and consistency 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing
To view or add a comment, sign in
-
-
📌 Day 20/100 – Add Binary (LeetCode 67) Today’s challenge was about adding two binary strings and returning the result in binary format — just like simulating manual binary addition with carry logic. 🔹 Problem: Given two binary strings a and b, return their sum as a binary string without converting them into decimal. 🔹 Approach: Start from the end of both strings (like column-wise addition). Use a carry variable to handle overflow (0 or 1). Keep appending the result (sum % 2) to a StringBuilder. Reverse the string at the end since we append from LSB to MSB. 🔹 Key Learnings: StringBuilder is more efficient than string concatenation in Java. Handling indices carefully avoids edge-case bugs. Binary addition logic is similar to decimal addition — just base changes, logic stays. #100DaysOfCode #Day20 #LeetCode #Java #BinaryMath #DSA #ProblemSolving #CodingJourney #KeepLearning
To view or add a comment, sign in
-
-
📌 Day 27/100 - Generate Parentheses (LeetCode 22) 🔹 Problem: Given n pairs of parentheses, generate all combinations of well-formed (balanced) parentheses. 🔹 Approach: Use backtracking to build strings character-by-character. Keep two counters: open = number of '(' used, close = number of ')' used. You may add '(' while open < n. You may add ')' while close < open (to maintain balance). When the current string length reaches 2*n, add it to the result list. 🔹 Complexity: Time: proportional to the number of valid combinations (Catalan number) — roughly O(4ⁿ / n^(3/2)). Space: output-sensitive — O(n * Cn) for storing results, and O(n) extra for recursion depth. 🔹 Key Learning: Backtracking is ideal when you need to enumerate valid combinations subject to constraints. Always enforce constraints early (here: close < open) to prune invalid branches. Think in terms of state (open/close counts) rather than raw string manipulation. #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA
To view or add a comment, sign in
-
-
🚀Day 99/100 #100DaysOfLeetCode 🔍Problem: Sum of Two Integers✅ 💻Language: Java 💡Approach: Instead of using the ‘+’ or ‘–’ operators, this problem leverages bit manipulation to perform addition. 🔸Use XOR (^) to calculate the sum without carry. 🔸Use AND (&) followed by a left shift (<< 1) to calculate the carry. 🔸Repeat until no carry remains. 📚Key Takeaways: 🔹Reinforced understanding of bitwise operations. 🔹Learned how addition can be simulated using logical operations. 🔹Improved understanding of low-level arithmetic computation. ⚡Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 40.88 MB (Beats 10.05%) #100DaysOfLeetCode #Java #BitManipulation #CodingChallenge #ProblemSolving #DSA #LeetCode #CodingJourney
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