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
Check if a year is a leap year in Python
More Relevant Posts
-
🚀 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 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
-
-
🚀 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
-
-
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
-
-
🚀 Day 3 of #14DaysOfPython 🐍 Today’s focus: Loops (Iteration Mastery) — where automation really begins. 💡 Easy way to understand loops: 🔹 Why loops? 👉 When you need to repeat a task multiple times instead of writing code again and again 💡 Core Concepts (Logic First): 🔹 for loop vs while loop for → when you know how many times to run while → when condition decides 🔹 range() variations range(n) → 0 to n-1 range(start, end) range(start, end, step) 🔹 Loop control break → stop loop immediately continue → skip current step pass → do nothing (placeholder) 🔹 Infinite loop ⚠️ 👉 Happens when condition never becomes false 🔹 Iteration patterns 👉 Numbers, strings, lists — everything can be looped 🧠 Problems I practiced: Sum of digits Reverse a number Factorial Count occurrences ✨ Key takeaway: Loops are not about syntax — they are about thinking in repetition and patterns. Day 3 done ✅ Moving to Day 4 💪 #Python #HackerRank #CodingJourney #LearningInPublic #ProblemSolving #DeveloperJourney #100DaysOfCode#codegnan
To view or add a comment, sign in
-
-
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
-
-
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
-
-
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
-
-
Day 3/30 Comparing options is easy… but choosing the better one requires understanding the logic behind it. 🔹 Problem: Compare Simple Interest and Compound Interest 🔹 What I focused on today: Understanding the difference in calculation logic between simple and compound interest 🔹 My Thinking Process: Simple Interest is calculated only on the principal amount Compound Interest is calculated on principal + accumulated interest Compare both results to see how compounding makes a difference 👉 Even small changes in logic can lead to big differences in output 🔹 Inputs I used: Principal amount Rate of interest Time (in years) 🔹 Code: principal = float(input("Enter principal amount: ")) rate = float(input("Enter rate of interest: ")) time = float(input("Enter time (in years): ")) # Simple Interest simple_interest = (principal * rate * time) / 100 # Compound Interest amount = principal * (1 + rate / 100) ** time compound_interest = amount - principal print("Simple Interest:", simple_interest) print("Compound Interest:", compound_interest) 🔹 Example: Principal = 1000, Rate = 10%, Time = 2 years Simple Interest = 200 Compound Interest = 210 🔹 Key Takeaway: Compound interest grows faster because it builds on previous interest, not just the original amount #Day3 #Python #30DaysOfCode #LearningInPublic #DataAnalytics #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 11/111 — Diving Deeper into NumPy Today I explored array indexing, slicing, and data types in NumPy, and things are starting to feel much more powerful and precise 📊 🔹 What I learned: • How to access specific elements using indexing • How slicing works to extract parts of arrays • Understanding different NumPy data types (int, float, etc.) • How data type affects memory and performance 💡 Key takeaway: Indexing and slicing make it possible to work with exact portions of data instead of the whole dataset, which is super useful for real-world data analysis. Also, learning about data types showed me that even small details like choosing int vs float can impact efficiency and behavior. It’s getting clearer how NumPy is not just about storing data, but about working with it intelligently, appreciating the help, w3schools.com 🙏 Still learning step by step, but it feels like things are connecting more now. On to the next one 🚀 Code for Change #111daysoflearningforchange #day11 #python #codeforchange
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