🚀 Day 44 of #100DaysOfCode 📌 Problem: 762 – Prime Number of Set Bits in Binary Representation Today I solved an interesting bit manipulation problem on LeetCode that combines binary representation with prime number logic. 🔎 Problem Summary: Given two integers left and right, count how many numbers in that range have a prime number of set bits (1s) in their binary form. 💡 Key Insight: The maximum number of set bits for numbers ≤ 10⁶ is 20. So we only need to check prime numbers up to 20: {2, 3, 5, 7, 11, 13, 17, 19} For each number, count the set bits using: Python Copy code num.bit_count() ✅ Python Solution: Python Copy code class Solution: def countPrimeSetBits(self, left: int, right: int) -> int: primes = {2, 3, 5, 7, 11, 13, 17, 19} count = 0 for num in range(left, right + 1): if num.bit_count() in primes: count += 1 return count ⏱ Time Complexity: O(n) 🧠 Concepts Used: Bit Manipulation | Prime Numbers | Set Every day I’m getting more comfortable with binary operations and optimization techniques. #LeetCode #Day42 #CodingJourney #Python #ProblemSolving #BitManipulation #100DaysOfCode
Counting Prime Set Bits in Binary Numbers
More Relevant Posts
-
How the asyncio event loop actually works? TL;DR: It's a loop that checks: "Which tasks are ready to run right now?" The Event Loop keeps doing the following - 1. Check which tasks are ready 2. Run one task until it hits 'await' 3. Task pauses, switch to next ready task 4. Repeat What Happens code hits await some_operation()? -> Task says: "I'm waiting for I/O" -> Event loop skips it, runs another task -> When I/O completes, task becomes ready again -> Loop picks it up and resumes Catch - Event loop runs in one thread. This is why blocking calls freeze everything. I’m deep-diving into Python internals and performance. Do follow along and tell your experiences in comments. #Python #PythonInternals #SoftwareEngineering #BackendDevelopment #Asyncio
To view or add a comment, sign in
-
-
😵 Thread-local storage works great... until you move to async. Then the weird stuff starts. Request IDs bleeding between coroutines. Background tasks sharing state. “Random” bugs that disappear under logging. Sound familiar? Async doesn’t care about threads. It cares about execution context. In my latest article I explain: 🔍 Why threading.local() fails under asyncio 🧠 How ContextVars isolate state per coroutine ⚙️ Real examples with async tasks and request-scoped data 👉 https://lnkd.in/d_aVTDtW #python #softwaredevelopment #backend #engineering #asyncio
To view or add a comment, sign in
-
Understanding how data structures behave is crucial for writing reliable and scalable Python code. In my latest article, I explore the real difference between Lists and Tuples in Python and why choosing the right one can impact system stability, performance, and trust in real-world applications. From flexibility to stability, this article explains when data should evolve and when it must remain unchanged. Read the full article here: https://lnkd.in/gvQahst3 #Python #DataScience #Programming #Coding #PythonProgramming #SoftwareEngineering #TechLearning #Developers #DataEngineering #Analytics #MachineLearning #AI #TechCommunity #LearnToCode #CareerGrowth
To view or add a comment, sign in
-
A teammate recently ran into this Pandas error: TypeError: argument of type 'float' is not iterable The code looked correct: df.query("Overseas Collection in Crores == 0") The issue? The column name had spaces. query() evaluates the condition as a Python expression. Because the column name contained the word in, Pandas interpreted it as the membership operator. The Fix: df.query("`Overseas Collection in Crores` == 0") Or: df[df["Overseas Collection in Crores"] == 0] Clean column naming conventions help prevent subtle bugs. #Python #Pandas #DataEngineering
To view or add a comment, sign in
-
Day 67 of 365 Days of code the infamous brainrot number Qn 1) Reorder list You are given the head of a singly linked-list. The positions of a linked list of length = 7 for example, can intially be represented as: [0, 1, 2, 3, 4, 5, 6] Reorder the nodes of the linked list to be in the following order: [0, 6, 1, 5, 2, 4, 3] Notice that in the general case for a list of length = n the nodes are reordered to be in the following order: [0, n-1, 1, n-2, 2, n-3, ...] You may not modify the values in the list's nodes, but instead you must reorder the nodes themselves. approach: use 5 pointers(scary :")) #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
🚀 Day 51 of #100DaysOfCode ✅ Solved: 1689. Partitioning Into Minimum Number of Deci-Binary Numbers Today’s problem looked tricky at first, but the solution turned out to be beautifully simple once the pattern was understood. 🔎 Problem Insight: A deci-binary number contains only digits 0 or 1. To form a number like "82734", think about each digit: If a digit is 8, we need at least 8 deci-binary numbers contributing 1 at that position. If a digit is 3, we need at least 3 deci-binary numbers at that position. 👉 So the minimum number of deci-binary numbers required is simply: 📌 The maximum digit in the given number 💡 Example: Input: "82734" Output: 8 🧠 Python Code: Python Copy code class Solution: def minPartitions(self, n: str) -> int: return int(max(n)) ⏱ Time Complexity: O(N) 💾 Space Complexity: O(1) This problem is a great example of how understanding the pattern simplifies the solution dramatically. #LeetCode #ProblemSolving #Python #DataStructures #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Just practiced Pandas and data cleaning hits different when you're working with real messy data. Covered data types, type conversion, handling missing values, replacing inconsistent entries, and using category dtype to save memory — FuelType column went from 11488 bytes to 1460 bytes just by changing the dtype. Notebook here 👉 https://lnkd.in/d3djYPvp #Python #Pandas #DataAnalysis #LearningInPublic
To view or add a comment, sign in
-
LeetCode Problem 83: Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. The below implementation in Python successfully resolves this in time complexity of O(n) where n is length of the list with constant space complexity. The approach is simple, handle the base case first like list having 0 or 1 number of nodes and then write the logic of handling lists of length greater than one. Maintain two pointers, one to keep track of present node and other to keep track of previous node. Check if the value of both nodes match or not, if match update the pointing of previous node, point its next to the present.next. #LeetCode #LinkedList #Python #CompetitiveProgramming #Algorithms #DataStructures #ProblemSolving
To view or add a comment, sign in
-
-
Hello Angel One I would like to report a potential edge-case issue in the historical candle API (getCandleData) that I’m facing while running a Python Smark SDK. Following Code is executed at 2026-02-25 10:29:02 Request: {'exchange': 'NSE', 'symboltoken': '99926000', 'interval': 'ONE_MINUTE', 'fromdate': '2026-02-25 10:25', 'todate': '2026-02-25 10:29'} Response: {'message': "From datetime can't be greater than current datetime", 'errorcode': 'AB1012', 'status': False, 'data': None} Angel One
To view or add a comment, sign in
-
Day 54 of 365 Days of code 1) Capacity to Ship Packages Within D Days Approach: Binary search 1)set low = max(weights) 2) high= low*sum(weights) 3) perform the below steps until low<=high condition fails i) mid=low+(high-low)//2;res=0 ii) set w = mid and initialize day=1 iii) iterate through the loop and perform the stuff i put in screenshot (ahh life hurts :") ) iv) if the day <= days: set res=mid ; set high=mid-1 v) else low=mid+1 4) return res #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
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