Day 36 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Uncommon Characters in Two Strings We were given two strings s1 and s2. Task was to find characters that are present in only one string. Not in both. Final result should be sorted 💻 Approach 🔹️Create two frequency arrays (or sets). 🔹️Traverse s1 and mark its characters. 🔹️Traverse s2 and mark its characters. 🔹️Now check each character from 'a' to 'z': ▪️If present in only one string → include it ▪️If present in both → skip it 🔹️Add valid characters to result string. 🔹️Sort the result. Simple comparison logic. --- 📊 Complexity Analysis Time Complexity: **O(n + m)** Space Complexity: **O(n + m)** --- 📚 What I learned today: ▫️Set/frequency based comparison is useful for string problems. ▫️Checking presence instead of count simplifies logic. ▫️Iterating over fixed character range helps in sorting automatically. ▫️Problem is more about filtering than processing. Day 36 completed. Understanding string comparison better 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
Day 36 of #50DaysOfCode: Uncommon Characters in Two Strings
More Relevant Posts
-
Day 97/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 456 – 132 Pattern(Medium) 🧠 Approach: Traverse the array from right to left while maintaining a stack. Use a variable to track the “middle” element (the ‘2’ in 132 pattern) and check if a valid pattern exists. 💻 Solution: class Solution: def find132pattern(self, nums: List[int]) -> bool: stack = [] third = float('-inf') for i in range(len(nums) - 1, -1, -1): if nums[i] < third: return True while stack and nums[i] > stack[-1]: third = stack.pop() stack.append(nums[i]) return False ⏱ Time | Space: O(n) | O(n) 📌 Key Takeaway: Using a monotonic stack while iterating backwards helps efficiently detect complex patterns in linear time. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 38 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Print Bracket Number We were given a string str. It contains brackets. Task was to assign a number to each bracket. Each pair gets the same number. Based on order of opening. Let’s understand it simply. ◾️Imagine you are assigning IDs to tasks. ◾️Every time a new task starts, you give it a new ID. ◾️When that task ends, it keeps the same ID. ◾️Multiple tasks can be nested. ◾️But each one has its own number. That’s exactly how brackets behave. 💻 Approach (Using Stack) 🔹️Create an empty stack. 🔹️Initialize a counter = 0. 🔹️Traverse the string. 🔹️If opening bracket: ▪️Increase counter ▪️Push it into stack ▪️Print the counter 🔹️If closing bracket: ▪️Take top value from stack ▪️Print it ▪️Pop from stack Each pair gets same number. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Stack helps in tracking nested structures. ▫️Assigning IDs during traversal simplifies pairing logic. ▫️LIFO nature perfectly matches bracket problems. ▫️Nested patterns are easier with stack-based thinking. Day 38 completed. Stack understanding getting stronger 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 37 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Second Most Repeated String in a Sequence We were given a list of strings. Task was to find the second most frequent string. Not the most frequent. The one just below it. 💻 Approach 🔹️Create a hash map to store frequency of each string. 🔹️Traverse the sequence and count occurrences. 🔹️Track the highest and second highest frequency. 🔹️Find the string with second highest count. 🔹️Return that string. Simple counting + comparison. 📊 Complexity Analysis Time Complexity: O(N * max(|Si|)) Space Complexity: O(N * max(|Si|)) 📚 What I learned today: ▫️Hash maps are very useful for frequency-based problems. ▫️Tracking second maximum needs careful comparison. ▫️One-pass counting + second pass evaluation works well. ▫️String problems often reduce to counting patterns. Day 37 completed. Getting more comfortable with hash maps 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
.Day 47 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Bracket Validity (Valid Parentheses) We were given a string s. It contains only brackets: (), {}, [] Task was to check whether the string is valid. Valid means: ✔️ Same type of brackets ✔️ Correct order ✔️ Every opening has a matching closing 💻 Approach (Using Stack) 🔹️Create an empty stack. 🔹️Traverse the string. 🔹️If opening bracket → push into stack. 🔹️If closing bracket: ▪️Check if stack is empty → invalid ▪️Check top of stack ▪️If matching → pop ▪️Else → invalid 🔹️At the end, stack should be empty. If empty → valid Else → not valid 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Stack is the best fit for bracket matching problems. ▫️Checking empty stack avoids runtime errors. ▫️Matching pairs logic must be handled carefully. ▫️Order of brackets is more important than count. Day 47 completed. Revising stack patterns again 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 30 of Solve With Me: Today’s problem: Reverse String (LeetCode 344). We are given a character array s. Our task is to reverse the array in-place (without using extra space). What is the idea? We swap characters from the beginning and end moving toward the center. Approach (Two Pointer ) Initialize two pointers: start = 0 end = s.length - 1 Traverse till the middle: Swap s[start] and s[end] Increment start Decrement end Stop when start >= end Why this works ? Each swap places characters in their correct reversed position. Only half traversal is needed since we fix two positions in one step. Example: Input : s = ['h','e','l','l','o'] Step 1 : swap h ↔ o → ['o','e','l','l','h'] Step 2 : swap e ↔ l → ['o','l','l','e','h'] Output : ['o','l','l','e','h'] #leetcode #problemsolving #dsa #codingpractice #day30
To view or add a comment, sign in
-
-
🚀 Day 68 of #100DaysOfCode 🔥 Solved Median of Two Sorted Arrays (LeetCode Q4) today! 💡 Problem Insight: Find the median of two sorted arrays in an efficient way without merging them. 🧠 Approach: - Use Binary Search on the smaller array - Partition both arrays such that left side has smaller elements and right side has larger ones - Ensure correct balance of elements on both sides ⚙️ Algorithm: - Apply binary search to find correct partition - Check conditions for valid split - If valid → calculate median based on total length - Else → adjust search space ⏱️ Complexity: - Time: O(log(min(n, m))) - Space: O(1) 📌 Key Learning: Brute force is not always the answer — smart partitioning can optimize everything. 💬 Think smart, not hard. #DSA #LeetCode #BinarySearch #100DaysOfCode #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 66 of #100DaysOfCode Today, I solved LeetCode 73 – Set Matrix Zeroes, a classic problem that tests in-place matrix manipulation and optimization techniques. 💡 Problem Overview: Given a matrix, if any cell contains 0, its entire row and column must be set to 0. The challenge is to perform this efficiently without using excessive extra space. 🧠 Approach: To solve this optimally, I focused on: ✔️ Using the first row and first column as markers ✔️ Tracking whether the first row/column initially contained zero ✔️ Updating the matrix in-place based on these markers This avoids using additional space and achieves optimal performance. ⚡ Key Takeaways: In-place algorithms help reduce space complexity Using matrix itself as storage is a powerful optimization trick Handling edge cases (first row/column) is critical 📊 Complexity Analysis: Time Complexity: O(n × m) Space Complexity: O(1) Improving problem-solving skills one day at a time 🚀 #LeetCode #100DaysOfCode #DSA #Matrix #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
🚀 DSA Day 48 – LeetCode Problem 435: Non-overlapping Intervals Today’s problem was a great example of applying a Greedy Algorithm effectively 🧠 🔍 Problem Insight: We are given a set of intervals, and the goal is to remove the minimum number of intervals so that the rest do not overlap. 💡 Key Idea: Sort intervals based on their end time Always pick the interval that finishes earliest If the next interval overlaps, we remove it Otherwise, we include it and move forward ⚡ Why this works? Choosing the interval with the earliest end time leaves more room for upcoming intervals — a classic greedy strategy for optimal selection. 🧠 What I Learned: How greedy algorithms simplify complex problems Importance of sorting in interval-based questions Making optimal local choices to achieve global optimum 💻 Time Complexity: O(n log n) (due to sorting) 📦 Space Complexity: O(1) (excluding input) Another day, another concept mastered 💪 — consistency is compounding! #DSA #LeetCode #GreedyAlgorithm #CodingJourney #100DaysOfCode #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 LeetCode Update: “Sort Colors” Problem Solved! I recently solved the **Sort Colors** problem and got it accepted ✅ (89/89 test cases passed). Here’s a quick breakdown of my approach 👇 🧠 Problem Insight • The array contains only 0s, 1s, and 2s • Goal: sort them in-place without using extra space ⚙️ Approach Used: Dutch National Flag Algorithm • Maintained three pointers: low, mid, high • Divided the array into three regions: * 0s → left side * 1s → middle * 2s → right side • Traversed the array once and swapped elements accordingly 📈 Time & Space Complexity • Time Complexity: O(n) • Space Complexity: O(1) (in-place sorting) 💡 Key Learning • Efficient use of pointers can eliminate the need for extra space • Classic problems often have optimal patterns worth mastering 🔥 Always exciting to see how a simple-looking problem can teach powerful concepts! #LeetCode #DSA #CodingJourney #Cpp #ProblemSolving
To view or add a comment, sign in
-
-
Continuing my 100 Days of DSA journey. Day 69 — LeetCode (Balanced Binary Tree) Balanced Binary Tree – Given a binary tree, determine if it is height-balanced (i.e., the heights of left and right subtrees of every node differ by no more than 1). Approach (DFS + Height Optimization): a) Use a recursive function to calculate the height of each subtree b) For each node, recursively get the height of left and right subtrees c) If any subtree returns -1, propagate -1 upwards (indicating imbalance) d) Check if the absolute difference between left and right heights is greater than 1 e) If unbalanced, return -1 immediately f) Otherwise, return 1 + max(leftHeight, rightHeight) Time Complexity: O(n) Space Complexity: O(h) (recursion stack) On to Day 70... #100DaysOfCode #DSA #LeetCode #Cpp #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #Greedy #Strings #Optimization
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