Hello dudes and dudettes!! 🚀 Day 17/150 — Solved LeetCode 13: Roman to Integer Today’s problem was a fun twist — not your usual numbers, but ancient ones 😄🏛️ Converting Roman numerals into integers sounds simple… until the rules start playing tricks on you. 🧠 What’s the Problem About? You’re given a Roman numeral string like: 👉 “III”, “IV”, “IX”, “MCMIV” And your job is to convert it into a normal integer. 💡 Initial Thought At first, I assumed: “Just map each symbol and keep adding.” And that works… sometimes. But then comes the twist 👇 🔥 The Catch Roman numerals don’t always follow simple addition. 👉 If a smaller value comes before a bigger value, you subtract instead of adding. Examples: IV = 5 - 1 = 4 IX = 10 - 1 = 9 That’s where things get interesting. 💥 The Breakthrough Moment Instead of overthinking, I simplified the logic to one powerful idea: Look at the next character. If the next value is bigger → subtract current Otherwise → add current That’s it. Just one small check completely solves the problem. ⚙️ How It Works Traverse the string from left to right Compare each character with the next Decide whether to add or subtract Keep updating the total Simple logic. Clean execution. 📊 Why This Problem Is Cool It mixes logic with pattern recognition Shows how a tiny condition can change the whole approach Teaches you to look ahead before deciding 😎 What I Learned Don’t assume rules are always straightforward Edge cases often define the real solution Breaking the problem into small decisions makes everything easier 🎯 Key Takeaway “Sometimes the answer isn’t in the current step… it’s in what comes next.” 🔥 Another step forward — learning to think, not just code. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
Roman to Integer LeetCode Solution
More Relevant Posts
-
Hello dudes and dudettes!! 🚀 Day 20/150 — Solved LeetCode 14: Longest Common Prefix Today’s problem looked simple on the surface… but turned out to be a great exercise in thinking systematically 😄 🧠 What’s the Problem About? You’re given a list of strings, and your task is to find the longest common prefix shared among all of them. In simple terms: 👉 “What is the longest starting part that every word has in common?” 💡 Example Input: ["flower", "flow", "flight"] All words start with: 👉 "fl" But after that: "flower" → o "flow" → o "flight" → i ❌ So we stop there. 🎯 Final answer: "fl" 🔥 The Catch At first, I thought: “Let me compare strings directly.” But the real trick is how you compare them. Instead of comparing whole words, I realized: 👉 Compare character by character (column-wise) 🧠 The Breakthrough Idea Think of the words like this: f l o w e r f l o w f l i g h t Now check: Column 1 → all f ✅ Column 2 → all l ✅ Column 3 → o, o, i ❌ 👉 Stop immediately. ⚙️ Approach That Worked Take the first word as a reference Loop through each character Compare that character with all other words If any mismatch → stop Otherwise → add it to the prefix 😎 Why This Problem Is Interesting It teaches you to break problems into smaller checks Shows how powerful a simple idea (column comparison) can be Reinforces the importance of stopping early when conditions fail 💡 What I Learned Don’t overcomplicate — start with the simplest structure Comparing step-by-step can be more effective than comparing everything at once Early exit conditions can save time and improve efficiency 🎯 Key Takeaway “You don’t need to compare everything — just stop at the first mismatch.” 🔥 Another step forward in the journey — learning to think clearly and solve efficiently. #LeetCode #Algorithms #Strings #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 18/150 — Solved LeetCode 12: Integer to Roman Today’s problem felt like stepping into history… and turning it into code 😄🏛️ At first, converting numbers into Roman numerals sounded straightforward. But once I got into it, I realized it’s less about memorizing symbols and more about thinking strategically. 🧠 What’s the Problem About? You’re given an integer, and you need to convert it into its Roman numeral representation. Simple idea… but Roman numerals follow unique rules: Some values are directly represented (like 1 → I, 5 → V) Some are combinations (like 4 → IV, 9 → IX) So it’s not just mapping — it’s about choosing the right combination. 💡 The Key Insight The breakthrough came when I stopped thinking of it as “conversion” and started thinking of it as a greedy process: Always pick the largest possible Roman value and subtract it. That’s it. 🔥 How It Works Imagine breaking a number step by step: For example, take 1994: 1000 → M → remaining = 994 900 → CM → remaining = 94 90 → XC → remaining = 4 4 → IV 🎯 Final answer: MCMXCIV Instead of guessing, we systematically reduce the number using the biggest possible values. ⚙️ Why This Approach Is Powerful It avoids unnecessary complexity It naturally handles special cases like 4 (IV) and 9 (IX) It guarantees the correct result using a consistent pattern 😎 What I Learned Problems become easier when you change how you look at them Greedy algorithms are incredibly effective when applied correctly Sometimes the best solution is just: 👉 “Take the biggest piece and move forward” 🎯 Key Takeaway “Don’t overcomplicate — break the problem into the largest meaningful steps.” 🔥 This problem was a great reminder that even ancient systems like Roman numerals can be solved with modern thinking. On to the next challenge 🚀 #LeetCode #Algorithms #Greedy #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 21/150 — Solved LeetCode 151: Reverse Words in a String Today’s problem was a great reminder that even something as simple as a sentence can hide a few tricky details 😄 At first glance, reversing words sounds easy… But once spaces start behaving weirdly, things get interesting. 🧠 What’s the Problem About? You’re given a string that contains words separated by spaces. Your task is to: 👉 Reverse the order of words 👉 Not the characters inside them 💡 Example Input: "the sky is blue" Output: 👉 "blue is sky the" 🔥 The Twist It’s not just about reversing words… The string might contain: Extra spaces at the beginning Extra spaces at the end Multiple spaces between words Example: " hello world " Expected Output: 👉 "world hello" So we also need to clean up the spaces while solving it. 🧠 The Thought Process Instead of overcomplicating things, I broke it down: Extract the words (ignore spaces) Reverse their order Join them back with a single space That’s it. Simple steps → clean solution. ⚙️ Why This Approach Works Splitting automatically removes extra spaces Reversing handles the order Joining ensures proper formatting No unnecessary checks. No messy conditions. 😎 Why This Problem Is Interesting It looks easy but tests your handling of edge cases Shows how built-in operations can simplify problems Reinforces the idea that clarity beats complexity 💡 What I Learned Clean input → clean output Breaking a problem into steps makes it easier Sometimes the best solution is the simplest one 🎯 Key Takeaway “Don’t fight the problem — break it down and let simple steps solve it.” 🔥 Another step forward in the journey — writing cleaner, smarter solutions. #LeetCode #Algorithms #Strings #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 19/150 — Solved LeetCode 58: Length of Last Word Today’s problem looked super simple at first… but taught me a great lesson about handling edge cases carefully 😄 🧠 What’s the Problem About? You’re given a string that contains words separated by spaces. Your task is to find the length of the last word. Sounds easy, right? Well… not always 👇 💡 The Catch The string might contain: Extra spaces at the beginning Extra spaces at the end Multiple spaces between words So it’s not just about “finding the last word” — it’s about finding the last valid word. 🔥 Example Input: " hello world " At first glance, it looks messy 😵 But the actual last word is: 👉 "world" 👉 Length = 5 🧠 The Thought Process Instead of trying to split everything immediately, I started thinking: Why not scan from the end? Because: The last word is always near the end We can skip spaces quickly Then just count characters until we hit a space ⚙️ Approach That Worked Ignore trailing spaces Start from the end of the string Count characters until a space appears That count is your answer Simple, efficient, and clean. 😎 Why This Problem Is Interesting It’s not about complexity — it’s about precision It shows how small edge cases can break simple logic It encourages thinking in reverse (which is surprisingly powerful) 💡 What I Learned Always consider edge cases like extra spaces Sometimes scanning backward is smarter than forward Even easy problems can sharpen your attention to detail 🎯 Key Takeaway “Simple problems aren’t always trivial — they test how carefully you think.” 🔥 Another step forward — improving not just coding skills, but problem-solving mindset. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 11/150 — Cracked LeetCode 274: H-Index Today’s problem was less about coding… and more about thinking smart 😄 At first glance, it looks like just another array problem. But once I dug in, I realized it’s actually about measuring impact — not just numbers. 🔍 What’s the Problem About? You’re given an array where each number represents how many times a research paper was cited. Now the twist: 👉 You need to find the H-Index Which basically means: A researcher has an H-Index of h if they have h papers with at least h citations each. 🧠 The “Aha!” Moment Initially, it feels confusing… like, “Where do I even start?” But everything clicks when you: 👉 Sort the array in descending order Suddenly, the problem becomes super clean. Now it’s just about checking: “Do I have 1 paper with ≥1 citation?” “Do I have 2 papers with ≥2 citations?” “Do I have 3 papers with ≥3 citations?” …and so on. The moment this condition fails — boom, you stop. That’s your answer. 📊 Quick Example Input: [3, 0, 6, 1, 5] After sorting: [6, 5, 3, 1, 0] Now checking step-by-step: 1 paper → valid ✅ 2 papers → valid ✅ 3 papers → valid ✅ 4 papers → not valid ❌ 🎯 Final Answer: 3 💡 What Made This Problem Interesting? It’s not about checking everything — it’s about knowing when to stop A simple sort can completely change how you see the problem It teaches you to think in terms of thresholds and consistency, not just values 😎 My Takeaway This problem is a perfect reminder that: “Sometimes the smartest solution isn’t more work… it’s better perspective.” 🔥 One more step forward in the journey. Let’s keep building. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) Return True if the values a and b are close to each other and False otherwise. Whether or not two values are considered close is determined according to given absolute and relative tolerances. If no errors occur, the result will be: abs(a-b) <= max(rel_tol * max(abs(a),abs(b)), abs_tol). rel_tol is the relative tolerance – it is the maximum allowed difference between a and b, relative to the larger absolute value of a or b. For example, to set a tolerance of 5%, pass rel_tol=0.05. The default tolerance is 1e-09, which assures that the two values are the same within about 9 decimal digits. rel_tol must be nonnegative and less than 1.0. abs_tol is the absolute tolerance; it defaults to 0.0 and it must be nonnegative. When comparing x to 0.0, isclose(x, 0) is computed as abs(x) <= rel_tol * abs(x), which is False for any nonzero x and rel_tol less than 1.0. So add an appropriate positive abs_tol argument to the call. The IEEE 754 special values of NaN, inf, and -inf will be handled according to IEEE rules. Specifically, NaN is not considered close to any other value, including NaN. inf and -inf are only considered close to themselves. #python #softwaredevelopment #aiwithanisharya
To view or add a comment, sign in
-
I built a tool that lets you ask questions about your codebase in plain English. 🧠 Like literally just type — "where is the FAISS vector store initialized?" — and it finds the exact file, function, and code for you. No more ctrl+F. No more digging through 20 files manually. It's called CodeMind. Getting started is super simple too — just paste your GitHub repo link and it'll clone it automatically, or upload a ZIP file if you prefer. That's it, you're ready to start asking questions. Here's how it works under the hood: → Loads your entire codebase → Breaks it into chunks and converts them into embeddings → Stores everything in a FAISS vector store → When you ask something, it pulls the most relevant code and sends it to Groq LLM for a proper answer Built with Python · LangChain · FAISS · Groq · Streamlit 🔗 Try it: https://lnkd.in/gYV8UfC8 🐙 GitHub: https://lnkd.in/gk3F5kZf Still a lot to improve but happy with how v1 turned out. Would love honest feedback from anyone into AI or dev tooling! 🙌 #RAG #LangChain #GenerativeAI #Python #OpenSource #BuildInPublic #AIEngineering
To view or add a comment, sign in
-
-
📌 Sunday is for Revision Revisiting the problems I’ve already solved to strengthen my understanding and retain concepts better. 🚀 Day 4 – Leveling Up Problem-Solving Same pattern. Slight twist. Better thinking. Showing up daily is the real win. 📌 Today’s Problem: Sum of Squares of N Numbers Looks similar to yesterday’s problem… But the approach needs a sharper mindset. 🔹 Approaches Explored 1️⃣ Iterative Approach (For Loop) → Adding squares one by one 2️⃣ Formula-Based Approach → Direct mathematical solution for better efficiency 💡 Key Takeaway Even small variations in problems can change how you think. ✔️ Learned how similar problems require different perspectives ✔️ Understood that formulas can optimize performance 📈 Progress Update: From understanding patterns → to applying smarter solutions Consistency is the real growth engine 🔑 #Python #ProblemSolving #100DaysOfCode #Consistency #LearningJourney #DeveloperMindset
To view or add a comment, sign in
-
-
🚀 Day 1 — Building Problem Solving Skills I’m continuing my journey to improve problem-solving skills by staying consistent, disciplined, and accountable — one problem at a time. 🧩 Problem: • Two Sum (LeetCode #1) 📚 Topic: Arrays (Pair Traversal) 💡 Key Insight: Checking all possible pairs works, but it highlights the need for more efficient approaches as input size grows. ⚡ Approach: • Pick an element using index i • Traverse remaining elements using index j • Check if nums[i] + nums[j] == target • Return indices when condition is satisfied 🎯 Takeaway: Even simple problems help strengthen logic and introduce optimization thinking. ⏱ Complexity: Time → O(n²) Space → O(1) 💻 Sample Input: nums = [2, 7, 11, 15] target = 9 ✅ Output: [0, 1] Consistency > Perfection 💪 #DSA #LeetCode #ProblemSolving #Python #CodingJourney #LearningInPublic #Arrays #TechGrowth
To view or add a comment, sign in
-
-
Day 15/30 🔹 Problem: Check if a year is a leap year 🔹 What I focused on today: Understanding how multiple conditions work together 🔹 My Thinking Process: A year is divisible by 4 → leap year But if divisible by 100 → NOT a leap year Exception: if divisible by 400 → leap year 🔹 Inputs I used: Year 🔹 Code: year = int(input("Enter a year: ")) if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap Year") else: print("Not a Leap Year") 🔹 Example: Year = 2024 → Leap Year Year = 1900 → Not a Leap Year Year = 2000 → Leap Year 🔹 Key Takeaway: Combining conditions correctly is important to avoid logical mistakes, even in simple problems #Day15 #Python #30DaysOfCode #LearningInPublic #DataAnalytics #ProblemSolving
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