Day 56: Bit-Heavy Sorting 🔢 Problem 1356: Sort Integers by The Number of 1 Bits The mission: Sort an array based on the number of set bits (1s). If there’s a tie, the smaller number wins. The Strategy: • Custom Sort: Swapped a standard sort for a bit-count comparison. • Tie-Breaking: Used Integer.bitCount() to compare 1s, then fell back to raw values if counts were equal. • Bubble Logic: Implemented a nested loop to bubble the "heavier" bit counts to the end. Is O(n²) the fastest way? Definitely not. Does it get the green checkmark for today? Absolutely. Sometimes simple logic just hits different. 🚀 #LeetCode #Java #BitManipulation #Algorithms #Coding #DailyCode
Java Bit-Heavy Sorting Challenge: Counting 1 Bits
More Relevant Posts
-
Day 65: The "One-Liner" Win 🎯 Problem 1784: Check if Binary String Has at Most One Segment of Ones Today was a lesson in simplifying logic. The challenge: check if a binary string contains more than one contiguous segment of '1's, given that the string starts with '1'. The Strategy: • Observation: If there are multiple segments of '1's, they must be separated by at least one '0'. • The Pattern: In a string starting with '1', any "new" segment of ones would look like "01" somewhere in the string. • The Execution: A simple !s.contains("01") handles the entire check. Sometimes we hunt for complex algorithms when a single string method is the ultimate counter. Clean, readable, and passed all test cases. 🚀 #LeetCode #Java #StringManipulation #Coding #Efficiency #DailyCode
To view or add a comment, sign in
-
-
🚀 LeetCode Problem || Count Submatrices With Equal Frequency of X and Y(3212) Today I worked on a problem where we need to count submatrices based on a condition involving characters in a grid. 🧩 Problem Idea We are given a grid containing: 'X' → treated as +1 'Y' → treated as -1 '.' → treated as 0 We need to count submatrices where: ✔ The total sum is 0 ✔ And at least one 'X' is present #Java #DSA #LeetCode #Matrix #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 82/100 – LeetCode Challenge ✅ Problem: #43 Multiply Strings Difficulty: Medium Language: Java Approach: Manual Multiplication with Result Array Time Complexity: O(n × m) Space Complexity: O(n + m) Key Insight: Multiply digits from right to left (least significant first). Store intermediate results in array where index i + j + 1 holds current digit. Handle carry by adding to previous index. Solution Brief: Edge case: if either number is "0", return "0". Created result array of size n1 + n2 (max possible digits). Nested loops multiply each digit of num1 with each digit of num2. Accumulated results with proper carry handling. Built final string skipping leading zeros. #LeetCode #Day82 #100DaysOfCode #Math #String #Java #Algorithm #CodingChallenge #ProblemSolving #MultiplyStrings #MediumProblem #Multiplication #Array #DSA
To view or add a comment, sign in
-
-
🔥 Day-11 — Longest Substring Without Repeating Characters 🧩 Problem: Longest Substring Without Repeating Characters 💻 Platform: LeetCode (#3) This problem forced me to truly understand the Sliding Window pattern. Brute force checks every substring. That’s inefficient. Optimal approach: ✔ Use two pointers (left & right) ✔ Expand the window ✔ Shrink when duplicate appears ✔ Track max window size Time Complexity: O(n) Space Complexity: O(n) Big takeaway: If a problem mentions “longest substring” + “no repetition” → Sliding Window should be your first thought. Strings aren’t new logic. They’re just arrays of characters. Day-11 complete. Moving deeper into string patterns 🚀 #30DaysOfCode #LeetCode #DSA #Java #SlidingWindow #Algorithms #ProblemSolving #Developers
To view or add a comment, sign in
-
-
Day 33 of Daily DSA 🚀 Solved LeetCode 58: Length of Last Word ✅ Problem: Given a string s, return the length of the last word (a sequence of non-space characters). Approach: First, trim() the string to remove trailing spaces Traverse the string from the end Count characters until a space is encountered 💡 Key Insight: Instead of splitting the string (which uses extra space), we can simply iterate backwards for an efficient solution. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.17 MB A simple yet important problem to strengthen string traversal techniques. #DSA #LeetCode #Java #Strings #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Today's Coding Challenge: Rotate Array Took on the Rotate Array problem and focused on getting both correctness and efficiency right. ✅ Implemented an in-place solution with O(n) time complexity and O(1) space ✅ Leveraged the array reversal technique to avoid unnecessary extra memory ✅Performance beats 42.38% of submissions This problem looks simple at first glance, but the real test is optimizing space while keeping the logic clean and bug-free. It’s a solid reminder that understanding underlying patterns always beats brute force. Consistency > intensity. Showing up daily. 💪 #DataStructures #Algorithms #CodingChallenge #Java #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
Day 81/100 – LeetCode Challenge ✅ Problem: #11 Container With Most Water Difficulty: Medium Language: Java Approach: Two Pointers (Greedy Shrinking) Time Complexity: O(n) Space Complexity: O(1) Key Insight: Area = min(height[i], height[j]) × (j - i) Start with widest container (i=0, j=n-1). Move the pointer with smaller height inward — only this can potentially increase area. Solution Brief: Initialized two pointers at both ends. While i < j: Compute current area using smaller height Update max if current area larger Move the pointer with smaller height inward #LeetCode #Day81 #100DaysOfCode #TwoPointers #Java #Algorithm #CodingChallenge #ProblemSolving #ContainerWithMostWater #MediumProblem #Greedy #Array #DSA
To view or add a comment, sign in
-
-
#Day67 of my second #100DaysOfCode Today’s problem pushed me to think carefully about comparisons and sorting logic. DSA • Solved Reverse Pairs (LeetCode 493) — count pairs (i, j) such that i < j and nums[i] > 2 * nums[j] • Brute force: check every pair using nested loops → O(n²) time • Optimal approach: Modified Merge Sort to count valid pairs during merge → O(2n log n) time, O(n) space • Key insight: count pairs across the left and right halves before merging. Another reminder of how divide-and-conquer + merge sort patterns appear in many hard problems. #DSA #Algorithms #LeetCode #MergeSort #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Headline: Cracking the "Largest Rectangle in Histogram" (LeetCode 84) 🚀 I just cleared this classic Hard problem with a 0ms runtime! The challenge is finding the largest area in a histogram in O(n) time. The secret sauce? A Monotonic Stack. By storing indices of bars in increasing order, we can identify the "boundary" for each height in a single pass. Key takeaway: Choosing the right data structure (like a Stack) can turn an expensive O(n^2) search into a lightning-fast linear solution. 👨💻 #LeetCode #Java #Algorithms #DataStructures #CodingLife
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