Today’s focus shifted toward character-level manipulation using StringBuilder. Instead of only using built-in methods, the goal was to understand how characters can be read, transformed, and written back using logic. What became clearer during practice: - Every character has an ASCII value, which allows manual case conversion - StringBuilder makes it possible to update characters directly without creating new strings - Loop-based transformations help in building real problem-solving thinking, not just method usage One small transformation example: StringBuilder sb = new StringBuilder("PraTiM007"); for (int i = 0; i < sb.length(); i++) { char ch = sb.charAt(i); if (ch >= 'A' && ch <= 'Z') ch = (char)(ch + 32); // convert to lowercase else if (ch >= 'a' && ch <= 'z') ch = (char)(ch - 32); // convert to uppercase sb.setCharAt(i, ch); } System.out.println(sb); Output : pRAtIm007 The biggest realization here: - Real learning starts when logic replaces built-in shortcuts - Small character problems quietly build strong algorithmic thinking Not perfect yet, but the control over strings now feels much more real than before. #java #stringbuilder #problemSolving #codingjourney #learninginpublic #softwaredevelopment
StringBuilder Character Manipulation in Java
More Relevant Posts
-
🚀 Day 23 – LeetCode 1208 | Get Equal Substrings Within Budget Today’s problem focused on optimizing substring transformations under a cost constraint. 🧠 Problem Given two strings "s" and "t", each character change has a cost defined by the ASCII difference. Find the maximum length substring that can be converted within a given budget. 🔍 Key Insight Instead of brute force (O(n²)), convert the problem into: → “Longest subarray with sum ≤ k” This immediately maps to the Sliding Window (Two Pointer) technique. ⚙️ Approach • Calculate cost = |s[i] − t[i]| • Expand window → add cost • If budget exceeded → shrink window • Track max length ⏱ Complexity Time: O(n) Space: O(1) 💻 Code (Java) class Solution { public int equalSubstring(String s, String t, int maxCost) { int left = 0, currentCost = 0, maxLen = 0; for (int right = 0; right < s.length(); right++) { currentCost += Math.abs(s.charAt(right) - t.charAt(right)); while (currentCost > maxCost) { currentCost -= Math.abs(s.charAt(left) - t.charAt(left)); left++; } maxLen = Math.max(maxLen, right - left + 1); } return maxLen; } } 📌 Takeaway Whenever you see: • longest substring • contiguous • sum constraint Think → Sliding Window Pattern recognition > memorizing solutions. #LeetCode #DSA #SlidingWindow #Java #ProblemSolving #CodingInterview #SoftwareEngineering #100DaysOfCode #Developers #TechCareer
To view or add a comment, sign in
-
Today’s focus was on performing multiple text modifications together using StringBuilder. Instead of a single operation, the goal was to understand how real text editing happens step by step — similar to how strings are modified inside real applications. What became clearer during this practice: - StringBuilder allows deleting, inserting, and appending text in the same object - Multiple operations can be chained to simulate real editing workflows - Mutable strings make complex updates simpler and more efficient than normal String operations A small combined example: StringBuilder sb = new StringBuilder("abcdef"); sb.deleteCharAt(3); // abcef sb.append("pqrst"); // abcefpqrst sb.delete(2, 6); // abqrst sb.insert(2, 'g'); // abgqrst sb.insert(5, 10); // abgqr10st sb.insert(6, "xyz"); // abgqr1xyz0st Final output : abgqr1xyz0st The biggest realization here: - Real strength in programming comes from combining small operations into meaningful logic - Understanding mutation and sequence of steps matters more than memorizing methods Progress is becoming more visible now, especially in handling strings with confidence. #java #stringbuilder #problemSolving #codingjourney #learninginpublic #softwaredevelopment
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟱𝟵/𝟭𝟬𝟬 — 𝗢𝗻𝗲 𝗗𝗮𝘆 𝗧𝗼 𝟲𝟬 Day 59. One day away from another milestone. But today? Simple string manipulation. Two pointers. Classic reversal. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟮𝟬𝟬𝟬: Reverse Prefix of Word (Easy) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given a word and a character, reverse the prefix up to the first occurrence of that character. Example: word = "abcdefd", ch = 'd' Result = "dcbaefd" (Reverse "abcd" → "dcba", keep "efd") 𝗧𝗵𝗲 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: Find the index. Two-pointer swap. Done. 👉 Find first occurrence of character 👉 If not found, return original word 👉 Two pointers: left = 0, right = index 👉 Swap characters while moving inward 👉 Return modified string Time: O(n), Space: O(n) for char array 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: Two-pointer reversal. Day 31 used it for linked lists. Day 59 uses it for strings. Same pattern. Different data structure. That's the power of understanding fundamentals—they transfer. 𝗖𝗼𝗱𝗲: https://lnkd.in/g7UXBf_u 59 down. 41 to go. Tomorrow = 60. 𝗗𝗮𝘆 𝟱𝟵/𝟭𝟬𝟬 ✅ #100DaysOfCode #LeetCode #Strings #TwoPointer #Algorithms #ProblemSolving #CodingInterview #Programming #Java #Fundamentals #Day60Tomorrow
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
-
-
Today’s focus moved beyond built-in functions into writing custom reverse logic on a part of a string. Instead of reversing the entire text directly, the idea was to control specific index ranges and apply logic manually. This felt closer to real problem-solving than simple method usage. What became clearer during this step: - Reversing characters manually builds stronger control over indices and loops - StringBuilder allows in-place modification, which keeps the logic efficient - Breaking a problem into start index, end index, and swaps makes complex operations manageable A small example of reversing only the second half: StringBuilder sb = new StringBuilder("abcdef"); int mid = sb.length() / 2; reverse(sb, mid, sb.length() - 1); // reverse second half System.out.println(sb); public static void reverse(StringBuilder sb, int i, int j) { while (i < j) { char t = sb.charAt(i); sb.setCharAt(i, sb.charAt(j)); sb.setCharAt(j, t); i++; j--; } } Output : abcfed The biggest realization here: - Real algorithmic thinking starts when we control the process instead of relying on ready-made methods - Even a simple reverse can teach index handling, swapping logic, and boundary control This step felt like a shift from basic string handling toward actual problem-solving mindset. #java #stringbuilder #algorithms #problemSolving #codingjourney #learninginpublic
To view or add a comment, sign in
-
🚀 Day 17 — Valid Parentheses Continuing the Stack pattern. 🧩 Problem solved: Valid Parentheses 💻 Platform: LeetCode (#20) Given a string containing only '(', ')', '{', '}', '[' and ']', determine if the input string is valid. Example: Input: s = "()[]{}" Output: true Input: s = "([)]" Output: false --- 🧠 First Thought (Brute Force) Repeatedly remove adjacent matching pairs like "()", "[]", "{}" until no more removals are possible. If the string becomes empty → valid. But this leads to O(n²) complexity. Clearly inefficient. --- ⚡ Optimal Approach — Stack (via StringBuilder) Key Insight: A closing bracket must always match the most recently seen opening bracket. That’s exactly what a Stack is built for — LIFO. Twist: Instead of Stack<Character>, I used StringBuilder as the stack. Same logic, lighter overhead. Steps: • Iterate through each character • If top of StringBuilder matches current closing bracket → pop (deleteCharAt) • Otherwise → push (append) • If StringBuilder is empty at end → valid Time Complexity: O(n) Space Complexity: O(n) 🔍 What this problem reinforced: ✔ Stack is the go-to structure when order + matching matters ✔ LIFO logic maps perfectly to nested bracket structures ✔ StringBuilder can simulate a stack — not just for string building! This problem made the Stack pattern click in a new way. Solutions are available here: 🔗https://lnkd.in/gW8atfqw Day-17 complete. ✅ #DSA #Java #LeetCode #Stack #ProblemSolving #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
#100DaysOfCode 🚀 👉Solved: LeetCode 75 – Sort Colors The goal was to sort an array containing only three values: 0 (Red), 1 (White), and 2 (Blue) At first glance this looks like a simple sorting problem. But the twist: ❌ No built-in sort ✔ One pass ✔ Constant space The solution uses the famous **Dutch National Flag Algorithm**. Instead of sorting normally, we maintain three pointers: • low → for 0s • mid → current element • high → for 2s Rules: • If nums[mid] == 0 → swap with low • If nums[mid] == 1 → move mid forward • If nums[mid] == 2 → swap with high This allows sorting the array in a single pass. 📌 Key Points: ✔ In-place sorting ✔ One pass algorithm ✔ Constant space usage ✔ Classic three-pointer technique ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Problems like this show how powerful pointer techniques can be. Day 15✅ #DSA #Java #LeetCode #Algorithms #ProblemSolving #100DaysOfCode #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Day 6 — this problem broke my brain until I thought about it like a chef cutting a sandwich. 🧠 LeetCode 241 — Different Ways to Add Parentheses The problem: Given an expression, return ALL possible results from every different way to place parentheses. 2-1-1 → [0, 2] — same numbers, different brackets, different answers. The insight 💡 Every operator is a potential "last operation." Split there. Solve left. Solve right. Combine every result from both sides. Repeat recursively for every operator. That's it. Divide and Conquer. "2*3-4*5" Split at * → left:"2", right:"3-4*5" Split at - → left:"2*3", right:"4*5" Split at * → left:"2*3-4", right:"5" ... combine all results → [-34,-14,-10,-10,10] Why recursion fits perfectly here: Smaller subexpressions have the same structure as the original. Classic D&C pattern — break, solve, merge. Real world connection 🔗 This is exactly how compilers build Abstract Syntax Trees. Every operator is a split point. Every subexpression becomes a subtree. Day 6 done. Streak alive. 💪 #DSA #LeetCode #Java #DivideAndConquer #Recursion #100DaysOfCode #BackendDeveloper #CompetitiveProgramming
To view or add a comment, sign in
-
-
🔥 Day 83 of #100DaysOfCode Today’s problem: LeetCode: Minimum Size Subarray Sum 🎯 📌 Problem Summary Given: An integer target An array nums Return the minimum length of a contiguous subarray whose sum is greater than or equal to target. If no such subarray exists → return 0. Example: target = 7 nums = [2,3,1,2,4,3] Output → 2 (because [4,3] = 7) 🧠 Approach: Sliding Window (Two Pointers) This is a classic variable-size sliding window problem. ⚙️ Strategy: Use two pointers: l (left) and r (right) Expand window by moving r Keep adding to total When total >= target: Update result Shrink window from left Subtract from total 🔁 Core Logic: for each r: total += nums[r] while total >= target: update min length total -= nums[l] l++ ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 💡 What I Learned Sliding window is extremely powerful for subarray problems. The key is knowing when to expand and when to shrink. Many medium/hard problems are just variations of this pattern. Today’s runtime: ⚡ 1ms (99% faster) Consistency builds mastery. On to Day 84 🚀 #100DaysOfCode #LeetCode #SlidingWindow #Java #DSA #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 Daily LeetCode Challenge – Day 37 Today’s problem was Find All Possible Stable Binary Arrays I. Problem: We are given three integers zero, one, and limit. We need to count the number of stable binary arrays such that: The array contains exactly zero number of 0s. The array contains exactly one number of 1s. Any subarray with size greater than limit must contain both 0 and 1. In simpler terms, we cannot place more than limit consecutive 0s or 1s, otherwise the array becomes unstable. The brute force that came to mind: Generate all possible arrays using the given number of 0s and 1s and then check if they satisfy the limit condition. But this approach quickly becomes inefficient because the number of combinations grows rapidly. 💡 Better Idea – Dynamic Programming with Memoization First, we focus on the limit. The limit tells us the maximum number of identical elements that can appear consecutively. For example, if limit = 2, then sequences like [0,0,0] or [1,1,1] are not allowed because they contain more than two identical elements in a row, which would make the array unstable. To construct valid arrays, we add elements in blocks: ->If the last placed element was 1, the next block must contain 0s. ->If the last placed element was 0, the next block must contain 1s. ->The size of each block can range from 1 to min(remaining elements, limit). This ensures that: we never exceed the number of remaining 0s or 1s we never violate the limit constraint. We recursively explore all valid possibilities while keeping track of: ->remaining 0s ->remaining 1s ->the last placed element. To avoid recomputation, we store previously computed results in a DP table. ⚡ Time Complexity: O(zero × one × limit) ⚡ Space Complexity: O(zero × one) 🔍 Key Insight: Instead of generating all binary arrays, we construct them step by step while respecting the limit constraint and store intermediate results, which turns an exponential brute force solution into an efficient dynamic programming approach. #LeetCode #DailyCodingChallenge #Java #DynamicProgramming #Algorithms #ProblemSolving #CodingInterview
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