🚀 Day 47 Out of #365DaysOfCode - LeetCode Github link: https://lnkd.in/gGUy_MKZ Today I have worked on a classic problem: converting an integer into its corresponding Excel column title. At first glance, it looks like a simple base-26 conversion. But the interesting twist is that Excel columns are 1-based indexed and do not contain a zero character. That means we need to adjust the number before applying the modulus operation to correctly map values to letters. 💡 Key Learnings: Handling custom base conversions Managing edge cases with non-zero indexing Efficient string building using StringBuilder Strengthening problem-solving fundamentals ⏱️ Time Complexity: O(log₍26₎ n) #Java #DataStructures #Algorithms #ProblemSolving #CodingPractice
Converting Integers to Excel Column Titles with Java
More Relevant Posts
-
🔥 Day 92 of #100DaysOfCode Today’s challenge: LeetCode – Search a 2D Matrix 🧩📊 📌 Problem Summary You are given a matrix where: Each row is sorted in ascending order The first element of each row is greater than the last element of the previous row 👉 This means the entire matrix behaves like a sorted 1D array. Goal: Return true if target exists, otherwise false. 🧠 Approach: Double Binary Search Instead of scanning row by row, we use Binary Search twice. Step 1️⃣: Find the Correct Row Binary search on rows: If target > last element of row → move down If target < first element of row → move up Otherwise → target must be inside this row Step 2️⃣: Binary Search Inside That Row 💡 Why This Works? Because: Rows are sorted Row ranges don’t overlap It behaves like a flattened sorted array. ⏱ Time Complexity: O(log m + log n) 💾 Space Complexity: O(1) 🚀 Performance Runtime: 0 ms Beats 100% submissions Memory: Very efficient 🔥 🧠 Key Learning Whenever: Data looks 2D But ordering behaves like 1D 👉 Think Binary Search Optimization Stack → Sliding Window → Queue → Binary Search → Matrix Search Patterns are connecting now 💪 On to Day 93 🚀 #100DaysOfCode #LeetCode #BinarySearch #Matrix #Java #DSA #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 54 Out of #365DaysOfCode -LeetCode Maximum Product of Word Lengths (Optimized with Bit Manipulation) Github link: https://lnkd.in/gGUy_MKZ Today I worked on an interesting string problem that initially caused a Time Limit Exceeded (TLE) error using a brute-force character comparison approach. 🔎 Problem Statement: Given an array of words, find the maximum value of length(word[i]) × length(word[j]) such that the two words do not share any common letters. 💡 Initial Approach: Compared every pair of words Checked characters one by one using string search Result: ❌ TLE for large inputs ⚡ Optimized Approach (Bit Masking): Represented each word as a 26-bit integer (for letters a–z) Used bitwise AND to check if two words share common letters If (mask[i] & mask[j]) == 0, the words are valid Reduced repeated character comparisons significantly 📈 Key Learnings: Bit manipulation can drastically improve string comparison problems Preprocessing data smartly reduces redundant computation Always look for patterns when constraints are small (like 26 lowercase letters) This problem reinforced how optimization techniques can turn an inefficient O(n² × wordLength) approach into a much faster solution. #Java #DSA #BitManipulation #ProblemSolving #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 17/100 – Sorted Squares (Two Pointer Approach) Today I solved the “Sorted Squares” problem on LeetCode. 🔹 Problem: Given a sorted array (non-decreasing order), return an array of the squares of each number, also sorted. 🔹 Brute Force Idea: 1. Square each element. 2. Sort the array again. Time Complexity: O(n log n) ❌ (Not optimal because sorting takes extra time.) 🔹 Optimal Approach (Two Pointer Technique): Since the array is already sorted, the largest square will come from either: - The leftmost negative number - Or the rightmost positive number So I used: • left pointer at start • right pointer at end • filled the result array from the back At each step: Compare absolute values Place the larger square at the current index Move the corresponding pointer ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) ✨ Key Learning: Instead of blindly sorting again, understanding the pattern of negative numbers helped me optimize the solution. #Day17 #100DaysOfCode #LeetCode #Java #DataStructures #Arrays.
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟏𝟓 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on grouping logic using arrays + hashing concepts 🗂️ and understanding different ways to build unique keys. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • 🔤 Group Anagrams 🔹 𝐆𝐫𝐨𝐮𝐩 𝐀𝐧𝐚𝐠𝐫𝐚𝐦𝐬 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝟏 – 𝐒𝐨𝐫𝐭𝐢𝐧𝐠 𝐁𝐚𝐬𝐞𝐝 • 🔄 Converted each word into a char array • 📊 Sorted the characters • 🔑 Used the sorted string as a key in HashMap • 📦 Grouped words sharing the same sorted key 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝟐 – 𝐅𝐫𝐞𝐪𝐮𝐞𝐧𝐜𝐲 𝐀𝐫𝐫𝐚𝐲 𝐁𝐚𝐬𝐞𝐝 • 🔢 Created a frequency array of size 26 • 🧮 Built a unique key using character counts • ⚡ Used computeIfAbsent for cleaner insertion • 📌 Avoided sorting for better efficiency 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • 🧠 Anagrams share identical character distributions • 🔑 The way you build the key defines performance • ⚡ Frequency-array approach avoids O(k log k) sorting • 📊 Combining arrays with hashing improves efficiency 🧠 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Even in array problems, sometimes the real power lies in how you represent the data 🔑 15 days consistent 🔥 On to Day 16 🚀 #DSA #Arrays #Strings #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Headline: Cracking the "Largest Rectangle in Histogram" (LeetCode 84) 🚀 I just cleared this classic Hard problem with a 0ms runtime! The challenge is finding the largest area in a histogram in O(n) time. The secret sauce? A Monotonic Stack. By storing indices of bars in increasing order, we can identify the "boundary" for each height in a single pass. Key takeaway: Choosing the right data structure (like a Stack) can turn an expensive O(n^2) search into a lightning-fast linear solution. 👨💻 #LeetCode #Java #Algorithms #DataStructures #CodingLife
To view or add a comment, sign in
-
-
🚀 Day 17 of #100DaysOfCode Solved 75. Sort Colors on LeetCode 🎨 🧠 Key insight: Although this problem is often solved using the Dutch National Flag algorithm, it was interesting to apply QuickSort and see how a general-purpose sorting algorithm still performs efficiently for constrained inputs. ⚙️ Approach: 🔹Applied QuickSort recursively 🔹Chose the middle element as the pivot 🔹Partitioned the array around the pivot 🔹Continued sorting left and right partitions ⏱️ Time Complexity: Average: O(n log n) 📦 Space Complexity: O(log n) (recursive stack) #100DaysOfCode #LeetCode #DSA #Sorting #QuickSort #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 42 of #100DaysOfCode Solved 1508. Range Sum of Sorted Subarray Sums on LeetCode 📊 🧠 Problem Insight: Given an array, we must compute the sum of all subarray sums, sort them, and return the sum of elements between indices left and right. ⚙️ Approach Used: 1️⃣ Generate all possible subarray sums using nested loops 2️⃣ Store them in an array of size n*(n+1)/2 3️⃣ Sort the subarray sums 4️⃣ Compute the sum of elements from index left-1 to right-1 5️⃣ Apply mod = 1e9 + 7 to avoid overflow This approach works well because the total number of subarrays is manageable for the given constraints. ⏱️ Time Complexity: O(n² log n) O(n²) to generate subarray sums O(n² log n) to sort them 📦 Space Complexity: O(n²) #100DaysOfCode #LeetCode #DSA #Arrays #Algorithms #Java #CodingPractice #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Solved LeetCode 707 Design Linked List Today I implemented a fully functional singly Linked List from scratch. Unlike typical linked list problems, this one required designing the data structure itself and implementing multiple operations manually. 🔎 Operations implemented: • get(index) • addAtHead(val) • addAtTail(val) • addAtIndex(index, val) • deleteAtIndex(index) Key Concepts Applied: ✔ Custom Node class design. ✔ Pointer manipulation. ✔ Index-based traversal. ✔ Edge case handling (empty list, head operations, invalid index). ✔ Dynamic size management. This problem reinforced an important lesson: Understanding how a data structure works internally is far more powerful than just using built-in libraries. Designing the linked list from scratch improved my confidence in: • Pointer logic • Handling boundary conditions • Writing clean and structured code Building core data structures manually is one of the best ways to strengthen DSA fundamentals. #LeetCode #DataStructures #LinkedList #Algorithms #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟰𝟳/𝟭𝟬𝟬 | 𝗗𝗲𝗹𝗲𝘁𝗲 𝗡𝗼𝗱𝗲𝘀 𝗙𝗿𝗼𝗺 𝗟𝗶𝗻𝗸𝗲𝗱 𝗟𝗶𝘀𝘁 𝗣𝗿𝗲𝘀𝗲𝗻𝘁 𝗶𝗻 𝗔𝗿𝗿𝗮𝘆 Day 47 ✅ — Hash set meets linked list. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟯𝟮𝟭𝟳: Delete Nodes From Linked List Present in Array (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Remove all nodes whose values appear in a given array. Simple concept, but the implementation requires combining two data structures efficiently. The key? Convert array to 𝗛𝗮𝘀𝗵 𝗦𝗲𝘁 for O(1) lookups. Then traverse the linked list with dummy node pattern, checking each node against the set. Eighteen days of linked list practice means the traversal logic is automatic. My focus was purely on optimization—hash set instead of repeated array searching. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Convert nums array to HashSet 👉 Use dummy node for clean edge case handling 👉 Traverse list with prev and curr pointers 👉 If curr.val in set, skip node 👉 Otherwise, move forward Time: O(n + m), Space: O(m) where m = array size 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Eighteen linked list problems. The dummy node pattern has appeared so many times it's muscle memory. When fundamentals are solid, you focus on what actually matters—choosing the right data structure. Hash sets turn O(n×m) solutions into O(n+m). That's the difference between passing and timing out. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gFMUU6bn 𝗗𝗮𝘆 𝟰𝟳/𝟭𝟬𝟬 ✅ | 𝟱𝟯 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #HashSet #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #TimeComplexity #Programming #Optimization
To view or add a comment, sign in
-
Day 16/100 – LeetCode Challenge Problem Solved: Binary Tree Level Order Traversal Today’s problem focused on traversing a binary tree level by level. Instead of visiting nodes in depth-first order, the goal is to group nodes according to their depth in the tree. The idea behind the solution is to track the level of each node while traversing the tree. Starting from the root at level 0, each recursive call increases the level for its child nodes. When visiting a node, we check whether a list for that level already exists. If not, we create one; otherwise, we append the node value to the existing level list. By doing this, the traversal naturally organizes nodes into separate lists representing each level of the tree. Time Complexity: O(n) Space Complexity: O(n) Key takeaway: Tree problems often become easier when you track additional context during traversal. In this case, maintaining the current level allows the recursion to build a structured level-by-level result. Day 16 completed. Continuing the consistency streak and strengthening tree traversal concepts. #100DaysOfLeetCode #Java #BinaryTree #TreeTraversal #Algorithms #ProblemSolving
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