🔍 Day 30 | Shift Happens (and That’s Beautiful) Today’s LeetCode challenge was #848 – Shifting Letters 🌀 At first glance, it looks like a simple “shift characters” task — but under the hood, it’s a neat example of prefix-sum logic meets modular arithmetic. 💡 The Problem: For each index i, shift the first i+1 letters by shifts[i] times — wrapping around from 'z' to 'a'. 🧠 The Trick: If we start from the end of the string and move backward, we can keep a cumulative shift sum that already accounts for all later shifts. This avoids repeatedly looping over the prefix and keeps our time complexity O(n) instead of O(n²). ⚙️ Approach: Traverse from right to left Keep adding each shift to a running total (totalShift) Apply totalShift % 26 to shift the current character efficiently Update the string using a StringBuilder 💨 Why It’s Optimal: ✅ Single pass — linear time ✅ Constant extra space ✅ Clean and scalable even for large inputs (up to 10⁵ length! Sometimes the cleanest solutions come from flipping your perspective — literally shifting your direction Shishir chaurasiya and PrepInsta #LeetCode #CodingChallenge #Java #Algorithms #ProblemSolving #LearningEveryday
"Shifting Letters Challenge: A Prefix-Sum Logic Trick"
More Relevant Posts
-
🧠 Day 37 / 100 – Implement Queue using Stacks (LeetCode #232) Today’s challenge was about building a Queue using two Stacks, and it really made me appreciate the power of thinking creatively with basic data structures. A queue works in FIFO (First In, First Out) order, while a stack follows LIFO (Last In, First Out) — but by using two stacks, I could recreate queue behavior perfectly. This problem taught me how sometimes you don’t need a new data structure — just a new perspective. By transferring elements only when necessary, I learned how to make operations both efficient and intuitive. 🔍 Key Learnings Two stacks can together simulate queue behavior efficiently. Use one stack for incoming elements and the other for outgoing ones. Always transfer only when needed to maintain time efficiency. 💭 Thought of the Day Creativity in coding often comes from repurposing what you already know. This challenge reminded me that mastering fundamentals allows you to solve complex problems with simple logic. 🔗 Problem Link:https://lnkd.in/g7my77rr #100DaysOfCode #Day37 #LeetCode #Python #Queue #Stack #DataStructures #ProblemSolving #AlgorithmPractice #CodingJourney #LearnByDoing #TechGrowth #CleanCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Day 8 of #45DaysOfLeetCode Challenge 😎 📌Today's problem: Palindrome Number (LeetCode #9) 💡 🔹 Concept: Check whether a given integer reads the same backward and forward — without converting it to a string! 🔹 Logic Used: Instead of reversing the entire number, I reversed only half of it to improve efficiency. This avoids unnecessary computation and eliminates integer overflow risks. 🔹 Key Learnings: ✅ Optimized logic using mathematical manipulation ✅ Improved understanding of number reversal techniques ✅ Importance of edge case handling (negative numbers, trailing zeros) ⚙️ Result: 💻 Runtime: 4 ms (Beats 100%) 💾 Memory: 44.84 MB 😎Small optimizations make a big difference in performance! 💪 📌Problem: https://lnkd.in/ef6AC2j6 🔥Each day is a step closer to writing cleaner and more optimized code. ✨ Let’s keep pushing forward and refining our problem-solving skills! 💻🔥 #LeetCode #Day8 #100DaysOfCode #ProblemSolving #Java #CodingChallenge #PalindromeNumber #DataStructures #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 87/100 of #100DaysOfCode 💡 Problem: 3321. Find X-Sum of All K-Long Subarrays II (Hard) 🔗 Platform: LeetCode Today’s challenge was all about optimizing sliding window logic with frequency-based ordering! The task — find the “x-sum” of every k-sized subarray, keeping only the top x most frequent elements (and if tied, prefer larger values). 🧠 Key Learnings: How to maintain frequency counts efficiently in a sliding window. Managing top-x elements dynamically using TreeSet and custom comparators. Overcoming TLE issues by switching from naive sorting (O(n*k)) to a balanced TreeSet approach (O(n log n)). ⚙️ Concepts Used: → Sliding Window → Frequency Map (HashMap) → Ordered Sets (TreeSet) → Custom Comparator Logic 🔥 This one really tested both logic & optimization — but once it clicked, it felt amazing! #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #DSA #SlidingWindow #Optimization
To view or add a comment, sign in
-
-
💻 Day 62 of #LeetCode100DaysChallenge Solved LeetCode 142: Linked List Cycle II — a problem that deepens understanding of linked list traversal and cycle detection using pointers. 🧩 Problem: Given the head of a linked list, return the node where the cycle begins. If there’s no cycle, return null. A cycle exists if a node can be revisited by continuously following the next pointer. The goal is to identify the exact node where the cycle starts — without modifying the list. 💡 Approach — Floyd’s Cycle Detection (Tortoise and Hare): 1️⃣ Use two pointers — slow and fast. 2️⃣ Move slow by 1 step and fast by 2 steps until they meet (if a cycle exists). 3️⃣ Once they meet, reset one pointer to the head. 4️⃣ Move both one step at a time; the node where they meet again is the start of the cycle. 5️⃣ If no meeting point (i.e., fast or fast.next becomes null), return null. ⚙️ Complexity: Time: O(N) — each pointer traverses the list at most twice. Space: O(1) — no extra memory used. ✨ Key Takeaways: ✅ Strengthened Floyd’s algorithm understanding for detecting and locating cycles. ✅ Learned how mathematical reasoning helps pinpoint the start node of a loop. ✅ Reinforced efficient use of pointer manipulation in linked list problems. #LeetCode #100DaysOfCode #Java #LinkedList #CycleDetection #FloydsAlgorithm #DSA #CodingJourney #WomenInTech #ProblemSolving
To view or add a comment, sign in
-
-
🌳 Day 60 of 100: Maximum Depth of Binary Tree 🌳 Today’s challenge was LeetCode 104 – Maximum Depth of Binary Tree 🌲 The task? Given the root of a binary tree, find the maximum depth — the number of nodes along the longest path from the root to a leaf node 🍃 💡 Intuition: A binary tree’s depth can be thought of as its “height”. To find it, we just need to know the depth of the left and right subtrees — and the answer is the greater of the two, plus one for the current node. This is a classic example of recursion done right — breaking a big problem into smaller ones that mirror the original. ⏱ Time Complexity: O(n) – visit every node once 🗂 Space Complexity: O(h) – h is the height of the tree (recursion stack) ✨ Key Takeaway: This problem beautifully highlights the power of divide and conquer — by solving smaller subproblems (left and right trees), we can elegantly solve the bigger one. #100DaysOfCode #Day60 #LeetCode #Java #CodingJourney #BinaryTree #Recursion #DataStructures #CodingPractice #ProblemSolving #WomenWhoCode #CodeNewbie #LearnToCode
To view or add a comment, sign in
-
-
💡 Day 19 of My LeetCode Journey — 3Sum Closest Today’s problem was “3Sum Closest”, a slight twist on the classic 3Sum challenge. 🧩 Problem Statement: Given an integer array nums and a target value, find three integers whose sum is closest to the target. Return the sum of those three numbers. Example: Input: nums = [-1, 2, 1, -4], target = 1 Output: 2 Explanation: (-1 + 2 + 1 = 2) ⚙️ Approach: Sort the array for easy pointer movement. Use a for loop to fix one element at a time. Apply the two-pointer technique to find the closest sum. Compare differences using Math.abs() to track which combination is nearer to the target. 📘 Key Learning: 🔹 Sorting simplifies pointer logic. 🔹 Math.abs() is crucial for measuring closeness. 🔹 Sometimes, you don’t need the exact answer — just the closest one. #30DaysOfCode #LeetCode #Java #CodingJourney #ProblemSolving #DataStructures #Algorithms #TwoPointers #TechLearning
To view or add a comment, sign in
-
-
🔥 Day 33/100 of #100DaysOfCode - Alternating Positive & Negative! Today's Problem: Rearrange Array Elements by Sign Task: Given an array with equal number of positive and negative integers, rearrange them in alternating positive/negative order (starting with positive). Solution: Used a two-pointer approach with separate indices for positive and negative positions! Created a temp array and placed positives at even indices (0, 2, 4...) and negatives at odd indices (1, 3, 5...). Key Insights: Since the array has equal positives and negatives, we can pre-determine positions O(n) time complexity with O(n) space for the temp array Clean and intuitive - no complex swapping needed Smart Pointer Management: Positive pointer moves by +2 each time Negative pointer moves by +2 each time Single pass through the original array Elegant solution for maintaining relative order while achieving the required alternation! ⚡ #100DaysOfCode #LeetCode #Java #Algorithms #Arrays #TwoPointers #CodingInterview
To view or add a comment, sign in
-
-
Problem: "73. Set Matrix Zeroes" The core of this problem is simple: if a cell is zero, its entire row and column must become zero. But the execution is tricky—you can't modify the matrix while you're still scanning for original zeros! My solution uses a clean, two-pass strategy with auxiliary storage: Pass 1: Use two HashSets to record the indices of rows and columns that contain an initial zero. Pass 2: Iterate again and set any cell to zero if its row or column is present in the HashSets. This approach is highly readable and ensures optimal O(M . N) time complexity. While this solution uses O(M+N) extra space, it's a fantastic baseline. The next step is tackling the O(1) space constraint by cleverly using the matrix's first row and column as the marker sets. That's the real optimization puzzle! #Algorithms #DataStructures #LeetCode #CodingChallenge #Java #SoftwareEngineering #100daysofcode
To view or add a comment, sign in
-
-
Day 55 of My DSA Challenge Problem: Count the number of triplets in an array that can form a valid triangle. Concept Recap: For any three sides to form a triangle, the sum of any two sides must be greater than the third side. Optimized Approach: Instead of checking every triplet (which takes O(N³)), I sorted the array and used a two-pointer technique to bring it down to O(N²): Sort the array. Fix the largest side (arr[k]) and use two pointers (i, j) to find pairs where arr[i] + arr[j] > arr[k]. If the condition holds, all elements between i and j can form valid triangles. Count and move pointers accordingly. Time Complexity: O(N²) Space Complexity: O(1) Takeaway: Sorting combined with the two-pointer approach often transforms brute-force solutions into elegant and efficient ones. #Day55 #DSAChallenge #TwoPointerTechnique #Sorting #Optimization #Java #ProblemSolving #DataStructures #Algorithms #CodingChallenge #GeeksforGeeks #LeetCode #100DaysOfCode #ProgrammersJourney #TechLearning
To view or add a comment, sign in
-
-
In the original post, they mention one of my favorite topics: managing complexity in software development. Should we tackle it by pretending things are simple, or should we assume it will be complex and we need to manage it? We strive to simplify things and improve productivity in software development, but somehow the simple solutions tend to grow. We end up adding layer upon layer of details until we reach a point where we may have this strange feeling: What if we had just used, for example, a programming language that doesn’t pretend, doesn’t limit us, but allows us to specify all the details directly without the illusion of being able to abstract away low-level details with high-level abstractions? The "corner cases" and the subtle trade-offs on every detail still come back to haunt us as we develop real-world software. The real challenge, which requires experience, is knowing when to build and use high-level abstractions, and when to keep things simple and leave opportunities wide open, allowing us to focus on low-level details when it truly matters. Ironically, sometimes that approach is simpler, and there’s no need to manage complexity with anything more powerful than the original tool for making abstractions: function calls.
Software Architect | Tech Lead | Full Stack (Python, React, Kubernetes) | 20+ years building scalable systems
🚧 [The Great Abstraction Tragedy #1] Stacked Abstractions _once we coded, now we configure_ --- **1992:** You wrote C. You compiled. It ran. You felt unstoppable. Your tools? A terminal, a manual, and a terrifying sense of responsibility. **2025:** You write YAML that describes JSON that configures Docker that runs Node that calls Python that imports a C library written in 1992. It doesn’t work. You open GitHub. Last commit: "Temporary fix" (from 2018). Back then, a *stack* meant stack memory. Now it means 17 logos in a slide deck. We used to count bytes. Now we count dependencies. And lose both battles. We say we're standing on the shoulders of giants, but really we're balancing on a pile of abstractions, frameworks, and an alarming amount of duct tape. And somewhere at the bottom, a 30-year-old C function still runs silently, perfectly, and completely undocumented. We didn’t simplify computing. We just moved the complexity further away from the keyboard. But hey, at least it deploys in a container. And has dark mode. --- #GreatAbstractionTragedy #SoftwareEngineering #ProgrammingHumor #TechCulture #LegacyCode #DevLife
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
Make an Excel sheet, track your progress daily, and remember one word — consistency is the key to success Sushmitha S