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
Cracking LeetCode 274: H-Index Problem 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 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 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
To view or add a comment, sign in
-
-
There’s a difference between writing code and cultivating craft. Most developers chase complexity—more lines, more time, more “features.” But the best engineers develop a deeper instinct: how to express an idea with precision. That’s why I love Python’s one-liners. Not because they’re “short.” But because they reveal something real: clarity can be compressed—when you truly understand what you’re writing. A few examples: swapping values without clutter, transforming lists with comprehension, flattening nested structures, counting with the right tool, using ternary logic thoughtfully. These aren’t tricks. They’re reminders that efficiency isn’t only performance—it’s cognitive performance. ✅ Write code that the next person can read. ✅ Write code that future-you will trust. ✅ Let brevity serve meaning, not ego. #Python #OneLiner #LakkiData #LearningSteps
To view or add a comment, sign in
-
-
🚀 Day 50 of My Coding Journey Today, I explored powerful NumPy operations — sum() and prod() — and learned how combining them can solve interesting problems efficiently. 🔍 What I learned: sum(axis=0) → adds elements column-wise prod() → multiplies elements together By combining both, we can transform and reduce arrays in a single flow 💡 Problem Insight: Given a 2D array, 👉 First, compute the column-wise sum 👉 Then, find the product of that result 📌 Example: Input: 2 2 1 2 3 4 Step 1: Sum along axis 0 → [4, 6] Step 2: Product → 4 × 6 = 24 ✨ Key Takeaway: Understanding how axes work in NumPy makes complex operations simple and efficient. 💻 Code Snippet: import numpy as np n, m = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] my_array = np.array(arr) result = np.prod(np.sum(my_array, axis=0)) print(result) 🔥 Day 50 done! Staying consistent and learning something new every day. #Day50 #Python #NumPy #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Writing loops in Python for array operations? You’re doing it the hard way ❌ Let’s fix that with NumPy Broadcasting 👇 --- 📌 What is Broadcasting? It allows NumPy to perform operations on arrays of different shapes WITHOUT writing loops 🤯 --- 👀 Example: import numpy as np arr = np.array([1, 2, 3]) result = arr + 10 print(result) ✅ Output: [11 12 13] 👉 NumPy automatically "broadcasts" 10 to match array shape! --- 🔥 Now the real power: arr1 = np.array([[1,2,3], [4,5,6]]) arr2 = np.array([10,20,30]) result = arr1 + arr2 print(result) ✅ Output: [[11 22 33] [14 25 36]] 💡 Smaller array is stretched across rows automatically! --- 📌 Broadcasting Rules (Simple Version): ✔ Shapes must be compatible ✔ Matching from right to left ✔ Dimensions should be equal OR 1 --- 🔥 Why it matters? ✅ No loops → Faster code ✅ Cleaner syntax ✅ Used heavily in ML & Data Science --- ⚠️ Common Mistake: np.array([1,2,3]) + np.array([1,2]) ❌ Error: Shapes not compatible Follow for daily coding clarity 🚀 #Python #NumPy #DataScience #MachineLearning #Coding #Programming #LearnToCode #CodingBlockHisar #Hisar
To view or add a comment, sign in
-
-
Day 14 of DSA 🎯 How Slow & Fast Pointers Can Be Used in Numbers We usually think of slow & fast pointers in linked lists. But did you know we can use the same concept in numbers too? 🤯 📍 Problem: Happy Number (LeetCode 202) A number is happy if we replace it by the sum of the squares of its digits repeatedly, and eventually reach 1. If it loops endlessly in a cycle that doesn’t include 1, it’s not happy. ✅ Key Idea Treat the process as a sequence. If we end up in a cycle (not reaching 1), slow & fast pointers will eventually meet. 📌 Example n = 19 19 → 82 → 68 → 100 → 1 ( Reaches 1 → Happy Number ✅ ) n = 2 2 → 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4 (Cycle) ( Never reaches 1 → Not Happy ❌ ) Python Code class Solution: def fun(self, n: int) -> int: sum_n = 0 while n > 0: d = n % 10 total += d * d n //= 10 return sum_n def isHappy(self, n: int) -> bool: slow, fast = n, n while fast != 1: slow = self.fun(slow) fast = self.fun(self.fun(fast)) if slow == fast: # cycle detected return False return True 🚀 Why Does It Work? The sequence of sums is always within a limited range. So either it reaches 1 (happy) or enters a cycle (not happy). Slow pointer moves 1 step, fast pointer moves 2 steps. If there’s a cycle, they must meet. 💡 Key Takeaway Slow & fast pointers are not just for linked lists. They are powerful for detecting cycles in sequences, arrays, and even numbers! That’s it for Day 14! 🚀 Every problem solved today is a step closer to becoming the best version of me. #DSA #100DaysOfCode #LeetCode #HappyNumber #TwoPointers #LearningInPublic
To view or add a comment, sign in
-
-
💻 Solved a great problem today: Count Increasing Subarrays 🚀 Given an array, the task was to count all strictly increasing subarrays of size ≥ 2. 🔍 Approach I used: Broke the array into continuous increasing segments For each segment of length k, calculated subarrays using the formula: 👉 k(k-1)/2 Summed all results to get the final answer ⚡ Time Complexity: O(n) 📦 Space Complexity: O(n) 💡 This problem helped me understand how breaking a problem into patterns can simplify complex logic. Here’s my Python solution 👇 class Solution: def countIncreasing(self, arr): list2 = [] list2.append(arr[0]) list3 = [] for i in range(1, len(arr)): if arr[i-1] < arr[i] and arr[i] > 2: list2.append(arr[i]) else: list3.append(list2) list2 = [] list2.append(arr[i]) list3.append(list2) ans = 0 for i in list3: if len(i) > 1: ans += (len(i) * (len(i) - 1)) // 2 return ans 🔥 Always learning, always improving. #python #dsa #coding #problemSolving #programming #developers #learning
To view or add a comment, sign in
-
-
🚀 Day 87 – Advanced Comprehensions & Smarter Problem Solving 🐍💻 Today’s focus was on taking Python comprehension skills to the next level with tuples and dictionaries, applying them to real-world problem solving. 🔹 Backend (Python) Tuple Comprehension – Practiced generating sequences with cleaner syntax, making code more expressive and efficient. Dictionary Comprehension – Explored transforming datasets into key-value pairs in one elegant line, reducing boilerplate loops. Problem Solving – Applied both comprehensions to practical scenarios, reinforcing how concise code can still be powerful and readable. 🌱 Reflection – Day 87 was about mastering the art of writing compact yet meaningful code. Tuple and dictionary comprehensions not only save time but also sharpen the mindset of thinking in transformations rather than iterations. ✨ Always grateful to Ajay Miryala sir and the 10000 Coders team for their guidance in shaping this journey. ⚡ Step by step, building the mindset of a problem solver and a full stack developer. #Day87 #PythonLearning #TupleComprehension #DictionaryComprehension #Backend #CodingJourney #100DaysOfCode #LearnInPublic #10000Coders
To view or add a comment, sign in
-
-
Just solved “First Matching Character From Both Ends” 🚀 💡 My approach (simple & efficient): Instead of overcomplicating it, I used a two-pointer mindset without explicitly creating two pointers. Loop through the string from the start For each index i, compare: s[i] (from the front) s[n - i - 1] (from the back) The moment both match → return the index If no match → return -1 ✨ This works because we're checking symmetry from both ends in a single pass (O(n)) with O(1) space. Sometimes the best solutions aren’t fancy — they’re just clean and intuitive. 🔥 Consistency > Complexity. Small wins like this build strong problem-solving instincts. #LeetCode #DSA #Python #CodingJourney #ProblemSolving #TechGrowth #CodeDaily #WomenInTech #FutureEngineer #100DaysOfCode #KeepBuilding
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