🚀 Day 60/60 of #60DaysOfCode Completed the problem “Buildings with Sunlight” from . 🌇 Problem: Given heights of buildings, count how many receive sunlight from the left side. A building gets sunlight only if no taller building exists before it. 💡 Approach: Traverse from left and track the maximum height so far: - If current height ≥ max → it gets sunlight - Update max height 🧠 Key Learning: A simple greedy approach can solve this efficiently in one pass. 💻 Code: class Solution: def visibleBuildings(self, arr): max_height = 0 count = 0 for h in arr: if h >= max_height: count += 1 max_height = h return count ⚡ Complexity: - Time: O(n) - Space: O(1) Consistency paid off — 60 days strong 💪 Next target: bigger challenges 🚀 #Day60 #60DaysOfCode #Python #DSA #Greedy #ProblemSolving #CodingJourney #GeeksforGeeks
Buildings with Sunlight Problem Solution in Python
More Relevant Posts
-
🚀 Day 12/100: Scope & The Number Guessing Game! 🎯🔢 💡 Did you know? In the early days of computing, managing "Scope" was one of the biggest causes of system crashes. Today, understanding where your variables "live" is the secret to writing bug-free, professional code! I’ve hit Day 12 of #100DaysOfCode! Today was a deep dive into the internal mechanics of Python, specifically Global vs. Local Scope. Key technical takeaways: ✅ Scope Hierarchy: Understanding that variables created inside a function are local to that function. ✅ Global Constants: Learning the best practice of using UPPERCASE for global constants that don't change. ✅ Game Logic: Building a "Number Guessing Game" with Difficulty Levels (Easy vs. Hard). ✅ Namespace: Learning how Python tracks names to avoid variable conflicts. Mastering Scope is like mastering your internal energy—if you don't control where it flows, your whole program can fall apart! 🛡️ Check out my code here: 🔗 https://lnkd.in/gBZgiBxr The grind is getting intense. Day 13, show me what you've got! ⚔️ #Python #100DaysOfCode #ProgrammingLogic #VariableScope #CleanCode #CodingChallenge #DevCommunity
To view or add a comment, sign in
-
LeetCode Day 13 – Container With Most Water Today I solved the classic “Container With Most Water” problem — a great example of optimizing from brute force to an efficient solution! Problem Insight: We are given an array of heights, and we need to find two lines that together with the x-axis form a container that holds the maximum water. Approaches: Brute Force (O(n²)) Check all possible pairs Calculate area = width × min(height[i], height[j]) Keep track of maximum Optimal Approach – Two Pointer (O(n)) Start with two pointers at both ends Calculate area Move the pointer with smaller height inward Repeat until pointers meet Key Idea: The limiting factor is always the smaller height Moving the larger height won’t help increase area Complexity: Time: O(n) Space: O(1) What I learned: How two-pointer technique drastically reduces complexity Importance of understanding constraints before coding #LeetCode #Day13 #DSA #CodingJourney #Python #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
🗓 7 April 2026 🚀 LeetCode #703 – Kth Largest Element in a Stream Solved this problem using a clean and efficient Min Heap approach 🔥 💡 Instead of storing all elements, I maintained only the top K largest elements, which makes the solution scalable for large data streams. 🧠 Approach: • Created a min heap • Added elements in the constructor • If size exceeds k → removed the smallest element • In add(): – Push new value into heap – Pop if size exceeds k – Return the top element (Kth ) ⚡ Time Complexity: O(n log k) 📦 Space Complexity: O(k) 💭 Key Insight: We don’t need to store all elements — just maintain the top k elements. The smallest among them is the answer 🎯 #LeetCode #DSA #Python #Coding #100DaysOfCode #Heap
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
-
-
Day 10/100 – DSA Challenge Today’s problem: Move Zeroes (LeetCode 283) What I Learned: The goal was to move all zeroes to the end of an array while maintaining the relative order of non-zero elements — and importantly, doing it in-place. Key Idea: Two-Pointer Technique I used a two-pointer approach: One pointer (fast) iterates through the array Another pointer (slow) tracks where the next non-zero element should go Whenever a non-zero element is found, it is swapped with the element at the slow pointer, ensuring all non-zero elements are shifted forward while zeroes naturally move to the end. Why this approach? Maintains order of elements Works in O(n) time complexity Uses O(1) extra space (in-place) Takeaway: This problem reinforced how powerful the two-pointer technique is for array manipulation problems, especially when constraints require in-place operations. Looking forward to tackling more problems and improving consistency! #Day10 #100DaysOfCode #DSA #Python #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Solved today’s LeetCode challenge: Longest Common Prefix 💻🔥 Problem: Given an array of strings, find the longest common starting substring among all strings. ✅ Example: ["flower", "flow", "flight"] → "fl" ["dog", "racecar", "car"] → "" 🧠 My Approach: Started with the first word as a prefix and compared it with the remaining strings one by one. Whenever a mismatch happened, I kept shrinking the prefix from the end until it matched. This helped me understand: 🔹 String slicing in Python 🔹 Prefix matching logic 🔹 Edge case handling 🔹 Writing optimized clean code 💡 Time Complexity: O(n * m) (n = number of strings, m = prefix length) Consistency > Motivation. One problem every day builds strong problem-solving skills 📈 Check Out : https://lnkd.in/dtumdVUQ #LeetCode #Python #DSA #CodingJourney #ProblemSolving #100DaysOfCode #SoftwareEngineer #Programming #Tech #Learning
To view or add a comment, sign in
-
𝗜𝘁 𝘀𝘁𝗮𝗿𝘁𝘀 𝘄𝗶𝘁𝗵 𝗮 𝗻𝗼𝗯𝗹𝗲 𝗶𝗻𝘁𝗲𝗻𝘁𝗶𝗼𝗻: "𝗜 𝗮𝗺 𝗴𝗼𝗶𝗻𝗴 𝘁𝗼 𝘀𝗮𝘃𝗲 𝘁𝗶𝗺𝗲." It ends with you debugging a Python script at 2 AM for a process that you could have finished by hand before lunch. Engineers love to solve problems with code. But sometimes, code is the most expensive solution. Here is the math on why "𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗻𝗴 𝗘𝘃𝗲𝗿𝘆𝘁𝗵𝗶𝗻𝗴" is actually hurting your productivity. 𝗥𝗲𝗴𝗶𝘀𝘁𝗲𝗿 𝗻𝗼𝘄 : https://lnkd.in/dkVrmCHc #DeveloperLife #Automation #Productivity #IndieHacker #Engineering #TheVentureBuild
To view or add a comment, sign in
-
Day 65 – Coding Challenge 🚀 Today’s problem was an interesting mix of simulation and stack-based processing. 🔹 Problem Statement: Given an array, repeatedly apply operations on adjacent elements with opposite signs: If absolute values differ → keep the one with larger absolute value If equal → remove both Continue until no more operations can be performed. 🔹 Approach: Used a stack-like approach to simulate the process For each element: Compared with the last element in the result Resolved conflicts based on sign and absolute value Repeated merging/removal until stable Ensured the final array satisfies all conditions This problem highlights how stack-based simulation helps efficiently handle sequential conflicts and reductions. Day 66 next — let’s keep building 💪 #geekstreak60 #npci #day65 #dsa #python #codingchallenge #problemSolving #learningjourney #consistency
To view or add a comment, sign in
-
-
🚀 Day 21 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem : Evaluate Reverse Polish Notation (#150) 💡 Key Learning: This problem strengthens understanding of stack-based expression evaluation, especially for postfix (Reverse Polish) notation. ⚡ Approach: Use a stack to store operands Traverse tokens → If number → push to stack If operator → pop two elements → apply operation → push result back Final result will be at top of stack 🧠 Why this works: Postfix expressions eliminate need for parentheses Stack ensures correct order of operations Efficient evaluation → O(n) time 🔥 Result : ✔️ Runtime: 0 ms (Beats 100%) 📈 A classic stack problem that builds strong foundation for expression parsing & evaluators. A big thanks to Shivam Singh, Nikhil Yadav & Akshat Tiwari for this amazing challenge 🙌 Consistency is compounding. Keep going. 💪 #Day21 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #Stack #Consistency
To view or add a comment, sign in
-
-
Today: LeetCode 88 — Merge Sorted Array. Saw "sorted arrays" in the problem. My brain immediately said: two pointers. Started coding. Got stuck pretty fast. The issue? When you're merging into an existing array without extra space, two pointers aren't enough — you need a third one tracking where to place elements. And you have to go backwards through nums1, or you'll overwrite values you still need. Took longer than I'd like to admit. Used hints. Eventually got it — and it beat 100% on runtime. The real lesson wasn't the algorithm. It was this: pattern recognition gets you to the door, but you still have to figure out which version of the pattern fits. "Two pointers" is a family of techniques, not a single move. Knowing the name isn't the same as understanding the shape of the problem. Day 36 of #1000DaysOfLearning #DSA #Python #LearningInPublic
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