💡 Check if a Number is an Armstrong Number 🐢 Optimal Approach 🔹 Count the number of digits in the given number 🔹 For each digit, raise it to the power of total digits and sum them 🔹 If the sum equals the original number → it’s an Armstrong number 🕒 Time Complexity: O(log10N + 1) — proportional to the number of digits in N 💾 Space Complexity: O(1) — uses only constant extra space #Python #CodingPractice #ProblemSolving #LearningEveryday #Algorithms #MathLogic #NeelsLearns
How to Check if a Number is an Armstrong Number in Python
More Relevant Posts
-
💡 Big-O & Arrays — Building Strong DSA Foundations In this post, I explore how algorithm efficiency is measured using Big-O Notation and how static vs dynamic arrays differ in performance. These concepts shape how we write scalable, efficient code — the kind that handles real-world data, not just textbook examples. Let’s keep growing, one concept at a time. #DataStructures #Algorithms #BigO #Arrays #Python #LearningJourney #DataScience #Coding
To view or add a comment, sign in
-
#Day20 #100DaysOfCode 🧩 Problem: Given a matrix where each row and column is sorted in increasing order, determine whether a given element x exists in the matrix. 💡 Approach: Instead of searching every element, I used an optimized O(n + m) approach — starting from the top-right corner and moving left or down based on comparisons. #100DaysOfCode #Day20 #Python #CodingChallenge #DataStructures #Algorithms #Matrix #SearchAlgorithm #ProblemSolving
To view or add a comment, sign in
-
-
Day 41 of #180DaysOfCode Today, I leveled up the 𝗿𝗼𝘁𝗮𝘁𝗲𝗱 𝘀𝗼𝗿𝘁𝗲𝗱 𝗮𝗿𝗿𝗮𝘆 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: 𝗦𝗲𝗮𝗿𝗰𝗵 𝘄𝗶𝘁𝗵 𝗗𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝘀! 🔍 When the array contains duplicates, the previous approach needed a tweak. If nums[low] == nums[mid] == nums[high], we can't decide which side is sorted. The solution? Trim duplicates by moving low and high inward, then proceed with the standard rotated search logic. This ensures we still achieve O(log n) performance in most cases, though it can degrade to O(n) with many duplicates. A subtle but important edge case that makes binary search even more interesting! #Python #Algorithms #BinarySearch #RotatedArray #Duplicates #Coding
To view or add a comment, sign in
-
-
🚀Day 80 of #100DaysOfDSA 🚀 Solved LeetCode 451 — Sort Characters By Frequency 🔹 Problem: Sort a string based on the frequency of its characters in descending order. 🔹 Approach: Used Hash Map + Sorting 1️⃣ Count frequency of each character using a dictionary 2️⃣ Sort characters by their frequency (descending) 3️⃣ Rebuild the string by repeating characters based on count ✨ Key Insight: Hash maps are great for frequency counting, and sorting by values helps in many pattern-based problems. #LeetCode #DSA #Python #ProblemSolving #HashMap #Sorting #CodingJourney #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Day 12 of #100DaysOfLeetCode Problem: 26. Remove Duplicates from Sorted Array Category: Arrays / Two Pointers Today’s problem was about removing duplicates from a sorted array in-place, ensuring each element appears only once and returning the new length. This problem was a great way to strengthen my understanding of two-pointer traversal and array updates without extra space. 🧠 Key Learnings: Used one pointer to track the position of the last unique element while iterating through the array. When a new unique value was found, it was placed at the next available position. Improved confidence in working with in-place modification techniques. Learned to think efficiently — no need for extra arrays or memory allocation. 🎯 Takeaway: Understanding how to manipulate arrays in-place is key to writing space-optimized and interview-ready code. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Arrays #TwoPointers #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
Day 9 of #30DaysOfCode | LeetCode Problem 3. Longest Substring Without Repeating Characters Implemented an optimized Sliding Window approach to find the length of the longest substring without repeating characters. By maintaining a dynamic window using two pointers and a hash set, the algorithm achieves O(n) time complexity while efficiently managing unique character sequences. #Python #LeetCode #CodingChallenge #ProblemSolving #DataStructures #Algorithms #DSA
To view or add a comment, sign in
-
-
“I just watched a video on building your first machine learning model in Python. Honestly? At first, I didn’t understand much — all the code, datasets, and algorithms felt overwhelming. But here’s the thing: ML isn’t just about memorizing code. It’s about understanding the idea: teaching a computer to recognize patterns and make predictions. Watching the video made me realize that the journey starts with small steps, and trying things yourself. I’m excited to dig deeper and actually build my first model soon! #MachineLearning #Python #LearningJourney #DataScience”
To view or add a comment, sign in
-
-
Focus on Array Manipulation & Efficiency Diving deep into NumPy fundamentals! 🐍 This experiment covers everything from creating 1D, 2D, and 3D arrays to generating special arrays (zeros, ones, identity). We also explored crucial operations like reshaping, slicing, and arithmetic on arrays. NumPy is non-negotiable for efficient numerical computation in Python! #NumPy #Python #ScientificComputing #DataScience #Coding
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