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
Second Most Frequent String in Sequence
More Relevant Posts
-
🚀 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 70 of #100DaysOfCode 📌 LeetCode Q3: 3Sum 💡 Problem: Find all unique triplets in the array which gives the sum of 0. 🧠 Approach I Used: - First, sorted the array - Fixed one element - Applied two-pointer technique for the remaining part - Skipped duplicates to avoid repeated triplets ⚡ Key Insight: Instead of brute force O(n³), using sorting + two pointers reduces it to O(n²) ❗ Edge Cases Handled: - Duplicate values - No valid triplets - Negative + positive mix ⏱ Complexity: - Time: O(n²) - Space: O(1) (excluding result) 🔥 Takeaway: Two-pointer + sorting = deadly combo for array problems 💯 💬 Open to feedback & better approaches! #Day70 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 46 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Geometric Sum using Recursion We were given an integer n. Task was to find the sum: 1 + 1/3 + 1/3² + ... + 1/3ⁿ Using recursion. 💻 Approach 🔹️Define a recursive function sum(n). 🔹️Base case: ▪️If n == 0 → return 1 🔹️Recursive case: ▪️Return sum(n-1) + 1/(3ⁿ) Each call adds one term. And moves toward smaller n. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion can be used for summation of series. ▫️Each recursive call adds one term to the result. ▫️Understanding base case is important to stop recursion. ▫️Power calculations are common in series problems. Day 46 completed. Getting more comfortable with recursive formulas 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 83 of #100DaysOfCode Today I solved "Binary Tree Maximum Path Sum" on LeetCode using DFS + Recursion. Key Idea: At every node, we calculate the maximum path sum passing through it. But here’s the twist We ignore negative paths because they reduce the total sum. Approach: • Recursively get the max path sum from left and right subtrees • Ignore negative values using max(0, …) • Update the global answer as: root->val + left + right • Return to parent: root->val + max(left, right) This ensures we consider both: Path passing through the node Path extending upwards Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Greedy choice (ignore negative paths) Time Complexity: O(n) Space Complexity: O(h) This problem really sharpened my understanding of handling multiple path possibilities in trees From simple traversals to advanced patterns — growth is visible #Day83 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
-
Day 92/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 347 – Top K Frequent Elements(Medium) 🧠 Approach: Count the frequency of each element using a hashmap, then sort the elements based on frequency in descending order and pick the top k. 💻 Solution: class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: freq = {} for num in nums: freq[num] = freq.get(num, 0) + 1 sorted_items = sorted(freq.items(), key=lambda x: x[1], reverse=True) return [item[0] for item in sorted_items[:k]] ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Hashmaps combined with sorting provide a simple way to solve frequency-based problems, though heaps or bucket sort can optimize performance further. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 76 of #100DaysOfCode Today I solved "All Nodes Distance K in Binary Tree" on LeetCode using a DFS + Backtracking approach. Key Idea: We need to find all nodes at distance K from a given target node — not just in its subtree, but also through its ancestors. Approach: • First, locate the target node using DFS • From target → collect nodes in its subtree at distance K • While backtracking: Track distance from current node to target Check if current node is at distance K Explore the opposite subtree for remaining distance This allows us to cover both downward and upward paths in the tree. Concepts Used: • Binary Trees • Depth First Search (DFS) • Backtracking • Tree traversal Time Complexity: O(n) Space Complexity: O(h) This problem really improved my understanding of handling tree paths beyond simple parent-child traversal Every day, a new pattern unlocked. #Day76 #100DaysOfCode #LeetCode #BinaryTree #DFS #Backtracking #Cpp #CodingJourney
To view or add a comment, sign in
-
-
Day 36 – #100DaysOfLeetCode Challenge Today I worked on the problem “Subarray Sum Equals K.” Problem Overview: Given an array of integers and an integer k, the task is to find the total number of continuous subarrays whose sum equals k. Example: Input: nums = [1, 1, 1], k = 2 Output: 2 Explanation: The subarrays [1,1] (from index 0→1 and 1→2) both sum to 2. Approach – Prefix Sum + HashMap To solve this efficiently: 🔹 Use a running sum (prefix sum) while iterating through the array 🔹 Store the frequency of prefix sums in a HashMap 🔹 At each step, check if (current_sum - k) exists in the map 🔹 If it exists, add its frequency to the count Time Complexity: O(n) Space Complexity: O(n) Key Learning: This problem highlights how prefix sums combined with hashing can drastically optimize problems involving subarrays and cumulative sums. Day 36 of my #100DaysOfLeetCode journey — staying consistent and improving problem-solving skills one day at a time!
To view or add a comment, sign in
-
-
🔥 Day 171 of My LeetCode Journey Problem 112: Path Sum 💡 Problem Insight: Today’s problem was about checking whether a binary tree has a root-to-leaf path whose sum equals a target value. The key detail here is root-to-leaf — not any path. Missing that leads to wrong answers. 🧠 Concept Highlight: The solution is a clean use of DFS (recursion): Subtract the current node’s value from the target Move to left and right subtrees When you reach a leaf, check if the remaining sum is zero This ensures you explore all valid paths without unnecessary work. 💪 Key Takeaway: Tree problems often reduce to accumulating state along a path. Instead of storing paths, update the condition as you traverse. ✨ Daily Reflection: This problem reinforced how recursion naturally fits tree traversal. Once you think in terms of paths and state, the solution becomes straightforward. #Day171 #LeetCode #BinaryTree #DFS #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 38 Today I solved: Majority Element (LeetCode 169) 💡 Problem: Given an array, find the element that appears more than [n/2] times. You can assume that the majority element always exists. 💡 My Approach: I used a HashMap (frequency counting) approach: 1️⃣ Traverse the array and store frequency of each element 2️⃣ Calculate n/2 3️⃣ Iterate through the map 👉 Return the element whose frequency is greater than n/2 💡 Key Insight: The majority element will always dominate the count (> n/2), so once counted, it’s easy to identify ✅ ⚡ Complexity: Time: O(n) Space: O(n) #LeetCode #DSA #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 64 of #100DaysOfCode Today, I solved LeetCode 290 – Word Pattern, a problem that focuses on pattern matching and mapping relationships. 💡 Problem Overview: Given a pattern and a string, the task is to determine if the string follows the same pattern, ensuring a one-to-one mapping between characters in the pattern and words in the string. 🧠 Approach: To solve this problem efficiently, I focused on: ✔️ Using a hashmap to map pattern characters to words ✔️ Ensuring a bijection (one-to-one mapping) between pattern and words ✔️ Validating consistency throughout the traversal This approach ensures correctness while maintaining simplicity. ⚡ Key Takeaways: Hashmaps are powerful for mapping relationships Ensuring bijection is crucial in pattern problems Clean validation logic avoids edge-case errors 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Building strong fundamentals one problem at a time 🚀 #LeetCode #100DaysOfCode #DSA #HashMap #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
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