Starting sorting algorithms made me slow down more than expected. Even with simple logic like Bubble Sort, tracking swaps, passes, and early stopping conditions forces you to think more clearly about how data actually moves. This phase is less about speed and more about precision. Foundations are being strengthened again. . . . . #DSA #Java #SortingAlgorithms #LearningInPublic #InternshipPreparation
Mastering Bubble Sort for DSA
More Relevant Posts
-
Day 23 - Find Minimum in Rotated Sorted Array Technique Used: Modified Binary Search Key Idea: Since the array is rotated but originally sorted, used binary search to identify the pivot (minimum element). Compared mid with end to determine which half is unsorted and adjusted boundaries accordingly. Time Complexity: O(log n) #Day23 #LeetCode #Java #BinarySearch #DSA #Algorithms
To view or add a comment, sign in
-
-
#Postlog122 🚀 Tackled a classic Graph problem on 𝗚𝗲𝗲𝗸𝘀𝗳𝗼𝗿𝗚𝗲𝗲𝗸𝘀 :𝗨𝗻𝗱𝗶𝗿𝗲𝗰𝘁𝗲𝗱 𝗚𝗿𝗮𝗽𝗵 𝗖𝘆𝗰𝗹𝗲. 🔗 Detecting cycles in a graph is a fundamental concept, useful in everything from deadlock detection to network analysis. For an undirected graph, the logic requires a small but crucial tweak compared to directed graphs. 📝 𝗧𝗵𝗲 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: I used 𝗗𝗲𝗽𝘁𝗵 𝗙𝗶𝗿𝘀𝘁 𝗦𝗲𝗮𝗿𝗰𝗵 (𝗗𝗙𝗦) to traverse the graph. 💡 𝗞𝗲𝘆 𝗟𝗼𝗴𝗶𝗰: 𝗩𝗶𝘀𝗶𝘁𝗲𝗱 𝗔𝗿𝗿𝗮𝘆: To keep track of nodes we've processed. 𝗣𝗮𝗿𝗲𝗻𝘁 𝗧𝗿𝗮𝗰𝗸𝗶𝗻𝗴: The most important part! We pass the parent node in the recursive DFS call. 𝗧𝗵𝗲 𝗖𝘆𝗰𝗹𝗲 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻: If we encounter a neighbor that is already visited AND is not the parent of the current node, that means we've found a back edge, indicating a cycle exists. 🔄 𝗗𝗶𝘀𝗰𝗼𝗻𝗻𝗲𝗰𝘁𝗲𝗱 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀: To ensure complete coverage, I iterated through all vertices to handle graphs with multiple disconnected components. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: 𝗧𝗶𝗺𝗲: 𝗢(𝗩 + 𝗘) 𝗦𝗽𝗮𝗰𝗲: 𝗢(𝗩) #Java #DSA #GraphTheory #GeeksforGeeks #CodingChallenge #Algorithms #DataStructures
To view or add a comment, sign in
-
-
Day 71/100 – LeetCode Challenge ✅ Problem: #1356 Sort Integers by The Number of 1 Bits Difficulty: Easy Language: Java Approach: Custom Comparator with Bit Counting Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Sort integers based on number of set bits (1s in binary representation). If bit counts are equal, sort by natural integer order. Use Integer.bitCount() for efficient population count. Solution Brief: Converted primitive array to Integer[] for custom sorting. Applied Arrays.sort() with comparator: Compare bitCount(a) vs bitCount(b) If equal, compare integers directly using a.compareTo(b) Converted back to primitive array. #LeetCode #Day71 #100DaysOfCode #Sorting #Java #Algorithm #CodingChallenge #ProblemSolving #SortByBits #EasyProblem #BitManipulation #Comparator #DSA
To view or add a comment, sign in
-
-
Day 3 of Daily DSA 🚀 Solved LeetCode 1: Two Sum Approach: Used a HashMap to store numbers with their indices. For each element, checked if the complement (target - current) already exists. Complexity: • Time: O(n) • Space: O(n) Performance: Runtime: 2 ms (Beats 99.15%) Memory: 47.34 MB Focusing on writing clean and efficient solutions before over-optimizing. Consistency > Intensity 💯 #DSA #LeetCode #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
After exploring path-based recursion, I moved to generating all subsets of a string. This introduced a very clean pattern - For every element, you either include it or exclude it. That’s it. But that “either-or” creates a full decision tree. What became clear here: - Every element creates two branches. - Total subsets = 2ⁿ (tree expansion becomes visible). - Recursion can systematically explore combinations. - The structure is more important than the syntax. Core logic : if (index == str.length()) { System.out.println(current); return; } subset(index + 1, current + str.charAt(index)); // include subset(index + 1, current); // exclude This is where recursion started feeling predictable. Once the pattern is seen, similar problems start looking connected. #recursion #java #dsajourney #backtracking #problemSolving
To view or add a comment, sign in
-
Day 20 of Daily DSA 🚀 Solved LeetCode 179: Largest Number ✅ Approach: Converted all integers to strings and used a custom comparator while sorting. For two numbers a and b, we compare: a + b vs b + a This ensures the order that forms the largest possible number. Edge Case Handled 💡 If the highest element after sorting is "0", then the entire array contains zeros → return "0" instead of "000". ⏱ Complexity: • Time: O(n log n) — sorting with custom comparator • Space: O(n) — string array 📊 LeetCode Stats: • Runtime: 6 ms (Beats 96.21%) ⚡ • Memory: 44.96 MB (Beats 76.86%) Comparator-based problems really sharpen logical thinking 🔥 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Sorting #Consistency
To view or add a comment, sign in
-
-
Day 25 of Practicing DSA on LeetCode Solved: • (540) Single Element in a Sorted Array – Medium Focused on: -Applying binary search on index patterns -Using even–odd index logic to narrow the search space -Achieving O(log n) time with O(1) extra space -Avoiding brute force by trusting array structure This problem showed how sorted data + index patterns = powerful optimizations. Think in patterns, not positions. Consistency over everything. #DSA #Java #LeetCode #BinarySearch #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 15 of Daily DSA 🚀 Solved LeetCode 540: Single Element in a Sorted Array ✅ Approach: Used Binary Search on indices instead of values. Since elements appear in pairs, the unique element breaks the pairing pattern. By forcing mid to be even and comparing nums[mid] with nums[mid + 1], we can safely discard half of the array each time. ⏱ Complexity: • Time: O(log n) — binary search • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 52.96 MB (Beats 57.60%) A neat example of how index properties make binary search even more powerful. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 6 of Daily DSA 🚀 Solved LeetCode 977: Squares of a Sorted Array Approach: Used the two-pointer technique to compare squares from both ends of the array and build the result from back to front. This avoids extra sorting and keeps the solution optimal. Complexity: • Time: O(n) • Space: O(n) LeetCode Stats: • Runtime: 1 ms (Beats 99.80%) • Memory: 47.21 MB (Beats 74.22%) This problem reinforced how understanding data patterns can help eliminate unnecessary operations like sorting. #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
#𝐏𝐨𝐬𝐭𝐋𝐨𝐠118 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 777 – 𝐒𝐰𝐚𝐩 𝐀𝐝𝐣𝐚𝐜𝐞𝐧𝐭 𝐢𝐧 𝐋𝐑 𝐒𝐭𝐫𝐢𝐧𝐠 At first glance, this looks like a string manipulation problem. But once you slow down, the real challenge is understanding 𝐰𝐡𝐚𝐭 𝐢𝐬 𝐧𝐨𝐭 𝐚𝐥𝐥𝐨𝐰𝐞𝐝. 𝐊𝐞𝐲 𝐎𝐛𝐬𝐞𝐫𝐯𝐚𝐭𝐢𝐨𝐧𝐬: ~'𝐋' 𝐜𝐚𝐧 𝐨𝐧𝐥𝐲 𝐦𝐨𝐯𝐞 𝐥𝐞𝐟𝐭 ~'𝐑' 𝐜𝐚𝐧 𝐨𝐧𝐥𝐲 𝐦𝐨𝐯𝐞 𝐫𝐢𝐠𝐡𝐭 ~'𝐗' 𝐢𝐬 𝐣𝐮𝐬𝐭 𝐚 𝐩𝐥𝐚𝐜𝐞𝐡𝐨𝐥𝐝𝐞𝐫 (𝐟𝐫𝐞𝐞 𝐬𝐩𝐚𝐜𝐞) 𝐒𝐨 𝐢𝐧𝐬𝐭𝐞𝐚𝐝 𝐨𝐟 𝐬𝐢𝐦𝐮𝐥𝐚𝐭𝐢𝐧𝐠 𝐬𝐰𝐚𝐩𝐬, 𝐭𝐡𝐞 𝐩𝐫𝐨𝐛𝐥𝐞𝐦 𝐛𝐞𝐜𝐨𝐦𝐞𝐬 𝐚 𝐯𝐚𝐥𝐢𝐝𝐚𝐭𝐢𝐨𝐧 𝐭𝐚𝐬𝐤. 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 1.Use 𝐭𝐰𝐨 𝐩𝐨𝐢𝐧𝐭𝐞𝐫𝐬 on start and result 2.Skip all 'X' characters in both strings 3.Compare the next meaningful characters: ~They must match (L with L, R with R) ~'L' cannot move to the right → its index in start must be ≥ index in result ~'R' cannot move to the left → its index in start must be ≤ index in result If all checks pass, the transformation is valid #PostLog #LeetCode #DSA #ProblemSolving #TwoPointers #Algorithms #Java
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