𝗗𝗮𝘆 𝟭𝟬/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Solved Roman to Integer using HashMap + Single Traversal. ➤ Approach (O(n), O(1) space): • Store Roman symbols and their values in a HashMap • Traverse the string from left to right • If the current value is less than the next value → subtract • Otherwise → add ➤ Key Insight: Roman numerals mostly add up left to right, but when a smaller value appears before a larger one, it indicates subtraction (like IV, IX, XL). By checking the next character during traversal, we can decide whether to add or subtract — all in one pass. #LeetCode #Java #DSA #HashMap #StringManipulation #ProblemSolving #20DaysChallenge #Consistency
LeetCode Challenge: Roman to Integer Conversion with HashMap
More Relevant Posts
-
Day 20 - Find Lucky Integer in an Array Technique Used: HashMap Frequency Counting Key Idea: Constructed a frequency map to count occurrences of each element. Iterated through the map to identify elements whose value equals their frequency, and returned the maximum among them. Time Complexity: O(n) #Day20 #LeetCode #Java #DSA #HashMap #ProblemSolving
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟭𝟰/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Solved First Unique Character in a String using HashMap (Frequency Counting). ➤ Approach (O(n), O(1) space): • First pass: Count frequency of each character using a HashMap • Second pass: Traverse the string again and return the first character with frequency = 1 • If none found → return -1 ➤ Key Insight: Instead of checking each character repeatedly (which would be O(n²)), store frequencies once and reuse them. #LeetCode #Java #DSA #HashMap #StringProblems #ProblemSolving #20DaysChallenge #Consistency
To view or add a comment, sign in
-
-
🚀 Day 11 of #100DaysOfCode Solved Find Minimum in Rotated Sorted Array on LeetCode using Binary Search 🔄 🧠 Key insight: In a rotated sorted array, at least one half is always sorted. By comparing the middle element with the right boundary, we can determine which half contains the minimum and safely discard the other. ⚙️ Approach: 🔹Use binary search on the array 🔹Compare nums[mid] with nums[right] 🔹If nums[mid] > nums[right] → minimum lies in the right half 🔹Else → minimum lies in the left half (including mid) ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 23 of #100DaysOfCode 🌱 Topic: Strings / Hashing / Sliding Window ✅ Problem Solved: LeetCode 1461 – Check If a String Contains All Binary Codes of Size K 🛠 Approach: Generated all substrings of length k using sliding window. Stored each substring inside a HashSet to track uniqueness. Compared set size with 2^k to check if all possible binary codes exist. Used bit manipulation concept (1 << k) to calculate total combinations. ⏱ Time Complexity: O(n * k) 📦 Space Complexity: O(2^k) #100DaysOfCode #Day23 #DSA #Strings #Hashing #BitManipulation #Java #LeetCode #ProblemSolving #CodingJourney #Consistency #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 96 of #100DaysOfCode Solved LeetCode #1461 – Check If a String Contains All Binary Codes of Size K ✅ A solid mix of sliding window + bit manipulation, where efficiency really matters. Key Takeaways: -> Using rolling hash / bitmask to track binary substrings -> Avoiding substring overhead for better performance -> Understanding the limit: total required codes = 2^k -> Early pruning with length checks for optimization Language: Java -> Runtime: 6 ms (Beats 100%) ⚡ -> Memory: 47.73 MB Almost at the finish line — one binary string at a time 💻🔥 #LeetCode #Java #BitManipulation #SlidingWindow #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 86 of #100DaysOfCode Solved LeetCode Problem #3714 – Longest Balanced Substring II ✅ This problem builds on Part I and demands a more optimized approach to track balance efficiently across the string. A great exercise in combining prefix-state tracking with hashing to avoid brute force. Key Takeaways: -> Using state compression to represent balance conditions -> Leveraging HashMap to store first occurrences for maximum length -> Thinking in terms of prefix differences rather than substrings -> Optimizing time complexity with smart observations Language: Java -> Runtime: 308 ms (Beats 77.17%) -> Memory: 156.78 MB Consistency compounds. One day, one problem. 💻🔥 #LeetCode #Java #DataStructures #Strings #HashMap #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 29 of #100DaysOfCode Solved 442. Find All Duplicates in an Array on LeetCode ✅ 🧠 Key Insight: Since numbers are in the range 1 → n, each number ideally belongs at index num - 1. By repeatedly swapping elements into their correct positions (cyclic sort), duplicates naturally reveal themselves. ⚙️ Approach Used: 🔹Place each element at its correct index (nums[i] → nums[nums[i] - 1]) 🔹Skip when the element is already in the correct position 🔹After rearrangement, any index i where nums[i] ≠ i + 1 is a duplicate ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) #100DaysOfCode #LeetCode #DSA #Arrays #CyclicSort #Java #ProblemSolving #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟭𝟳/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Solved Isomorphic Strings using a HashMap for character mapping. ➤ Approach (O(n), O(n) space): • If lengths are different → return false • Traverse both strings together • Map each character from s to t • If a mapping already exists, ensure it matches • Also ensure two characters from s don’t map to the same character in t ➤ Key Insight: Isomorphic means maintaining a one-to-one mapping. The mapping must be consistent and unique. ➤ Two checks matter: • Existing mapping should match • No two characters map to the same target #LeetCode #Java #DSA #HashMap #StringProblems #ProblemSolving #20DaysChallenge #Consistency
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟭𝟯/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 🎯 Solved Two Sum using HashMap for constant-time lookup. ➤ Approach (O(n), O(n) space): • Traverse the array once • For each element, calculate complement = target - nums[i] • Check if complement already exists in the map • If yes → return the stored index and current index • Otherwise, store the current number with its index ➤ Key Insight: Instead of checking every pair (O(n²)), store what you’ve seen and look up what you need. This reduces the problem to a single pass. #LeetCode #Java #DSA #HashMap #ProblemSolving #20DaysChallenge #Consistency
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode – Day 12 Solved Search in Rotated Sorted Array II on LeetCode 🔄🔍 🧠 Key insight: When duplicates are present, it’s not always possible to directly identify the sorted half. If nums[left] == nums[mid], we can safely move left++ to reduce the search space and continue. ⚙️ Approach: 🔹Use modified binary search 🔹Handle duplicates by skipping equal boundary elements 🔹Identify the sorted half 🔹Check if the target lies in that range and adjust pointers accordingly ⏱️ Time Complexity: Average: O(log n) Worst case (many duplicates): O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #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