Continuing further with the Strings module today. This part focused on how strings interact with numbers and type conversion, and how built-in functionality can simplify problems that would normally require loops or extra logic. Understanding string concatenation behavior and converting integers to strings showed how flexible strings are in computation as well. int n = 1256; String s = Integer.toString(n); System.out.println(s.length()); // 4 What became clear : - Strings can be used as a tool for computation, not just for storing text - Converting numbers to strings can simplify certain logical problems - Some problems that look loop-based can be solved using built-in conversions - Thinking in terms of data representation becomes important in DSA This felt like a small but meaningful shift toward smarter problem solving instead of longer code. Still progressing through the Strings module. #Java #DSA #Strings #LearningInPublic #ProblemSolving #CodingJourney #Programming #JavaDeveloper #DeveloperJourney
Java Strings in Computation and Problem Solving
More Relevant Posts
-
Continuing with the Strings module. The focus shifted from basic string handling to actually solving problems using string logic. This involved counting specific characters, working with substrings, and understanding how nested loops apply to text just like they do with arrays. String s = "abcd"; for (int i = 0; i < s.length(); i++) { for (int j = i + 1; j <= s.length(); j++) { System.out.print(s.substring(i, j)); } System.out.println(); } Output: a ab abc abcd b bc bcd c cd d What became clear : - String problems often require nested loop thinking, similar to matrix traversal - Substrings help break a large problem into smaller continuous parts - Time complexity starts to matter once we generate all possible substrings - Logic matters more than syntax in problem-solving questions This felt like the point where Strings stopped being just text handling and started becoming real DSA practice. Continuing deeper into Strings. #Java #DSA #Strings #LearningInPublic #ProblemSolving #CodingJourney #Programming #JavaDeveloper #DeveloperJourney
To view or add a comment, sign in
-
Day 64/100: The "Special Binary String" Puzzle 🧩 Today's challenge was a fascinating problem that combines recursion with sorting logic - "Make Largest Special Binary String". At first glance, this problem seems deceptively simple. We're given a special binary string (defined recursively as a string that can be composed of smaller special strings concatenated together), and we need to rearrange it to form the lexicographically largest possible special string. The key insight? Special binary strings are essentially valid parentheses where '1' represents '(' and '0' represents ')'. This transforms the problem into finding valid parenthetical groupings and recursively optimizing them! My Approach: Track the balance of 1s and 0s while traversing the string Whenever the balance returns to zero, we've found a valid "special" substring Recursively process each inner substring Sort all special substrings in descending order and concatenate Wrap each processed result with '1' and '0' The trickiest part was understanding that each special substring needs to be transformed independently before sorting them at the current level. This ensures we're always working with the "largest" version at every nesting level. Runtime: 4ms (beats 15.40%) Memory: 43.13 MB (beats 79.62%) Learning to see binary strings as parentheses opened up a whole new perspective on this problem! Sometimes the hardest part isn't writing the code, but recognizing the pattern hiding in plain sight. 🔍 #100DaysOfCode #LeetCode #Java #CodingChallenge #Algorithms #ProblemSolving #Recursion #BinaryStrings #Programming #DeveloperJourney #CodeNewbie #TechCommunity #StringManipulation #DataStructures #Day64
To view or add a comment, sign in
-
-
🎯 Day 68 of #100DaysOfCode 📌 Problem: Combination Sum II Today's challenge was a twist on the classic combination sum problem! Each number in candidates can only be used once, and the solution set must not contain duplicate combinations. 🧠 Approach: Sorted the array first to handle duplicates efficiently Used recursion with backtracking Skipped duplicate elements to avoid repeated combinations Explored all possible combinations by picking/unpicking elements 📊 Stats: ✅ 176/176 test cases passed ⚡ Runtime: 6 ms | Beats 73.38% 💾 Memory: 45.61 MB | Beats 19.56% 📝 Takeaway: The key challenge was avoiding duplicate combinations while ensuring each element is used at most once. Sorting + skipping duplicates during recursion made this elegant. Memory optimization is the next frontier! 🔗 Problem: Combination Sum II 🏷️ #LeetCode #CodingChallenge #Java #Backtracking #Recursion #Algorithms #DuplicateHandling #TechJourney #Programming
To view or add a comment, sign in
-
-
🚀 Day 88 of 100 Days of LeetCode Problem: Min Cost Climbing Stairs Difficulty: Easy Today’s problem was another classic Dynamic Programming pattern. Each step has a cost, and you can climb either 1 or 2 steps at a time. The goal is to reach the top with the minimum total cost. You can start from index 0 or index 1. The key idea: To reach step i, you must come from either i-1 or i-2. So the recurrence becomes: dp[i] = cost[i] + min(dp[i-1], dp[i-2]) Finally, since you can reach the top from the last or second-last step: answer = min(dp[n-1], dp[n-2]) This problem reinforces the “take minimum of previous two states” DP pattern — very similar to Climbing Stairs but focused on cost minimization instead of counting ways. Time Complexity: O(n) Space Complexity: O(n) → can be optimized to O(1) Another solid DP variation completed. On to Day 89 💪 #LeetCode #100DaysOfCode #DSA #DynamicProgramming #Java #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode Problem Solved: Maximum Average Subarray I Day 14 of #75DaysofLeetCode Today I solved LeetCode 643 – Maximum Average Subarray I using the Sliding Window Technique. 🔹 Problem: Given an integer array nums and an integer k, find a contiguous subarray of length k that has the maximum average value. 🔹 Key Idea: Instead of recalculating the sum of every subarray of size k, we use the Sliding Window approach to update the sum efficiently by: • Adding the next element • Removing the previous element from the window This reduces the time complexity from O(n × k) to O(n). 💡 Concept Used: ✔ Sliding Window Algorithm ✔ Efficient Array Traversal ✔ Optimized Time Complexity 📌 Example: Input: nums = [1,12,-5,-6,50,3], k = 4 Output: 12.75 ✨ What I Learned: This problem helped me strengthen my understanding of window-based optimization techniques, which are very useful in many array and string problems. 🔗 Practicing data structures and algorithms consistently to improve problem-solving skills. #LeetCode #DSA #SlidingWindow #ProblemSolving #CodingPractice #Java #LearningInPublic #Programming
To view or add a comment, sign in
-
-
𝐉𝐚𝐯𝐚 𝐂𝐨𝐧𝐭𝐫𝐨𝐥 𝐅𝐥𝐨𝐰 𝐢𝐧 𝐀𝐜𝐭𝐢𝐨𝐧: 𝐂𝐋𝐈 𝐂𝐚𝐥𝐜𝐮𝐥𝐚𝐭𝐨𝐫. 🧮 I built a CLI Calculator to test my understanding of Java's control flow statements. Instead of a simple linear script, I implemented: 𝐂𝐨𝐧𝐭𝐢𝐧𝐮𝐨𝐮𝐬 𝐈𝐧𝐩𝐮𝐭: Wrapped the logic in a while loop. 𝐎𝐩𝐞𝐫𝐚𝐭𝐨𝐫 𝐇𝐚𝐧𝐝𝐥𝐢𝐧𝐠: Parsed char inputs to direct program flow. 𝐌𝐚𝐭𝐡 𝐋𝐨𝐠𝐢𝐜: Handled standard and modular arithmetic dynamically. 𝐓𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥 𝐈𝐦𝐩𝐥𝐞𝐦𝐞𝐧𝐭𝐚𝐭𝐢𝐨𝐧𝐬 : 𝐒𝐭𝐚𝐭𝐞 𝐌𝐚𝐧𝐚𝐠𝐞𝐦𝐞𝐧𝐭: Maintained program execution using a while loop. 𝐂𝐨𝐧𝐝𝐢𝐭𝐢𝐨𝐧𝐚𝐥𝐬: Used complex if/else logic to handle operators (+, -, *, /) and modulo (%). 𝐈𝐧𝐩𝐮𝐭 𝐇𝐚𝐧𝐝𝐥𝐢𝐧𝐠: Processed standard input via Scanner for dynamic variable assignment. 𝐂𝐡𝐞𝐜𝐤 𝐨𝐮𝐭 𝐭𝐡𝐞 𝐝𝐞𝐦𝐨 𝐛𝐞𝐥𝐨𝐰. 👇 #Java #Coding #TechTips #LearningInPublic #BackEnd #computer #science #engineering #learning #WeMakeDevs #IntelliJ #100DaysOfCode
To view or add a comment, sign in
-
Wrapping up the core concepts of the Strings module today. The final focus was on understanding what actually happens inside memory when strings are created and compared. Concepts like immutability, string interning, and the difference between == and .equals() made it clear that strings are not just simple text values, but structured objects with specific behavior. String a = "hello"; String b = "hello"; String c = new String("hello"); System.out.println(a == b); // true System.out.println(a == c); // false System.out.println(a.equals(c)); // true What became clear : - Strings in Java are immutable, meaning their value cannot be changed after creation - The string pool allows memory reuse when identical literals are created - "==" compares references, while ".equals()" compares actual content - Understanding memory behavior is essential for writing correct and efficient programs This felt like the point where Strings moved from simple syntax to real computer science understanding. Completed the core learning of the Strings module today. #Java #DSA #Strings #LearningInPublic #ProblemSolving #CodingJourney #Programming #JavaDeveloper #DeveloperJourney
To view or add a comment, sign in
-
#Day_34_of_my_DSA_Journey (mission: abki bar string, array par) Today I solved a classic matrix problem: If any element in a matrix is 0, set its entire row and column to 0. ✅Approach Used (Better Solution – O(m + n) Space) *Instead of modifying the matrix immediately (which can cause incorrect cascading zeros), I used: *A row_marker[] array *A col_marker[] array Step 1: Traverse the matrix and mark rows & columns where 0 appears. Step 2: Traverse again and update cells based on marked rows/columns. ✅Complexity Analysis: *Time Complexity: O(m × n) *Space Complexity: O(m + n) *Key Learning: Never modify data immediately in transformation problems if it can affect future computation. First mark, then update. #Java #DSA #CodingChallenge #ProblemSolving #Matrix #Programming #LearningByDoing
To view or add a comment, sign in
-
-
Understanding Data Types can completely change how you write code 👨💻 This visual explains something every programmer must master: Type Declaration, Arithmetic, and Type Conversion. 🔹 When you assign 3.5 to an int, it becomes 3 That’s called demotion → precision is lost. 🔹 When you assign 8 to a float, it becomes 8.0 That’s promotion → precision is preserved. Now look at division: 5 / 2 = 2 → because both are integers 5.0 / 2 = 2.5 → because one operand is float Same numbers. Different data types. Different results. This is why understanding type casting and arithmetic behavior is fundamental in C, C++, Java, and many other languages. Small concepts like this prevent big logical errors in real-world applications. #Programming #CProgramming #CPP #CodingBasics #SoftwareDevelopment
To view or add a comment, sign in
-
-
Functors, applicatives, and friends "Programming is about abstraction, since you can't manipulate individual sub-atomic particles on your circuit boards. Some abstractions are well-known because they're rooted in mathematics. Particularly, category theory has proven to be fertile ground for functional programming. Some of the concepts from category theory apply to object-oriented programming as well; all you need is generics, which is a feature of both C# and Java." https://lnkd.in/eAcy-2f5
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