For loop vs While loop — not interchangeable Quick mental model: -for loops iterate over a known sequence -while loops wait on a condition -for is about certainty. -while is about state. Choosing correctly makes code safer and easier to reason about. I’ve shared the difference so you don’t just write loops that work, but loops that behave correctly under pressure. #python #loop #forloop #whileloop
For vs While Loops: Choosing Correctly for Safe Code
More Relevant Posts
-
Day 7 of LeetCode 🚀 | 3Sum Closest Today’s problem was 3Sum Closest — finding three numbers whose sum is closest to a given target. Approach: Sort the array Fix one element and use the two-pointer technique Update the closest sum based on minimum difference Adjust pointers to move toward the target ⏱️ Time Complexity: O(n²) 📦 Space Complexity: O(1) #LeetCode #Day6 #DSA #ProblemSolving #TwoPointers #Python #CodingJourney
To view or add a comment, sign in
-
-
LeetCode | Longest Common Prefix 🔤 🔹 Approach: Sorting + Compare first & last strings 🔹 Key idea: Common prefix must match between smallest and largest 🔹 Time Complexity: O(n log n + m) 🔹 Space Complexity: O(1) Daily DSA practice to improve problem-solving skills 🚀 After sorting, the common prefix of the first and last string gives the answer #LeetCode #DSA #Strings #Python #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
LeetCode | Squares of a Sorted Array 🔢 🔹 Approaches: • Two Pointers (Optimal) • Square + Sort 🔹 Time Complexity: O(n) optimal / O(n log n) sorting 🔹 Space Complexity: O(n) Daily DSA practice to improve logic and consistency 🚀 “We compare absolute values from both ends to build the sorted squares efficiently.” #LeetCode #DSA #Arrays #TwoPointers #Python #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
LeetCode | Rearrange Array Elements by Sign 💻 🔹 Approach: Index placement 🔹 Key idea: Place positives at even indices and negatives at odd indices 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(n) Daily DSA practice to stay consistent and improve logic 🚀 #LeetCode #DSA #Arrays #Python #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
LeetCode | Two Sum II (Sorted Array) 🔢 🔹 Approach: Two Pointers 🔹 Key idea: Move pointers based on sum comparison 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) Daily DSA practice to build strong problem-solving skills 🚀 #LeetCode #DSA #TwoPointers #Arrays #Python #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
Solved leetcode problem: Longest Substring Without Repeating Characters Approach: Use a set to maintain unique characters in the current window. Expand with r. If duplicate appears → shrink from l until valid. Track max window length. Consistent pattern practice > memorizing solutions. #LeetCode #SlidingWindow #Python #DSA #CodingInterview
To view or add a comment, sign in
-
-
LeetCode | Sort Colors 🎨 🔹 Approach: Dutch National Flag Algorithm 🔹 Key idea: Use three pointers (low, mid, high) 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) Daily DSA practice to build strong problem-solving skills 🚀 #LeetCode #DSA #Arrays #Python #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 13 of #100DaysOfLeetCode 📌 Problem Solved: Container With Most Water 🧠 Topic: Two Pointers Approach: Placed two pointers at both ends of the array Calculated area using: area = (right - left) * min(height[left], height[right]) Moved the pointer with the smaller height inward Tracked the maximum area during each step ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) ✨ What I learned today: Instead of checking every possible pair (O(n²)), using two pointers reduces the solution to O(n). The key insight: the smaller height always limits the area. #Day12 #100daysofLeetCode #DSA #Python #TwoPointers #Arrays #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Starting Small with Python – Day 5/5 🐍 Today was all about creating a "Rock,Paper,Scissor Game" which we used to play when we were kids. 🔹 Tech,Tools & Library Used: ▪️Python ▪️PyCharm IDE ▪️Random 📌 This small exercise helped me understand how Python can automate everyday tasks — a simple but powerful use case. Taking it one small step at a time and enjoying the learning process 💡 Extending the 5-day challenge to 10-day challenge to learn and build more. #Python #LearningPython #100DaysOfCode #rockpapergame #PyCharm #StartSmall #CodingJourney
To view or add a comment, sign in
-
Day 42 ✅ | Reverse Linked List Revisited one of the most important linked list problems today. The goal is to reverse the list in-place by carefully adjusting node pointers. Key ideas used: Maintain prev and curr pointers Temporarily store the next node Reverse links step by step while traversing the list This problem is a great reminder that mastering the basics makes harder problems much easier 💪 #Python #LeetCode #LinkedList #ReverseLinkedList #ProblemSolving #Day42 #CodingJourney #DSA #Algorithms #DataStructures
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