Here’s the fix: The code used different variable names. Fixing that and keeping the print inside the loop makes it run perfectly. #DebuggingSkills #PythonForBeginners #STEMEducation #CodingChallenge #LearnCoding
Fixing Python Loop with Correct Variable Names
More Relevant Posts
-
Solved today’s LeetCode Hard: 3655. XOR After Range Multiplication Queries II ✅ At first, it looked like a direct simulation problem. For each query: • start from l • jump by k • multiply by v Simple idea. But with n = 1e5 and queries = 1e5, that approach breaks very fast. So the real challenge was not implementing the updates… It was figuring out how to avoid doing them one by one. What I learned from this problem: The important observation was that each query updates indices in an arithmetic progression: l, l+k, l+2k ... That led to a much better approach: • Large k → process directly • Small k → group and batch efficiently That small observation completely changed the problem. What I liked about this one is that it didn’t need some magical trick. It just needed the right way of looking at the updates. Sometimes hard problems are less about advanced coding and more about seeing the structure early. Good problem. Nice learning. 🚀 Problem Link : https://lnkd.in/dHBq8t5z Solution : https://lnkd.in/dqMAvJca #LeetCode #Cpp #ProblemSolving #CodingJourney #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Day 93 of #100DaysOfCode ✅ Solved: Max Consecutive Ones (LeetCode 485) ⚡ Runtime: 16 ms 💾 Memory: 21.78 MB At first glance, this problem looks very basic… but it tests something important — how well you track patterns in a single pass. 💡 What I did: - Kept a running "count" of consecutive 1s - Reset it whenever I hit a "0" - Continuously updated the maximum streak 🧠 Key Learning: You don’t always need complex logic. Sometimes, one clean loop + good observation = optimal solution. ⚙️ Complexity: Time → O(n) Space → O(1) 📌 Small problems like this build the foundation for solving bigger pattern-based questions (sliding window, DP, etc.) Consistency > Difficulty 💯 #LeetCode #DSA #CodingJourney #Day93 #100DaysOfCode
To view or add a comment, sign in
-
-
I created a new LeetCode video for my Slice of Life Coding series. This one covers LeetCode 217: Contains Duplicate. It’s an easy-level question, but there are multiple ways to solve it, which makes it a really good one to practice coming up with different approaches and then refining them into more optimal solutions. In the video, I go through 3 solutions, each one more optimized than the last, and talk through the time & space complexity for each. https://lnkd.in/gApAmKiT
LeetCode 217: Contains Duplicate | 3 Solutions Explained (Brute Force → Optimal Set)
https://www.youtube.com/
To view or add a comment, sign in
-
🚀 Day 7 of My LeetCode Journey Today’s problem: Reverse Integer At first glance, it looks simple — just reverse digits. But the real challenge was handling 32-bit integer overflow without using 64-bit storage. 🔍 What I learned: How to extract digits using modulo (%) Building the reversed number step by step Most importantly, checking overflow before updating the result ⚠️ Edge Case: If the reversed number goes beyond the 32-bit range [-2³¹, 2³¹ - 1], we must return 0 💡 Example: Input: 123 → Output: 321 Input: -123 → Output: -321 Input: 1534236469 → Output: 0 (Overflow case) Consistency over perfection 💪 #Day7 #LeetCode #DSA #CProgramming #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
𝗠𝗲𝗺𝗼𝗿𝘆 𝗛𝗶𝗲𝗿𝗮𝗿𝗰𝗵 If you work on compilers, runtimes, or low-level systems, you need to ask yourself: what kind of miss did my code create? One bad memory access can cost you hundreds of cycles. You can learn about: - Cache misses and set conflicts - False sharing and multithreading pitfalls - TLB and page-walk cost - How loop tiling can give you 30x speedups Source: https://lnkd.in/gqpSAiNe Optional learning community: https://t.me/GyaanSetuAi
To view or add a comment, sign in
-
🚀 Day 72 of #100DaysOfDSA Solved a classic Backtracking problem 🔥 🧩 Problem Solved: LeetCode 77 – Combinations 💡 Key Idea: Generate all possible ways to choose k numbers from 1 to n using Backtracking. 🔍 Approach: Start from a number and pick it Recursively choose next numbers in increasing order Once size becomes k, store the combination Backtrack and try other possibilities ⚡ What I Learned: How recursion builds combinations efficiently Importance of start index to avoid duplicates Backtracking = Choose → Explore → Undo 💻 Language Used: C++ #Day72 #100DaysOfDSA #LeetCode #Cpp #Backtracking #Recursion #CodingJourney
To view or add a comment, sign in
-
-
Implemented a menu-driven Queue using C 💻 Built a simple program demonstrating core queue operations: • Enqueue (Insertion) • Dequeue (Deletion) • Display Worked with front and rear pointers to manage the queue and handled edge cases like overflow and underflow. Attached a short video demo showing the program in action 🎥 This helped reinforce my understanding of data structures and modular coding in C. Next step: implementing a circular queue for better efficiency. #CProgramming #DataStructures #Queue #CodingPractice #LearningByDoing
To view or add a comment, sign in
-
💡 DP (Dynamic Programming) becomes simple with the right problem — Counting Bits (LeetCode 338) 👉 dp is using previous results to compute new results Instead of recomputing, just reuse: `bits[i] = bits[i >> 1] + (i & 1)` Same patterns. Less work. Faster solution. #DynamicProgramming #LeetCode #DSA #CodingInterview #ProblemSolving #BitManipulation
To view or add a comment, sign in
-
🚀 Day 9 of Coding Solved Problem #303 – Range Sum Query (Immutable) 💡 🔍 Problem Statement: Design a data structure that supports efficient range sum queries on an array. 🧠 Key Learning: Used Prefix Sum technique Learned how preprocessing helps reduce query time to O(1) Strengthened understanding of cumulative sums ⚡ Approach: Maintain a prefix sum array Store cumulative sum at each index For any query (l, r), compute result using: prefix[r] - prefix[l-1] 💻 Tech Stack: C++ | STL (vector) ✅ Successfully passed all test cases! ⚡ Optimized for fast queries #Day9 #LeetCode #DSA #CodingJourney #CPP #ProblemSolving
To view or add a comment, sign in
-
-
62 of #100DaysOfCode 🚀 Solved LeetCode 78 – Subsets using a pure recursive (include/exclude) approach in C++. 🔍 Approach: At each index, I make a decision: ✔️ Include the current element in the subset ❌ Exclude the current element This creates a recursion tree exploring all possibilities, and when we reach the end of the array, we store the current subset. 🧠 Core Idea: Pick → Recurse Backtrack → Skip → Recurse Store result when index reaches n #leetcode #cpp #recursion #backtracking #dsa #100DaysOfCode #codingjourney
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