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
StringBuilder Practice: Efficient Text Editing in Java
More Relevant Posts
-
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
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
-
🚀 Day 2/365 – Interleaving String (LeetCode 97) Today’s challenge was a classic Dynamic Programming problem – Interleaving String. 🔎 Problem Statement: Given three strings s1, s2, and s3, determine whether s3 is formed by interleaving s1 and s2 while maintaining the relative order of characters. 🧠 Key Learning At first glance, it looks like a simple string problem. But the real insight was realizing this is a 2D DP grid problem. If: len(s1) + len(s2) != len(s3) 👉 It’s immediately false. Then we build a DP table where: dp[i][j] = whether first i chars of s1 and first j chars of s2 can form first i + j chars of s3. This problem strengthened my understanding of: ✔️ State definition in DP ✔️ Transition logic ✔️ Space optimization (2D → 1D) ✔️ Thinking in terms of grid movement (down = s1, right = s2) 💡 Big Takeaway Most string problems are actually: 👉 Hidden Dynamic Programming 👉 About defining the correct state Consistency > Motivation. On to Day 3 💪 #365DaysOfCode #LeetCode #DynamicProgramming #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 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
-
Day 8/100 – LeetCode Challenge Problem: Trapping Rain Water Today’s problem focused on using the two-pointer technique to calculate how much water can be trapped between elevation bars. Approach: Use two pointers: left and right Maintain two variables: leftMax and rightMax Move the pointer with the smaller height Calculate trapped water using the difference between the current height and the maximum boundary Key Idea: Water trapped at any position depends on the minimum of the maximum heights on both sides. If height[left] < height[right] → process the left side Otherwise → process the right side Complexity: Time: O(n) Space: O(1) Concepts Practiced: Two-pointer technique Greedy decision making Array traversal optimization #100DaysOfCode #LeetCode #DSA #Java #TwoPointers #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
SUM() query stopped working after upgrading to Frappe v16 While upgrading some of my custom apps to v16, I noticed that using SQL aggregation functions like SUM(), COUNT(), or AVG() Etc directly inside Database API calls (such as frappe.get_all() or frappe.get_list() or frappe.get_value()) may no longer work as expected. Frappe v16 is moving toward stricter query validation and discouraging raw SQL expressions inside Database API fields. Modern frameworks are gradually moving toward: • Safer query construction • Better query validation • Database-agnostic code • Cleaner abstraction layers Because of this, Frappe Query Builder is becoming the preferred way to perform aggregations and complex queries. This small shift pushes developers to write more structured, maintainable, and secure database queries. If you're upgrading apps to Frappe v16, it might be a good time to start exploring the Query Builder more deeply. #Frappe #ERPNext #Python #OpenSource
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
-
-
LeetCode 2130 — Maximum Twin Sum of a Linked List This problem gives the head of a linked list with even length. For a list of size n, the iᵗʰ node and the (n−1−i)ᵗʰ node are considered twin nodes. The twin sum is defined as the sum of the values of these two nodes. The task is to return the maximum twin sum in the linked list. Example : Input : 5 → 4 → 2 → 1 Twin pairs : (5,1) → sum = 6 (4,2) → sum = 6 Output : 6 Approach used — Reverse Second Half + Twin Traversal Because twin nodes lie symmetrically from the start and end, the list can be processed efficiently by reversing half of it. Two main steps are used during traversal. • First, fast and slow pointers are used to locate the middle of the linked list. - slow moves one step at a time. - fast moves two steps at a time. When fast reaches the end, slow will be positioned at the start of the second half. • The second half of the list is then reversed so that twin nodes align during traversal. After reversing : - One pointer starts from the beginning of the list. - Another pointer starts from the reversed second half. At each step : - The twin sum is calculated. - The maximum twin sum is updated. This approach works in O(n) time and O(1) extra space. #leetcode #datastructures #linkedlist #java #problemSolving
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
-
-
Solved LeetCode Medium – 1536. Minimum Swaps to Arrange a Binary Grid today! 💻 Instead of actually swapping rows in the grid, I optimized the solution by tracking trailing zero counts per row and performing swaps on that array. This significantly simplifies the implementation and improves readability. Approach I Followed 1. Count Trailing Zeroes in Each Row For each row in the grid, traverse from the rightmost column. Count how many continuous zeroes appear at the end of that row. Store these counts in an array zeroes[i]. Example: Row: [1,0,0,0] → trailing zeroes = 3 Row: [1,1,0,0] → trailing zeroes = 2 2. Determine Required Zeroes per Row For row i, we need at least: requiredZeroes = n - i - 1 Because every row above must have enough zeros so that all elements above the main diagonal are zero. 3. Find a Suitable Row Search for the first row j ≥ i that has enough trailing zeroes. If no such row exists → return -1 (arrangement impossible). 4. Bring That Row Up Using Adjacent Swaps Swap row j upward until it reaches position i. Each adjacent swap increases the swap count. Instead of swapping rows in the grid, swap values in the zeroes array. This simulates the required row movement efficiently. 5. Continue Until Grid is Valid Repeat for every row until all constraints are satisfied. ✅ Time Complexity: O(n²) ✅ Space Complexity: O(n) It was a great exercise in greedy thinking, array manipulation, and edge-case handling. Always satisfying to break down a tricky grid problem into a simpler representation! 🚀 #LeetCode #DSA #Java #CodingPractice #GreedyAlgorithm #ProblemSolving #SoftwareEngineering
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