Day 47 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find a peak element in an array. A peak element is an element that is greater than or equal to its neighbors. What the program does: • Takes an array as input • Finds any peak element in the array • Handles edge cases (first and last elements) • Returns the peak value How the logic works: • If the array is empty → return None • If it has only one element → return that element • Check the first element: – If it is greater than or equal to the next element → it's a peak • Check the last element: – If it is greater than or equal to the previous element → it's a peak • Traverse the array from index 1 to n-2: – If an element is greater than or equal to both neighbors → return it • If no peak is found (rare case), return None Example: Input: [1, 3, 20, 4, 1, 0] Output: 20 Another example: Input: [1, 2, 3, 4, 5] Output: 5 Another example: Input: [5, 4, 3, 2, 1] Output: 5 Why this approach works: – Checks boundary conditions properly – Works for increasing and decreasing arrays – Time Complexity: O(n) Key learnings from Day 47: – Handling edge cases in arrays – Comparing neighboring elements – Writing clean traversal logic – Strengthening problem-solving skills #100DaysOfCode #Day47 #Python #PythonProgramming #Arrays #Algorithms #ProblemSolving #CodingPractice #DataStructures #InterviewPrep #LearnByDoing #DeveloperGrowth #ProgrammingJourney #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
Peak Element Finder in Python: Handling Edge Cases
More Relevant Posts
-
Day 49 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the Equilibrium Index of an array. An equilibrium index is an index where the sum of elements on the left is equal to the sum of elements on the right. What the program does: • Takes an array as input • Finds an index where left sum = right sum • Returns the index if found • Returns -1 if no such index exists How the logic works: • Calculate the total sum of the array • Initialize left_sum = 0 • Traverse the array using enumerate() • For each element: – Right sum = total_sum - left_sum - current element – If left_sum == right_sum, return the index • Add the current element to left_sum • If no equilibrium index is found, return -1 Example: Input: [-7, 1, 5, 2, -4, 3, 0] Output: 3(Left sum = Right sum = 1) Another example: Input: [1, 2, 3] Output: -1 (No equilibrium index) Another example: Input: [1, 0, -1] Output: 1 Why this approach is efficient: – Uses prefix sum concept – Avoids nested loops – Time Complexity: O(n) Key learnings from Day 49: – Understanding prefix sums – Optimizing from brute force to O(n) – Working with running totals – Strengthening array problem-solving #100DaysOfCode #Day49 #Python #PythonProgramming #Arrays #PrefixSum #Algorithms #DataStructures #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
🚀 Solved: Middle of the Linked List Today I worked on a classic linked list problem — finding the middle node efficiently. 🔹 Problem: Given the head of a singly linked list, return the middle node. If there are two middle nodes, return the second one. 🔹 Approach: Used the two-pointer technique: Slow pointer moves 1 step at a time Fast pointer moves 2 steps at a time By the time the fast pointer reaches the end, the slow pointer will be at the middle. 🔹 Complexity: Time: O(n) Space: O(1) 💡 Key takeaway: Two-pointer techniques are extremely powerful for linked list problems #coding #datastructures #python #leetcode #learning #problemsolvingSkills #10000 Coders #Vamsi Enduri #GALI VENKATA GOPI #Manoj Kumar Reddy Parlapalli
To view or add a comment, sign in
-
-
✅ Day 92 of 100 Days LeetCode Challenge Problem: 🔹 #2011 – Final Value of Variable After Performing Operations 🔗 https://lnkd.in/gX-JQNUJ Learning Journey: 🔹 Today’s problem was about evaluating a sequence of increment and decrement operations. 🔹 I initialized a variable ans = 0 to track the value. 🔹 Used a hashmap to map each operation to its effect: • "++X" and "X++" → +1 • "--X" and "X--" → -1 🔹 Iterated through the operations and updated ans accordingly. 🔹 Returned the final computed value. Concepts Used: 🔹 HashMap / Dictionary 🔹 String Matching 🔹 Simple Simulation Key Insight: 🔹 Instead of using multiple condition checks, mapping operations to values simplifies logic and improves readability. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
🚀 Day 81 – Mastering Date & Time in Python ⏰📅 Today’s learning journey was all about the datetime module — one of Python’s most practical tools for handling real‑world scenarios involving dates and times. 🔹 Current Date & Time – Practiced fetching the present moment with datetime.now(), a powerful way to anchor programs in real‑time. 🔹 Modification – Explored how to adjust dates and times, making it possible to calculate future or past events with ease. 🔹 Formatting with strftime – Learned how to present date and time in human‑friendly formats, turning raw data into readable output. 🔹 Parsing with strptime – Understood how to convert strings into datetime objects, bridging user input with program logic. 🔹 timedelta Magic – Discovered how to perform arithmetic on dates and times, enabling countdowns, schedules, and reminders. 🔹 Alarm Task – Applied these concepts to build a simple alarm, reinforcing how datetime can power real‑life applications. 🌱 Reflection – Working with time isn’t just technical; it’s about making programs responsive to the world around us. From reminders to logs, datetime is the backbone of time‑aware applications. ✨ Grateful to Ajay Miryala sir and the 10000 Coders team for guiding me through another essential building block in Python. ⚡ Day 81 was about turning abstract concepts into practical tools — learning to control time itself in code! #Day81 #PythonLearning #Datetime #CodingJourney #10000Coders #LearnInPublic #100DaysOfCode
To view or add a comment, sign in
-
Day 58 of my #100DaysOfCode challenge 🚀 Today I implemented a Python program to generate prime numbers within a given range. This is a practical extension of prime checking and useful in many DSA and real-world problems. What the program does: • Takes a range (start, end) as input • Checks each number in the range • Identifies whether it is prime or not • Returns a list of all prime numbers in that range Example Output: Prime numbers between 1 and 50: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] How the logic works: Start from max(2, start) For each number: • Assume it is prime • Check divisibility from 2 → √n If divisible → not prime If not divisible → add to result list 👉 Uses square root optimization for better performance Why this is important: – Builds on prime number fundamentals – Useful in: Competitive programming Number theory problems Range-based queries – Helps understand optimization using √n Time Complexity: O(n√n) Space Complexity: O(k) (number of primes) Key Takeaways: – Applying optimized prime checking – Working with ranges and loops – Improving efficiency using √n – Writing clean and scalable code #100DaysOfCode #Day58 #Python #Programming #DSA #Algorithms #PrimeNumbers #NumberTheory #CodingPractice #ProblemSolving #InterviewPrep #Optimization #DeveloperJourney #Consistency #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Week 4 of #100DaysOfCode — done! 🎉 Last week I learned how to build classes. This week I learned how to make them talk to each other. Topics covered: 🧹 Inheritance → Superclass, subclass, base class — and what they actually mean → How Python finds attributes (spoiler: it walks up the chain) → Overriding methods — and extending them with super() → isinstance, issubclass, type — when to use which → Multiple inheritance + MRO (Method Resolution Order) 🏗️ Abstract Classes & Interfaces → ABC + @abstractmethod — enforcing a contract on subclasses → Duck typing — "if it has a speak() method, it speaks" → Subclassing built-ins (list, dict, iterator) → Mixins — plugging in behaviour without full inheritance I’ve structured my learning into notes and practical examples to better understand the concepts : https://lnkd.in/epaBymnJ #100DaysOfCode #Python #OOP #LearningInPublic #Programming
To view or add a comment, sign in
-
✅ Day 90 of 100 Days LeetCode Challenge Problem: 🔹 #476 – Number Complement 🔗 https://lnkd.in/gzE6gM7d Learning Journey: 🔹 Today’s problem focused on finding the complement of a number by flipping its binary bits. 🔹 I first converted the integer to its binary representation using bin(num)[2:]. 🔹 Then, I created a helper function to flip each bit: • '0' → '1' • '1' → '0' 🔹 After generating the flipped binary string, I converted it back to an integer using int(..., 2). 🔹 Returned the final complemented value. Concepts Used: 🔹 Binary Representation 🔹 Bit Manipulation 🔹 String Traversal 🔹 Base Conversion Key Insight: 🔹 The complement operation is essentially a bitwise NOT, but only within the significant bits of the number (ignoring leading zeros). 🔹 Converting to binary simplifies the flipping logic for beginners. Complexity: 🔹 Time: O(log n) 🔹 Space: O(log n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
𝐈 𝐰𝐫𝐨𝐭𝐞 𝐭𝐡𝐞 𝐬𝐚𝐦𝐞 𝐥𝐢𝐧𝐞 𝟕 𝐭𝐢𝐦𝐞𝐬 𝐛𝐞𝐟𝐨𝐫𝐞 𝐥𝐞𝐚𝐫𝐧𝐢𝐧𝐠 𝐭𝐡𝐢𝐬 😩 A function is just a named block of code you can run anytime. def = define. then call it by name. 𝑾𝒉𝒚 𝒖𝒔𝒆 𝒕𝒉𝒆𝒎? → Write once, use many times → Easier to fix bugs (one place) → Cleaner code that humans can read 𝑲𝒆𝒚 𝒇𝒆𝒂𝒕𝒖𝒓𝒆𝒔: → 𝑷𝒂𝒓𝒂𝒎𝒆𝒕𝒆𝒓𝒔: Values you pass into a function so it can work with different data each time. → 𝙍𝙚𝙩𝙪𝙧𝙣: The value a function sends back to you after it finishes its job. → 𝘿𝙚𝙛𝙖𝙪𝙡𝙩 𝙖𝙧𝙜𝙪𝙢𝙚𝙣𝙩𝙨:Fallback values that a function uses if you don't pass anything for that parameter. → 𝘿𝙤𝙘𝙨𝙩𝙧𝙞𝙣𝙜𝙨: A short note inside a function that explains what it does (for you and others reading the code). 𝙁𝙪𝙡𝙡 𝙘𝙤𝙙𝙚 + 𝙚𝙭𝙖𝙢𝙥𝙡𝙚𝙨: 🔗 Vist my Github :https://lnkd.in/drGxebiM 𝑶𝒗𝒆𝒓 𝒕𝒐 𝒚𝒐𝒖: 👇 Type "GUILTY" if you've ever written the same loop 4 times in one script.😅 #python #AiEngineer #coding
To view or add a comment, sign in
-
-
🚀 Day 14/30 of My LeetCode Journey (Python + SQL) Two weeks in… consistency is starting to feel like a habit now 💻🔥 🔹 **Python Problem of the Day** 👉 *Best Time to Buy and Sell Stock* Given an array of stock prices, find the maximum profit by choosing the best day to buy and a future day to sell. 💡 *Key Concept:* Track minimum price so far + maximize profit in one pass (greedy approach). 🔹 **SQL Problems of the Day** 👉 *Sales Analysis III* Find products that were only sold in the first quarter of 2019. 💡 *Key Concept:* Date filtering + excluding records outside a range. 👉 *Classes with at Least 5 Students* Find all classes that have at least five students enrolled. 💡 *Key Concept:* GROUP BY + HAVING COUNT() ≥ 5. From basic queries to optimization patterns… seeing real progress now 📈 Day 14 done ✅ #LeetCode #30DaysChallenge #Python #SQL #CodingJourney #Consistency #ProblemSolving #Learning #DataAnalytics
To view or add a comment, sign in
-
🚀 100 Days of Code – Restarting My Python Journey #Day15 of #100DaysOfCode Continuing my Python journey with 📘 “100 Days of Code: The Complete Python Pro Bootcamp” on Udemy by Angela Yu (London App Brewery). 🎯 Day 15 Project — Coffee Machine ☕ Built a console-based coffee machine simulation that can: - Process user orders - Check resource availability (water, milk, coffee) - Handle coin transactions - Calculate change - Update machine resources after each order This project really felt like building a mini real-world system, combining logic, functions, and data handling. 🔗 Check out my progress here: https://lnkd.in/gAufnQ8F One key takeaway: Breaking down a real-world problem into smaller logical steps is the key to building scalable programs. The focus remains: consistency + deep understanding + building in public. 💡 Small steps daily. Big results over time. More updates coming soon… stay tuned! #100DaysOfCode #Python #CodingJourney #LearnInPublic #DeveloperLife #GitHub #Consistency #Day15 #Udemy #BackToLearning
To view or add a comment, sign in
-
Explore related topics
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