🔥 Day 96 — #100DaysOfLeetCode ✅ Problem: Binary Number with Alternating Bits (Easy) Today’s challenge was to check whether a given integer’s binary representation has alternating bits — meaning no two adjacent bits are the same. 🧠 Approach: Convert number to binary. Check if it contains "11" or "00". If yes → not alternating. Otherwise → valid alternating pattern. ⚡ Example n = 5 → binary = 101 → ✔ alternating ⏱ Complexity Time: O(k) Space: O(1) (k = number of bits) #LeetCode #DSA #CodingChallenge #Python #ProblemSolving
Alternating Binary Number Checker
More Relevant Posts
-
LeetCode Problem 3070: "Count submatrices with top left element and sum less than k": You are given a 0-indexed integer matrix grid and an integer k. Return the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k. Approach: use Prefix sum to calculate the total value of submatrix including the top left element upto a given cell. This approach is optimal and straightforward. #Python #DSA #LeetCode #ProblemSolving #CompetitiveProgramming #DailyCoding
To view or add a comment, sign in
-
-
Day 74 Sometimes a problem becomes clearer when you look at it from a different angle. #Day74 🧩 543. Diameter of Binary Tree Revisited this problem and got a better intuition. Key idea: • For every node, calculate the maximum depth of the left subtree • Calculate the maximum depth of the right subtree • The diameter passing through that node becomes: left_depth + right_depth Then track the maximum result globally while recursion returns the depth. What I realized today: Many tree problems become simple once you separate what you return vs what you track globally. Revision is making these patterns clearer. #LeetCode #DSA #Python #BinaryTree #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
LeetCode POTD 💫: Description: Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10**9 + 7. Here are my solutions: Using String Manipulation: https://lnkd.in/g4UpENeF Using Bit Manipulation: https://lnkd.in/gw9PZc7n #Python #DSA #Leetcode #DailyChallenge
To view or add a comment, sign in
-
-
🚀 Day 20 of #100DaysOfLeetCode 📌 Problem Solved: Search Insert Position 🧠 Topic: Binary Search Your approach: Classic binary search If found → return index If not found → return left (correct insert position) Why returning left works: At the loop end, left points to the smallest index where the target can go while keeping the array sorted. ⏱ Time Complexity: O(log n) 💾 Space Complexity: O(1) This is a solid DSA base already. Keep stacking days like this 🔥 #day20 #100daysofLeetCode #DSA #Python #BinarySearch #ConsistencyWins
To view or add a comment, sign in
-
-
✅ Day 6 of #DSAPrep > Problem: Reverse Integer > Platform: LeetCode > Concept: Number Manipulation + Overflow Handling Reversed an integer using modulo (%) and integer division (//). Handled: Negative numbers using a sign variable 32-bit integer overflow constraint Returned 0 if the reversed number goes outside the 32-bit signed integer range > Time Complexity: O(log n) > Space Complexity: O(1) #DSAPrep #Algorithms #Python #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Solved Today’s GeeksforGeeks POTD: Sum of Subarray Minimums using Python 🐍 Problem: Given an array of positive integers, the task is to find the sum of the minimum element of every possible subarray. Approach: A brute-force approach would check all subarrays, leading to O(n²) complexity. Instead, I used a more efficient approach with a Monotonic Stack. ✔️ For each element, we determine: • The Previous Smaller Element (PSE) • The Next Smaller Element (NSE) ✔️ This helps calculate how many subarrays consider that element as their minimum. Contribution formula: Element Contribution = arr[i] × left_count × right_count This allows the problem to be solved efficiently. 💡 Time Complexity: O(n) 💡 Space Complexity: O(n) Consistent practice with DSA problems like this strengthens algorithmic thinking and optimization skills. #geekstreak60 #npci #geeksforgeeks #dsa #python #algorithms #codingpractice #problemSolving
To view or add a comment, sign in
-
-
✅ Day 9 of #DSAPrep > Problem: Square Root of a Number > Platform: LeetCode > Concept: Mathematical Computation Computed the square root of a number using exponentiation, > Key Idea: - num ** 0.5 gives the square root - int() returns the floor value > Example: 36 → 6 > Time Complexity: O(1) > Space Complexity: O(1) Sometimes the simplest approach is the cleanest one ✅ Consistency continues 🚀 #DSAPrep #Python #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Solved Today’s POTD (27 Feb 2026): Number of Submatrix Having Sum = X on GeeksforGeeks using Python 🐍 Problem: Given a matrix of size n × m and an integer x, find the number of square submatrices whose sum of elements equals x. Approach: 🔹 Built a 2D Prefix Sum matrix to compute submatrix sums efficiently 🔹 Iterated over all possible square sizes 🔹 Calculated each square’s sum in O(1) using prefix formula 🔹 Counted squares where sum == x This problem strengthened my understanding of: ✔️ 2D Prefix Sum technique ✔️ How to reduce repeated calculations ✔️ Matrix-based pattern recognition 💡 Time Complexity: O(n³) (Works within constraints) Every day, learning a new pattern. Consistency is turning practice into confidence 💪 #day11 #geekstreak60 #npci #geeksforgeeks #dsa #python #learning #problemsolving #codingjourney
To view or add a comment, sign in
-
-
Here, the global keyword allows the function to modify the global variable directly. Each function call increases the same global value. This problem highlights how functions can create side effects when using globals. Powerful feature — but risky if misused. THE ANSWER IS : C (2) #Python #GlobalKeyword #ControlFlow #AdvancedPython #BuildInPublic
To view or add a comment, sign in
-
-
LeetCode Problem 1461: "Check if a binary string contains all binary codes of size k": Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false. Approach: I simply used a sliding window and a hash map where hash map stores the seen substrings of size k. Two pointers keep track of each substring of size k. A count variable is initialized to 0 which is incremented each time when a unique unseen substring of size k is seen, if this count reaches the max possible number of unique binary codes of size k (i.e. 2^k) the function returns True else False. #LeetCode #Python #BitManipulation #Strings #SlidingWindow #DataStructures #Algorithms #CompetitiveProgramming #ProblemSolving #OptimalSolution
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