One smart swap can completely change a string. Day 53 of 100 Days DSA Today’s problem was to find the lexicographically largest string possible with at most one swap. The key idea was tracking the largest character on the right side of every position and performing the first swap that increases the string order. A simple observation leads to an efficient O(n) solution. #100DaysOfCode #DSA #Java #CodingJourney #ProblemSolving #AMU #AligarhMuslimUniversity
Lexicographically Largest String with One Swap
More Relevant Posts
-
🚀 Day 34/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 709. To Lower Case Used ASCII manipulation to convert uppercase letters to lowercase by adding 32, without using built-in functions. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) Strengthening understanding of character encoding and string manipulation basics. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 66 — LeetCode Progress (Java) Problem: Find the Difference of Two Arrays Required: Given two integer arrays, return: Elements present in nums1 but not in nums2 Elements present in nums2 but not in nums1 Idea: Use sets to remove duplicates and quickly check membership. Approach: Convert both arrays into sets Iterate over nums1 set: Add elements not present in nums2 set to result1 Iterate over nums2 set: Add elements not present in nums1 set to result2 Return both lists Time Complexity: O(n + m) Space Complexity: O(n + m) #LeetCode #DSA #Java #HashSet #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 31/75 — Sum of Two Integers (Without + or -) Today's problem was about performing addition using bit manipulation. Key idea: • XOR (^) gives sum without carry • AND (&) + left shift gives carry Algorithm: while (b != 0): carry = (a & b) << 1 a = a ^ b b = carry Repeat until carry becomes zero. Time Complexity: O(1) Space Complexity: O(1) This problem gave a deeper understanding of how addition works at the binary level. 31/75 🚀 #Day31 #DSA #BitManipulation #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved a simple yet important String + Sliding Window problem. Focused on checking unique characters in fixed-size substrings efficiently. Great practice for improving window-based pattern recognition 🔥 🧠 Problem 🔎 Substrings of Size Three with Distinct Characters Given a string s, return the number of good substrings of length 3. 👉 A substring is good if all characters are distinct. 👉 Count all such substrings (including duplicates if they appear multiple times). Example Input: s = "xyzzaz" Output: 1 Input: s = "aababcabc" Output: 4 Improving DSA with small patterns and clean logic 🚀 #DSA #LeetCode #Strings #SlidingWindow #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Solved a problem where we need to check if two strings can be made equal using a special operation. The rule is: you can swap characters only if the distance between their positions is even. So basically, characters at even indices can only swap among themselves, and same for odd indices. Idea: Instead of actually swapping, I just counted characters separately for even and odd positions in both strings. If both match, then it’s possible — otherwise not. Simple concept, but interesting twist! 😊 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 45 of DSA🚀 🔹 Problem: Remove all occurrences of a given value from an array in-place and return the count of remaining elements. 🔹 Key Idea: Used the two-pointer technique to overwrite unwanted elements and keep valid ones at the beginning of the array. ✔ Time Complexity: O(n) ✔ Space Complexity: O(1) Small problems like this reinforce an important concept: in-place array manipulation without extra memory. #DSA #Java #LeetCode #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Day 56 of #100DaysOfLeetCode 💻✅ Solved #205. Isomorphic Strings problem in Java. Approach: • Used two arrays to track character mappings for both strings • Traversed both strings simultaneously • Checked if the mapping values at current characters are equal • If not equal, returned false (mapping mismatch) • Updated both arrays with the current index + 1 • This ensures consistent one-to-one mapping between characters Performance: ✓ Runtime: 8 ms (Beats 72.19% submissions) ✓ Memory: 44.16 MB (Beats 22.15% submissions) Key Learning: ✓ Learned how to maintain mapping consistency between two strings ✓ Practiced using arrays for character indexing ✓ Strengthened understanding of string pattern matching problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 88 - LeetCode Journey Solved LeetCode 24: Swap Nodes in Pairs in Java ✅ This problem is a great exercise in pointer manipulation in linked lists. Instead of changing values, I swapped the actual nodes by carefully adjusting the next pointers. Using a dummy node made the process much cleaner and helped handle edge cases smoothly. Step by step, I swapped pairs while moving forward in the list. Key takeaways: • Deep understanding of pointer manipulation • Importance of dummy node in linked list problems • Clean handling of edge cases • Iterative approach for swapping nodes ✅ All test cases passed ⚡ Efficient O(n) time and O(1) space Linked list problems like this really sharpen your fundamentals 🔥 #LeetCode #DSA #Java #LinkedList #Pointers #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 89/100 – 𝐈𝐬 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 Today’s problem was 𝐈𝐬 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 — a simple yet fundamental problem to understand two-pointer technique. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: We can efficiently check if one string is a subsequence of another using two pointers. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Traverse both strings Move pointer of s only when characters match Always move pointer of t 𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? We try to match characters of s in order within t without disturbing sequence. ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Initialize two pointers i (for s) and j (for t) If characters match → move both Else → move only j If i reaches end of s → subsequence exists ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(1) #Day89 #100DaysOfCode #Java #DSA #LeetCode #TwoPointers #CodingJourney
To view or add a comment, sign in
-
-
🚀100 Days of Code Day - 17 Problem Solved: Letter Combinations of a Phone Number Today I worked on an interesting backtracking problem where I generated all possible letter combinations from a given digit string (2–9), based on the classic phone keypad mapping. 🔍 Key Learnings: • Understood how recursion helps explore all possible combinations • Strengthened my knowledge of backtracking techniques • Improved problem-solving and logical thinking 💡Approach: Used a recursive backtracking method to build combinations step by step, exploring all possible letter mappings for each digit. 📌 Example: Input: "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] This problem is a great example of how powerful recursion can be when dealing with combinations. #Java #DSA #Backtracking #ProblemSolving #CodingJourney #LeetCode
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