🌟 Day 25 of #100DaysOfCode 🌟 🔍 Equal Character Frequency — Checking if All Characters Occur Equally 🔹 What I Solved Today, I solved the “Check if All Characters Have Equal Occurrences” problem — a simple yet insightful exercise in string manipulation and frequency analysis. 📝 Problem Statement Given a string s, return true if all characters that appear in s have the same number of occurrences. Otherwise, return false. ✅ Example 1: Input: s = "abacbc" Output: true Explanation: All characters ('a', 'b', 'c') occur twice. ✅ Example 2: Input: s = "aaabb" Output: false Explanation: 'a' appears 3 times, 'b' appears 2 times. Constraints: 1 ≤ s.length ≤ 1000 s consists of lowercase English letters. 🧠 Concepts Used Frequency Counting Array Manipulation Conditional Checking ⚙️ Approach Create an integer array of size 26 to store character counts. Count the frequency of each character. Identify the first non-zero frequency. Verify that all other non-zero frequencies match this one. Return true if all are equal, otherwise false. 🚀 What I Learned This problem reminded me that even simple problems can sharpen logical reasoning. Understanding how to work with frequency maps and character arrays is crucial for tackling many string-related challenges efficiently. Feeling great to be back in rhythm and pushing forward in my #100DaysOfCode journey! #100DaysOfCode #ProblemSolving #Java #DataStructures #Algorithms #CodingJourney
Solved "Equal Character Frequency" problem in #100DaysOfCode
More Relevant Posts
-
🚀 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
-
-
🌟 Day 26 of #100DaysOfCode 🌟 🔍 Remove Duplicate Letters — Lexicographically Smallest Unique String 🔹 What I Solved Today, I tackled the “Remove Duplicate Letters” problem — a fascinating challenge that combines stack operations, greedy logic, and lexicographical ordering. It’s a perfect test of both analytical and implementation skills. 📝 Problem Statement Given a string s, remove duplicate letters so that every letter appears once and only once. You must ensure the resulting string is the smallest in lexicographical order among all possible results. ✅ Example 1: Input: s = "bcabc" Output: "abc" ✅ Example 2: Input: s = "cbacdcbc" Output: "acdb" Constraints: 1 ≤ s.length ≤ 10⁴ s consists of lowercase English letters 🧠 Concepts Used Stack Greedy Algorithm HashMap / Frequency Counting Character Visitation Tracking ⚙️ Approach Count the frequency of each character using a map. Use a stack to build the result string. Iterate through each character: Decrease its frequency (as it’s now visited). If the character is already in the stack, skip it. Otherwise, while the current character is smaller than the top of the stack and the top of the stack will appear later again, pop it out to maintain lexicographical order. Push the current character into the stack. Convert the stack to the final result string. 🚀 What I Learned This problem beautifully demonstrates how greedy thinking and data structures like stacks can work together to maintain order and constraints. It deepened my understanding of how lexicographical optimization problems can be efficiently solved using character frequency and conditional popping. #100DaysOfCode #ProblemSolving #Java #DataStructures #Algorithms #CodingJourney #GeeksforGeeks #KeepLearning
To view or add a comment, sign in
-
-
✅Day 81 of #100DaysOfLeetCode 1.📌Problem: Given an integer n n and a list of queries, return the final n×n n×n matrix after performing increment operations. Each query defines a submatrix to increment all its elements by one. 2.🟠 Difficulty: Medium 3.📍Topic: Matrix, Prefix Sum 4.🎯 Goal: For each query, add 1 to all elements in the submatrix from (row1,col1) (row1,col1) to (row2,col2) (row2,col2) and return the matrix after all queries. 5.🧠key idea: Approach 1: Brute-force. For every query, iterate through all cells in the defined submatrix and increment by 1. After processing all queries, return the resulting matrix. #LeetCode #100DaysChallenge #CodingChallenge #Matrix #Java #ProblemSolving #Algorithm #DataStructures #Tech #WomenWhoCode #LearnToCode #DailyCode #CodeNewbie #Developer #InterviewPrep
To view or add a comment, sign in
-
-
✅ Day 68 of LeetCode Medium/Hard Edition Today’s challenge was “Number of Ways to Form a Target String Given a Dictionary” — a brilliant Dynamic Programming and Combinatorics problem that tests precision in transitions and precomputation logic 🧩⚙️ 📦 Problem: You’re given an array of equal-length strings words and a target string target. You must form target from left to right by picking characters from the columns of words under these rules: 1️⃣ Once you use column k from any word, all columns ≤ k in every word become unusable. 2️⃣ You can use multiple characters from the same word, respecting column progression. Return the number of ways to form target modulo 1e9 + 7. 🔗 Problem Link: https://lnkd.in/gns9CwWa ✅ My Submission: https://lnkd.in/g7bsgZq9 💡 Thought Process: This problem is a clever mix of frequency compression and DP memoization. We precompute a frequency table freq[26][m], where each cell represents how many words contain a given letter at column m. Then, using recursion with memoization: 🎯 At each step (i, j) Either use freq[target[i]][j] if it exists → multiply by ways for the next position (i+1, j+1) Or skip the current column → move to (i, j+1) The recurrence relation: dp[i][j] = freq[target[i]][j] * dp[i+1][j+1] + dp[i][j+1] All computations are done modulo 1e9 + 7. ⚙️ Complexity: ⏱ Time: O(26 * n + t * m) — efficient due to frequency precomputation 💾 Space: O(t * m) — for memoized DP table 💭 Takeaway: This challenge reinforced how precomputation and state optimization can transform a seemingly exponential recursion into an elegant polynomial-time solution 🚀 #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #Combinatorics #ProblemSolving #Java #CodingChallenge #DSA
To view or add a comment, sign in
-
-
🚩 Problem: 124. Binary Tree Maximum Path Sum 🔥 Day 52 of #100DaysOfLeetCode 🔍 Problem Summary: Given the root of a binary tree, return the maximum path sum. A path is any sequence of nodes where each pair is connected, and it does not have to pass through the root. A path may start and end anywhere in the tree. 🧠 Intuition: This problem is difficult conceptually, but the solution is surprisingly clean and short using DFS. At each node: Compute max path sum through left child Compute max path sum through right child The best upward path can only choose one side (left or right) But the global maximum might include both sides + current node So we: Maintain a global max path sum Return to parent only the max one-side path Update global max with left + right + current.val ⚙️ Performance: ⏱️ Runtime: 0 ms 🚀 💪 Beats: 100% of Java solutions 💾 Memory: 44.2 MB ⚡ (Beats 96.2% of users) 📊 Complexity: Time Complexity: O(n) Space Complexity: O(h) (height of tree) ✨ Key Takeaway: This problem teaches one of the most powerful patterns in tree problems: “Return one-side best gain, update global best for split paths.” Mastering this helps solve many advanced tree DP problems. Link:[https://lnkd.in/gsfQXVWi] #100DaysOfLeetCode #Day52 #Problem124 #BinaryTreeMaximumPathSum #TreeDFS #Recursion #Algorithms #DSA #Java #ProblemSolving #LeetCode #CodingChallenge #InterviewPreparation #CrackingTheCodingInterview #SoftwareEngineering #DataStructures #CodingCommunity #ArjunInfoSolution #CodeNewbie #Programming #TechCareers #CareerGrowth #DeveloperJourney #ZeroToHero #CodingIsFun #ComputerScience #JavaDeveloper #GameDeveloper #Unity #AI #MachineLearning
To view or add a comment, sign in
-
-
🚀 Problem 2: Reverse Integer 💡 Leetcode Problem No: 7 Today, I solved an interesting Leetcode-style problem that involves reversing an integer — while handling tricky cases like integer overflow 🔄 ✨ Challenge: Given an integer x, reverse its digits and return the reversed number. If reversing x causes the value to go outside the signed 32-bit integer range, return 0. 💻 Key Learnings: 🔹 Used Math.abs(x) to handle negatives elegantly 🔹 Applied overflow check using: if (rev > (Integer.MAX_VALUE - d) / 10) 🔹 Mastered modulus (%) and division (/) logic for digit extraction 🔹 Ensured both positive and negative numbers are correctly reversed 💙 Tip: Always consider edge cases and overflow conditions when working with integer manipulation problems. #Java #Coding #LeetCode #ProblemSolving #JavaDeveloper #ProgrammingChallenge #LeetcodeCoding
To view or add a comment, sign in
-
-
🚀 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
To view or add a comment, sign in
-
-
🚩 Problem: 169. Majority Element 🔥 Day 43 of #100DaysOfLeetCode 🔍 Problem Summary: Given an array nums, find the element that appears more than ⌊ n/2 ⌋ times. You may assume that the majority element always exists in the array. ✅ Approach 1: Using HashMap Count the frequency of each element using a HashMap and return the one that occurs most frequently. ✅ Approach 2 (Optimized): Boyer–Moore Voting Algorithm Maintain a candidate and count. Traverse the array: If count == 0, set candidate = num. If num == candidate, increment count, else decrement. Return the candidate. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ✨ Key Takeaway: The Boyer–Moore Voting Algorithm is a brilliant example of how a deep understanding of problem constraints can lead to an O(1) space solution — an essential pattern in algorithmic thinking. Link:[https://lnkd.in/gsc4XgbK] #100DaysOfLeetCode #Day43 #Problem169 #MajorityElement #BoyerMoore #Algorithms #DSA #Java #CodingChallenge #ProblemSolving #LeetCode #InterviewPreparation #DataStructures #TechCareers #ArjunInfoSolution #CodingCommunity #CodeNewbie #SoftwareEngineering #ZeroToHero #LearnToCode
To view or add a comment, sign in
-
-
💻 Day 75 of #100DaysOfCodingChallenge ✨ Problem: 560. Subarray Sum Equals K 📚 Category: Array Manipulation | Subarray Problems 💡 Approach: Brute Force 🧠 Language: Java 🔍 Problem Understanding: We’re given an integer array nums and an integer k. We need to count how many subarrays (continuous parts of the array) have a sum equal to k. Example: Input: nums = [1, 2, 3], k = 3 Output: 2 Explanation: [1,2] and [3] are the subarrays with sum 3. 🧠 Brute Force Approach: In the brute-force method, we check every possible subarray using two loops: 1️⃣ Start from each element as a subarray beginning. 2️⃣ Keep adding elements until the end, and check if the sum equals k. 3️⃣ If yes, increment the count. Although it’s not the most optimized, this approach helps build a strong foundation in understanding subarray logic. ⚙️ Complexity: Time Complexity: O(n²) Space Complexity: O(1) 🌱 Learning: This problem taught me how to approach subarray-based questions step-by-step — starting from brute force before moving toward optimized solutions like prefix sums + hashmaps. Building clarity in fundamentals always makes optimization easier later 🚀 #Day75 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #WomenInTech #DSA #ArrayManipulation
To view or add a comment, sign in
-
-
✅ Day 73 of LeetCode Medium/Hard Edition Today’s challenge was “K Inverse Pairs Array” — an elegant Dynamic Programming problem that combines combinatorics, recurrence optimization, and modular arithmetic ⚡💡 📦 Problem: Given two integers n and k, return the number of different arrays consisting of numbers from 1 to n such that there are exactly k inverse pairs. An inverse pair is [i, j] where 0 ≤ i < j < n and nums[i] > nums[j]. 🔗 Problem Link: https://lnkd.in/eqt3zX_D ✅ My Submission: https://lnkd.in/eX2ZyCCu 💡 Thought Process: This problem generalizes the concept of counting inversions across all permutations of 1..n. The key idea is to express dp[n][k] in terms of previously computed states using prefix-sum logic to reduce time complexity. We use the recurrence: dp[n][k] = dp[n][k - 1] + dp[n - 1][k] - (k >= n ? dp[n - 1][k - n] : 0) This formula cleverly builds on smaller subproblems by considering where the nth element can be inserted in permutations of size n-1. 🎯 Base Cases: dp[n][0] = 1 (sorted array, no inverse pairs) dp[1][k] = 0 for all k > 0 ⚙️ Complexity: ⏱ Time: O(n × k) 💾 Space: O(n × k) 🧩 Key Learnings: Deepened understanding of prefix-sum optimization in DP. Reinforced modular arithmetic handling (MOD = 10⁹ + 7). Learned how combinatorial recurrence can reduce nested loops. Strengthened recursive + memoized DP formulation in Java. #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #Recursion #Combinatorics #Java #DSA #ProblemSolving #KeepCoding #LearnEveryday
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