Buildings with Sunlight Problem Solution in Python

🚀 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

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories