🚀 Day 85 of My 100 Days LeetCode Challenge | Java Today’s problem was a beautiful recursion + pattern observation challenge. We had to find the k-th bit in a recursively defined binary string sequence — and the string grows exponentially with each step. Clearly, constructing the entire string was not an option. The breakthrough came from understanding the structure: Each sequence is built as: S(n) = S(n-1) + "1" + reverse(invert(S(n-1))) Once I noticed the symmetry around the middle element and how the second half mirrors the first (with inversion), the solution became a clean recursive reduction instead of brute force. ✅ Problem Solved: Find K-th Bit in N-th Binary String ✔️ All test cases passed (63/63) ⏱️ Runtime: 0 ms (Beats 100%) 🧠 Approach: Recursion + Divide & Conquer + Symmetry Observation 🧩 Key Learnings: ● Never build exponential structures directly — reduce the problem. ● Recursive definitions often hide symmetry. ● The middle element becomes a powerful pivot. ● Mirroring + inversion patterns simplify complex generation problems. ● Think structurally, not sequentially. This problem reminded me that many recursive constructions are just cleverly disguised divide-and-conquer problems. 🔥 Day 85 complete — stronger recursion intuition and pattern recognition sharpening further. #LeetCode #100DaysOfCode #Java #Recursion #DivideAndConquer #ProblemSolving #DSA #CodingJourney #Consistency
Java LeetCode Challenge: K-th Bit in Binary String Sequence
More Relevant Posts
-
🚀 Day 90 of My 100 Days LeetCode Challenge | Java Today’s challenge was a fascinating logic + mathematical insight problem. The task was to generate a binary string that does not exist in a given list of binary strings, where all strings have the same length. Instead of trying every possible combination, the solution becomes much simpler when you use the idea of diagonal flipping. By flipping the i-th bit of the i-th string, we guarantee that the newly created string differs from every string in the list at least in one position. This clever trick ensures the generated string is always unique. ✅ Problem Solved: Find Unique Binary String ✔️ All test cases passed (186/186) ⏱️ Runtime: 0 ms 🧠 Approach: Mathematical Insight (Diagonal Construction) 🧩 Key Learnings: ● Sometimes the smartest solutions come from mathematical reasoning rather than brute force. ● The diagonalization technique guarantees uniqueness. ● Understanding problem constraints can drastically simplify the approach. ● Logical insights can reduce exponential possibilities to linear solutions. ● Elegant algorithms often come from simple observations. This problem was a great reminder that a small logical trick can outperform complex algorithms. 🔥 Day 90 complete — sharpening my problem-solving intuition and algorithmic thinking. #LeetCode #100DaysOfCode #Java #Math #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 95 of My 100 Days LeetCode Challenge | Java Today’s challenge was a grid traversal + simulation problem that required careful observation of patterns. The goal was to find the three largest rhombus border sums in a grid. Unlike regular submatrix problems, this one only considers the border elements of rhombus shapes, which makes the calculation a bit more tricky. The approach involved exploring each cell as a potential rhombus center, expanding possible rhombus sizes, and calculating the sum of the boundary elements while ensuring the rhombus stays within grid limits. A TreeSet helped efficiently keep track of the top three unique sums. ✅ Problem Solved: Get Biggest Three Rhombus Sums in a Grid ✔️ All test cases passed (117/117) ⏱️ Runtime: 217 ms 🧠 Approach: Grid Traversal + Simulation + TreeSet 🧩 Key Learnings: ● Grid problems often require careful boundary management. ● Visualizing shapes (like rhombuses) helps simplify implementation. ● TreeSet is useful for maintaining sorted unique values efficiently. ● Simulation-based solutions demand attention to detail. ● Not every grid problem is about rectangles — shapes matter too. This problem was a good reminder that geometric patterns in grids can lead to interesting algorithmic challenges. 🔥 Day 95 complete — improving my grid traversal and pattern-handling skills. #LeetCode #100DaysOfCode #Java #GridProblems #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 10 – LeetCode Practice Today, I solved the Multiply Strings problem on LeetCode: 🎯 Difficulty: Medium 💻 Language Used: Java 💡 Approach: • Given two non-negative integer strings num1 and num2, the task was to return their product as a string without using built-in large number libraries. • I simulated digit-by-digit multiplication similar to how we multiply numbers on paper: – Reversed both strings and multiplied each digit pair. – Stored intermediate results in a result array and used carry propagation. – Finally built the resulting string by trimming leading zeros. ⏱ Complexity: • Time Complexity: O(n × m) (where n and m are lengths of num1 and num2) • Space Complexity: O(n + m) 📚 Key Takeaway: This problem strengthened my understanding of number manipulation at the string level and how to implement arithmetic logic without relying on built-in big integer functions — a useful technique for handling large numeric inputs. Consistent problem-solving practice continues to build my algorithmic intuition and implementation skills. 💪 #LeetCode #Java #DSA #Strings #Algorithms #ProblemSolving #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 11 of #50DaysLeetCode Challenge Today I tackled a HARD problem: “Regular Expression Matching” on LeetCode using Java. 🔹 Problem: Given a string "s" and a pattern "p", implement regex matching with support for: • "." → matches any single character • "*" → matches zero or more of the preceding element Return true if the entire string matches the pattern. Example: Input: "s = "aa", p = "a*"" → Output: "true" Input: "s = "aa", p = "a"" → Output: "false" 🔹 Approach I Used: I used Dynamic Programming (DP) — anything else here is inefficient or breaks on edge cases. ✔ Created a 2D DP table "dp[m+1][n+1]" ✔ "dp[i][j]" represents whether "s[0...i-1]" matches "p[0...j-1]" ✔ Handled "*" carefully: - Treat it as zero occurrence → "dp[i][j-2]" - Or one/more occurrence → match previous character ✔ Built the solution bottom-up 🔹 Concepts Practiced: • Dynamic Programming (2D DP) • String pattern matching • Handling complex edge cases #LeetCode #DSA #Java #DynamicProgramming #Algorithms #CodingChallenge #50DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 93 of My 100 Days LeetCode Challenge | Java Today’s problem explored recursion and backtracking, focusing on generating valid strings under specific constraints. The challenge was to generate happy strings of length n, where: The string consists only of 'a', 'b', and 'c' No two adjacent characters are the same From all possible happy strings, the goal was to find the k-th lexicographical string. To solve this, I used a backtracking approach that builds the string step by step. At each step, we try adding characters while ensuring they don't match the previous character. This naturally generates all valid happy strings in lexicographical order. Once all valid strings are generated, we simply return the k-th one if it exists. ✅ Problem Solved: The k-th Lexicographical Happy String of Length n ✔️ All test cases passed (345/345) ⏱️ Runtime: 22 ms 🧠 Approach: Backtracking + Recursion 🧩 Key Learnings: ● Backtracking is ideal for generating constrained combinations. ● Pruning invalid states early improves efficiency. ● Recursion makes exploring possible paths intuitive. ● Lexicographical generation often comes naturally with ordered iteration. ● Constraint-based string generation is a common interview pattern. This problem was a great exercise in systematically exploring possibilities while enforcing constraints. 🔥 Day 93 complete — strengthening recursion and backtracking intuition. #LeetCode #100DaysOfCode #Java #Backtracking #Recursion #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 97 of My 100 Days LeetCode Challenge | Java Today’s problem was a solid exercise in matrix processing and prefix sum optimization. The goal was to count the number of submatrices whose sum is less than or equal to a given value (k). A brute-force approach would be too slow, so the key was to use 2D prefix sums to efficiently compute submatrix sums. By converting the matrix into a prefix sum matrix, we can calculate the sum of any submatrix in constant time, making the overall solution much more efficient. ✅ Problem Solved: Count Submatrices With Sum ≤ K ✔️ All test cases passed (859/859) ⏱️ Runtime: 7 ms 🧠 Approach: 2D Prefix Sum 🧩 Key Learnings: ● Prefix sums are powerful for optimizing repeated range sum queries. ● 2D prefix sums extend the same idea from arrays to matrices. ● Preprocessing can drastically reduce computation time. ● Avoiding brute force is key in large input problems. ● Matrix problems often become easier with the right transformation. This problem reinforced how preprocessing techniques like prefix sums can turn complex problems into efficient solutions. 🔥 Day 97 complete — sharpening matrix optimization and prefix sum skills. #LeetCode #100DaysOfCode #Java #PrefixSum #Matrix #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 10 – LeetCode Practice Today, I solved the Combination Sum II problem on LeetCode: 🎯 Difficulty: Medium 💻 Language Used: Java 💡 Approach: • Given a list of candidate numbers (may contain duplicates) and a target, the goal was to find all unique combinations where the numbers sum to the target. • I applied a backtracking approach with careful duplicate handling: – Sorted the array to group duplicates. – During recursion, skipped elements that were the same as the previous at the same recursive level to avoid duplicate combinations. • This strategy ensured all valid combinations were found without repetition. ⏱ Complexity: • Time Complexity: depends on number of valid combinations • Space Complexity: O(n) for recursion stack 📚 Key Takeaway: This problem taught how sorting + backtracking + pruning helps explore the solution space efficiently and avoid duplicate results. Backtracking remains a powerful technique for combinatorial search. Consistent problem solving practice continues to strengthen my algorithmic intuition and confidence. 💪 #LeetCode #Java #DSA #Backtracking #Algorithms #ProblemSolving #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 11 – LeetCode Practice Today, I solved the Wildcard Matching problem on LeetCode: 🎯 Difficulty: Hard 💻 Language Used: Java 💡 Problem Overview: Given a string s and a pattern p, determine if the string matches the pattern. The pattern can contain special wildcard characters: ? → matches any single character * → matches any sequence of characters (including empty) The match must cover the entire string, not just a substring. 💡 Approach: I used a Dynamic Programming (DP) approach. Created a dp table where dp[i][j] represents whether the first i characters of string s match the first j characters of pattern p. If characters match or pattern has ?, we move diagonally in the DP table. If pattern contains *, it can represent: empty sequence → dp[i][j-1] multiple characters → dp[i-1][j] Finally, dp[m][n] gives the final result. ⏱ Complexity Time Complexity: O(m × n) Space Complexity: O(m × n) (where m = length of string, n = length of pattern) 📚 Key Takeaway This problem strengthened my understanding of Dynamic Programming for string pattern matching, especially handling flexible wildcards like * which can represent multiple states. Consistent practice is helping me recognize patterns and improve problem-solving speed. 💪 #LeetCode #Java #DSA #DynamicProgramming #Algorithms #ProblemSolving #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
#GenAI #RagforJAVA Few months ago I tried to build a RAG system in Java. I found 47 Python tutorials and exactly zero complete Java examples. So I figured it out the hard way : and wrote down everything I learned. Here's what nobody tells you about RAG in Java: The concept is simple. Two pipelines: #Ingest your docs (chunk → embed → store) #Answer questions (embed query → retrieve → prompt → LLM) The implementation is where it gets interesting. 𝗖𝗵𝘂𝗻𝗸𝗶𝗻𝗴 matters more than the model. I've seen teams obsess over GPT-4 vs Claude while their chunks are 2000 tokens with no overlap. Fix chunking first. 𝗬𝗼𝘂 𝗱𝗼𝗻'𝘁 𝗻𝗲𝗲𝗱 𝗮 𝗳𝗮𝗻𝗰𝘆 𝘃𝗲𝗰𝘁𝗼𝗿 𝗗𝗕 𝘁𝗼 𝘀𝘁𝗮𝗿𝘁. If you already use PostgreSQL, install pgvector. One extension. You're done. 𝗦𝗽𝗿𝗶𝗻𝗴 𝗔𝗜 𝗵𝗮𝘀 𝗺𝗮𝘁𝘂𝗿𝗲𝗱 𝗮 𝗹𝗼𝘁. VectorStore, EmbeddingModel, ChatClient — it's actually pleasant to work with now. 𝗘𝗺𝗯𝗲𝗱𝗱𝗶𝗻𝗴𝘀 𝗮𝗿𝗲 𝗰𝗵𝗲𝗮𝗽. 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗶𝗼𝗻 𝗶𝘀 𝗻𝗼𝘁. Stop worrying about embedding costs. Watch your LLM token usage instead. 𝗦𝗶𝗺𝗶𝗹𝗮𝗿𝗶𝘁𝘆 𝘁𝗵𝗿𝗲𝘀𝗵𝗼𝗹𝗱𝘀 𝗮𝗿𝗲 𝗺𝗮𝗻𝗱𝗮𝘁𝗼𝗿𝘆. Without one, your LLM gets handed irrelevant junk and hallucinates confidently. Always set withSimilarityThreshold(). I wrote a full guide: architecture diagrams, working Spring Boot code (IngestionService, RagService, REST controller), pgvector setup, chunking strategies, advanced patterns like HyDE and reranking, and a production checklist. All Java. No Python. #Java #SpringBoot #RAG #GenerativeAI #BackendEngineering #LLM
To view or add a comment, sign in
-
Today I solved the Unique Binary String problem on LeetCode using two different approaches in Java. • Method 1 (Optimized – Cantor’s Diagonal Approach) Constructed a new binary string by flipping the i-th bit of the i-th string. This guarantees the generated string differs from every string in the array at least at one position. Time Complexity: O(n) Space Complexity: O(n) (for the result string) • Method 2 (Brute / Less Optimized) Converted each binary string to its decimal representation, stored them, and checked for a number whose binary form (length n) is not present in the list. Time Complexity: O(n²) Space Complexity: O(n) Exploring multiple approaches to the same problem helps strengthen algorithmic thinking and optimization skills. #LeetCode #Java #Algorithms #ProblemSolving #CodingPractice #DataStructures
To view or add a comment, sign in
-
Explore related topics
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