They asked for the sum of 5 numbers. The loop ran forever. One line was missing: count += 1. Without incrementing the counter, the condition never became false. One line. Infinite loop. I wrote a beginner practice guide that walks through both classics: ✅ Sum of N numbers — counter loop, running sum, read inside the loop ✅ Sum of positive vs negative separately — two sums, if/else inside the loop ✅ Variables you need: num_of_numbers, sum, count (and why count < N, not <= N) ✅ Full program structure and trace examples ✅ Common mistakes: forget count += 1, wrong condition, forget to init sum to 0 ✅ Clear takeaways and next steps ~6 min read. No fluff. https://lnkd.in/gkhQBbuQ #Python #Programming #Coding #Beginners #LearnToCode #SumOfNumbers #WhileLoop #Practice #Tech #SoftwareDevelopment #CodingTips
Vimal Thapliyal’s Post
More Relevant Posts
-
They wanted the maximum of 5 numbers. The program printed 0. Every number was negative. max = 0 fails when all inputs are negative. Read the first number into max, then loop for the rest. One idea, two bugs avoided. I wrote a beginner guide that covers two classics in one: ✅ Maximum of N numbers — read first into max, loop N−1 times, update if larger (and why not max = 0) ✅ Decimal to binary — divide by 2, collect remainders, reverse. In code: prepend to a string. ✅ Why the "build as number" method loses leading zeros (and why string method is correct) ✅ Full programs: max of N and decimal-to-binary with n=0 handled ✅ Summary, takeaways, and next steps (min, binary→decimal) ~6 min read. Straight to the point. https://lnkd.in/gqJWam9x #Python #Programming #Coding #Beginners #LearnToCode #Maximum #DecimalToBinary #Binary #WhileLoop #Practice #Tech #SoftwareDevelopment #CodingTips
To view or add a comment, sign in
-
-
Day 3: Mastering Operators! 🚀 Today, I learned how to make my code "think" using Operators. These are the tools that let us do math and create logic in programming. What I practiced today: ✅ Math Operators: Using +, -, *, /, and % for calculations. ✅ Comparison: Using ==, >, and < to compare values. ✅ Logical Thinking: Using and, or, and not to build smart conditions. I have practiced these concepts with real examples and pushed all my code to Github💻 Small steps every day lead to big results. #Coding #Python #Learning #Codegnan
To view or add a comment, sign in
-
-
How do you explain a “function” to a newbie?🤔 For me, the simplest way is this: a function is a reusable tool for a specific task. ✨ Think about it like this: when you want to sweep your floor, you don’t reinvent the broom every time, right? You grab the broom, sweep, and done. ✅ In programming, a function works the same way. Once you’ve written it, you can reuse it anywhere you need that task done. No need to repeat the steps from scratch. So the next time someone asks you what a function is, don’t get lost in technical jargon. Just say: “It’s your broom in the coding world. Once you have it, you just keep using it.” 😉 What everyday object would you compare a function to? #Programming #Python #BackendDevelopment #SoftwareEngineering #LearnigInPublic
To view or add a comment, sign in
-
Day 5: 90-Day Coding Challenge 🚀 Continuing the journey by strengthening my understanding of greedy algorithms and efficient array traversal techniques. Today’s problem focused on the Best Time to Buy and Sell Stock challenge. The goal was to determine the maximum profit that can be achieved by buying and selling a stock once, given the stock prices across different days. Instead of checking all possible buy–sell combinations, I applied a greedy one-pass approach by tracking the minimum price seen so far and calculating the potential profit at each step. This allowed me to efficiently determine the best possible transaction while scanning the array only once. Today’s learning highlights: ✅ Understanding how maintaining a running minimum helps identify the best buying point ✅ Calculating profit dynamically while traversing the array ✅ Achieving an optimized O(n) time complexity with O(1) space complexity This problem reinforced an important insight: keeping track of key values during a single traversal can eliminate the need for nested iterations and significantly improve performance. Day 5 completed. On to Day 6. 💻🔥 #90DayCodingChallenge #CodingJourney #DSA #Arrays #GreedyAlgorithm #ProblemSolving #Python #LearningJourney #Consistency #Growth
To view or add a comment, sign in
-
They built "Guess the Number." It never asked for a guess. The loop never ran. guess wasn't defined. while guess != n crashed before the first input. One line before the loop: guess = 0. I wrote a beginner guide that walks through the whole game: ✅ How the game works — computer picks 1–10, user guesses, smaller/larger/correct ✅ Random numbers: import random, random.randint(1, 10) ✅ "Repeat until correct" → while guess != n, then if/elif/else inside ✅ Why guess = 0 at the start (so the loop runs at least once) ✅ Full program order and common mistakes (forget int(), randint(0,10)) ✅ Summary and next steps (limited attempts, 1–100, count guesses) ~5 min read. No fluff. https://lnkd.in/gMX8CSi6 #Python #Programming #Coding #Beginners #LearnToCode #GuessTheNumber #Random #WhileLoop #Practice #Tech #SoftwareDevelopment #CodingTips
To view or add a comment, sign in
-
🚀 Day 10 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem : Move Zeroes(#283) 💡 Key Learning: This problem looks simple but teaches a powerful concept — in-place array manipulation using two pointers while maintaining order. ⚡ Approach: Use a left pointer (l) to track position for non-zero elements & traverse with right pointer (r) → non-zero is found → swap element at l & r then l++ 🧠 Why this works: Maintains relative order Avoids extra space → O(1) Single pass → O(n) 🔥 Result : ✔️ Runtime: 0 ms (Beats 100%) 📈 Problems like these build strong fundamentals for advanced DSA. Consistency is compounding. Keep going. 💪 #Day10 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #TwoPointers #Consistency
To view or add a comment, sign in
-
-
LeetCode Win Today 🚀 Solved “Apply Operations to an Array” with a simple two-pass approach. ⚡ Runtime: 0 ms (Beats 100%) Approach: 🔹 Pass 1: Traverse the array If nums[j] == nums[j-1] → Double the left element → Set the right element to 0 🔹 Pass 2: Move all zeros to the end using a two-pointer technique. 💡 Key Insight: Instead of solving everything in one complex loop, split the problem into two clean steps. 📊 Complexity: • Time → O(n) • Space → O(1) (in-place) Consistent practice. Clear thinking. Better code every day. 🧠⚡ #leetcode #dsa #algorithms #datastructures #coding #programming #python #softwareengineering #computerscience #tech #codinglife #problem-solving #100daysofcode #developers #codingjourney #techcommunity 🚀
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
-
-
🚀 Day 14 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem : Best Time to Buy and Sell Stock (#121) 💡 Key Learning: This problem builds intuition for tracking minimum values and maximizing profit using a single pass. ⚡ Approach: Use two pointers → buy (l) & sell (r) If price[r] > price[l] → calculate profit Update max profit If price[r] < price[l] → move l to r (better buying point) 🧠 Why this works: Single traversal → O(n) Keeps track of minimum buying price No extra space required → O(1) 🔥 Result : ✔️ Runtime: 57 ms (Beats 38.25%) 📈 Simple logic, but powerful pattern for many stock & profit-based problems. Consistency is compounding. Keep going. 💪 #Day14 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #Greedy #Consistency
To view or add a comment, sign in
-
-
They wanted to repeat 10 times. They used while, forgot to increment. Infinite loop. With for i in range(10) you get 0..9 automatically. No counter to forget. Same idea, fewer bugs. I wrote a beginner guide that covers for and range(): ✅ while vs for — condition vs "each element in a sequence" ✅ for over a string (for x in "Hello") ✅ range(stop), range(start, stop), range(start, stop, step) ✅ Negative step to count down (e.g. 10 down to 1) ✅ for i in range(10) to repeat N times; range(1, 11) for 1 to 10 ✅ Common patterns and summary ~5 min read. No fluff. https://lnkd.in/g6HY7erg #Python #Programming #Coding #Beginners #LearnToCode #ForLoop #Range #Practice #Tech #SoftwareDevelopment #CodingTips
To view or add a comment, sign in
More from this author
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