🚀 Day 63 of My LeetCode journey 🚀 Problem : Custom Sort String Today’s problem was interesting because instead of sorting using normal alphabetical order, we sort the given string based on a custom priority order. 🧠 Problem Understanding Given: order → defines priority of characters. str → the input string which needs to be rearranged. Goal: ✅ Arrange characters of str based on the sequence defined in order. ✅ Characters not present in order should appear at the end (any order). 💡 Approach (Simple & Efficient) Count frequency of each character in str. First append characters following the order. Then append remaining characters. Time Complexity: O(n) Space Complexity: O(1) (fixed array size for 26 letters) ✨ Learnings Sometimes the problem isn't about sorting, but about following a custom priority. Frequency counting is extremely powerful for character-based problems. StringBuilder → best way to build strings efficiently in Java. #leetcode #coding #dsa #java #100DaysOfCode #day63 #learningEveryday #problemSolving
Custom Sort String Problem on LeetCode
More Relevant Posts
-
🚀 Day 56 of my #100DaysOfLeetCode Challenge 🚀 Today's problem: Matrix Diagonal Sum Language: Java In this challenge, I practiced calculating the sum of both primary and secondary diagonals of a square matrix. The goal was to improve my understanding of nested loops and conditional logic for index-based problems. Key Takeaways: Strengthened logic for 2D array traversal Improved debugging and edge case handling Reinforced clean, readable code habits Here’s the core idea from my solution: If i == j (primary diagonal) or i + j == n - 1 (secondary diagonal), add that element to the sum. #LeetCode #Java #CodingChallenge #100DaysOfCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
💻 LeetCode Challenge – Day 6: Merge Two Sorted Lists Today’s challenge was all about linked lists — merging two sorted lists into one sorted list 🔗 🔹 Problem: Given two sorted linked lists, merge them into a single sorted linked list and return it. 🔹 Key Learnings: ✅ Deepened understanding of linked list traversal and pointers ✅ Practiced building a dummy node approach for cleaner logic ✅ Learned how to handle edge cases efficiently ✅ Reinforced the importance of iterative vs recursive thinking This problem really helped me think more clearly about data structure manipulation and clean code design. 💪 #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #LinkedList #MergeTwoSortedLists #CodingJourney
To view or add a comment, sign in
-
-
💡 LeetCode 1929 – Concatenation of Array 💡 Today, I solved LeetCode Problem #1929: Concatenation of Array, a simple yet satisfying problem that tests your understanding of array manipulation and indexing in Java. ⚙️📊 🧩 Problem Overview: You’re given an integer array nums. Your task is to create a new array ans such that ans = nums + nums (i.e., concatenate the array with itself). 👉 Example: Input → nums = [1,2,1] Output → [1,2,1,1,2,1] 💡 Approach: 1️⃣ Find the length n of the given array. 2️⃣ Create a new array of size 2 * n. 3️⃣ Loop through nums once — place each element both at index i and index n + i. 4️⃣ Return the resulting array. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Single traversal of the array. ✅ Space Complexity: O(n) — For the concatenated array. ✨ Key Takeaways: Practiced index manipulation and array construction. Reinforced the importance of efficient iteration. A great warm-up problem that strengthens logical thinking and array fundamentals. 🌱 Reflection: Even the simplest problems build the foundation for solving more complex ones. Every bit of consistent practice helps in mastering problem-solving and clean coding habits. 🚀 #LeetCode #1929 #Java #ArrayManipulation #DSA #CodingJourney #CleanCode #ProblemSolving #AlgorithmicThinking #ConsistencyIsKey
To view or add a comment, sign in
-
-
🌟 Problem 21 – Merge Two Sorted Lists I solved this problem today on LeetCode 💪. It helped me understand how to work with linked lists and how to merge them efficiently. 🧩 Description: Given two sorted linked lists, merge them into one sorted list and return its head. 👉 Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] ✅ Approach: * Compare nodes from both lists one by one. * Add the smaller value to the new list. * Continue until all elements are merged. 📈 Time Complexity: O(n + m) 📦 Space Complexity: O(1) #LeetCode #TopInterview150 #Java #DSA #Coding #ProblemSolving #LinkedList
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 74 Count and Say Problem: Given an integer n, return the n-th term of the “Count and Say” sequence a fascinating pattern where each term describes the previous one. Example: Input: n = 4 Output: "1211" My Approach: Used recursion to generate the previous term. Applied run-length encoding logic counted consecutive digits and built the next term using a StringBuilder. Optimized for clean, readable iteration with O(N²) complexity (due to string building). Understanding recursive string construction deepens how we visualize “generation-based” sequences it’s not just about coding, it’s about seeing patterns grow. #100DaysOfCode #Java #LeetCode #ProblemSolving #Recursion #StringManipulation #CodingJourney #TechWithPurpose #takeUforward
To view or add a comment, sign in
-
-
💡 LeetCode #58 — Length of Last Word Today I solved LeetCode Problem 58: Length of Last Word 🧠 Problem Summary: Given a string s consisting of words and spaces, return the length of the last word in the string. A word is defined as a sequence of non-space characters. Key Idea: We can traverse the string from end to start — Skip trailing spaces. Count the number of characters until the next space (which marks the last word). This avoids unnecessary splitting and saves extra space. #LeetCode #Java #DSA #Strings #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
💻 LeetCode 50 Days Challenge — Day 7: Merge Sorted Array Day 7 of my #LeetCode50DaysChallenge ✅ Today’s problem was about merging two sorted arrays efficiently — Merge Sorted Array ✨ 🧩 Problem: You are given two sorted integer arrays nums1 and nums2, along with integers m and n, representing the number of valid elements in each array. The task is to merge nums2 into nums1 so that the result is a single array sorted in non-decreasing order, all done in-place without returning a new array. 💡 Approach: I started by appending all elements from nums2 to nums1 from the index m onward. Then, I simply used Java’s built-in Arrays.sort() to sort the combined array. Although this isn’t the most optimal in-place merge, it’s clean, concise, and leverages Java’s efficient sorting algorithm — perfect for understanding the fundamentals of merging. ⏱️ Time Complexity: O((m + n) log(m + n)) 📊 Example: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Every problem solved adds up — like merging arrays, small consistent steps combine into something powerful. Keep going! 💪 #LeetCode #CodingChallenge #Day7 #ProblemSolving #Java #SoftwareDevelopment #Consistency #50DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 62/100 of #100DaysOfLeetCode Today’s challenge was “Happy Number” (LeetCode Problem 202). The task was to determine whether a given number is a Happy Number — meaning that by repeatedly replacing the number with the sum of the squares of its digits, the process eventually reaches 1. 💡 Key Takeaways: Strengthened understanding of pointer movement logic. Improved implementation skills using mathematical and logical thinking in Java. #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms
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