🚀 Day 42 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a deep dive into string-based arithmetic — no shortcuts allowed! 🧩 multiply(num1: str, num2: str) -> str — Multiply two non-negative integers represented as strings, without using int() or BigInteger. 📌 Challenge: → No built-in conversion from string to integer → No BigInteger libraries → Just pure digit-by-digit simulation, like manual multiplication → Example: num1 = "123", num2 = "456" ✅ Output: "56088" 🔍 Approach: → Reversed both strings to simplify digit placement → Used ASCII math: ord(char) - ord('0') to extract digits → Stored intermediate products in an array of size len(num1) + len(num2) → Managed carry manually and built the final string from the result array 💡 What made it click: → Realized that each digit product lands at position i + j in the result array → Practiced dry runs to visualize how "123" * "456" becomes "56088" → Saw how carry propagation works across the array → Appreciated how reversing strings simplifies index math 📚 What I learned: ✅ How to simulate arithmetic without integer conversion ✅ How to use ASCII tricks to decode digits ✅ How to manage carry and build results step-by-step ✅ The power of dry runs to debug and understand logic Have you ever built a calculator or tackled string-based math problems? Let’s swap strategies and visual walkthroughs 💬 #Day42 #Leetcode #Python #StringManipulation #ASCIITricks #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
"Day 42 of #100DaysOfCode: String Arithmetic Challenge"
More Relevant Posts
-
🧩 Day 38 / 100 – Transpose Matrix (LeetCode #867) Today’s problem focused on understanding matrix manipulation — specifically, the Transpose of a matrix. Transposing means flipping a matrix over its diagonal, turning rows into columns and columns into rows. It’s a simple concept but helps strengthen 2D array traversal logic — especially how to navigate nested loops cleanly and avoid index confusion. This was a good reminder that clarity and structure matter just as much as complexity. 🔍 Key Learnings Transposing a matrix means swapping element positions — matrix[i][j] → result[j][i]. Use nested loops efficiently to fill the new matrix with swapped indices. Always keep track of dimensions — rows become columns and vice versa. 💭 Thought of the Day Even small transformations like a transpose can teach big lessons in clean logic. Sometimes we overthink “hard” problems, but mastering basics like matrix traversal builds the foundation for solving advanced ones like rotation or dynamic programming grids. 🔗 Problem Link:https://lnkd.in/gHKB9h4b #100DaysOfCode #Day38 #LeetCode #Python #Matrix #Transpose #ProblemSolving #Algorithms #DataStructures #CodingChallenge #CodeEveryday #LearningJourney #CleanCode #TechGrowth #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Product of Array Except Self — LeetCode #238 Today, I solved one of the most elegant problems in array manipulation — “Product of Array Except Self.” 🧩 Problem in short: Given an integer array nums, return an array answer such that answer[i] equals the product of all numbers in nums except nums[i], ✅ Without using division ✅ In O(n) time ✅ With O(1) extra space 💡 Key Insight — Prefix & Suffix Products Instead of recalculating every product, the trick is to use two passes: First pass: Store the product of all elements before each index (prefix). Second pass: Multiply each element by the product of all elements after it (suffix). This way, each position in the output represents the product of all other elements — efficiently and elegantly. ⚙️ Complexity Time: O(n) Space: O(1) (excluding the result array) 📊 Result ✅ Accepted — Runtime: 20 ms ⚡ Beats 74.21% in performance and 55.22% in memory usage Every problem like this reinforces one key principle: In interviews (and real-world problems), pattern recognition always beats rote memorization. This one beautifully highlights the Prefix–Suffix Pattern, seen in problems like Trapping Rain Water and Subarray Product. #LeetCode #DSA #CodingInterview #Python #Arrays #PrefixSuffix #ProblemSolving
To view or add a comment, sign in
-
-
🧠 Day 28 DSA Challenge – Problem 745: Prefix and Suffix Search This problem was a deep dive into efficient string mapping and prefix-suffix optimization 🔍 🎯 Problem Statement: Design a special dictionary that allows searching words by both a prefix and a suffix. Implement the WordFilter class such that f(pref, suff) returns the largest index of the word matching both conditions — or -1 if none exist. 🧩 How I Solved It: Built a hash map (dictionary) to store all possible prefix-suffix combinations as keys. For each word, I combined every prefix and suffix pair using a unique separator (#) to avoid overlap. Stored the latest index for each combination, ensuring that the lookup returns the largest valid index efficiently. The f() method simply checks for the combined key in the map — making searches O(1) after preprocessing. ⚙️ Performance Stats: ⏱ Runtime: 1152ms (beats 50%) 💾 Memory: 91.98MB (beats 81.25%) ✅ Testcases Passed: 17 / 17 ✨ Insight: This challenge emphasized the power of hash-based precomputation — trading space for blazing-fast lookup performance ⚡ #LeetCode #Problem745 #PrefixSuffixSearch #DSA #HashMap #StringManipulation #CodingChallenge #Python #100DaysOfCode #KeepBuilding
To view or add a comment, sign in
-
-
👇 🚀 LeetCode Problem: String to Integer (atoi) 📘 Problem #8 | Medium Level 🧠 Concept: This problem is all about manually converting a string into an integer, similar to how the C/C++ atoi() function works — but with extra rules for spaces, signs, and number limits. 💡 Key Steps to Solve: Trim spaces – Ignore any leading whitespace. Check the sign – Identify if the number is positive or negative (+ / -). Extract digits – Read characters until a non-digit appears. Handle overflow – Clamp results within 32-bit signed integer range: Minimum: -2³¹ = -2147483648 Maximum: 2³¹ - 1 = 2147483647 Return the result – Considering the sign and bounds. 🧩 Example: Input: " -42" Output: -42 Input: "4193 with words" Output: 4193 Input: "-91283472332" Output: -2147483648 🔥 Takeaway: This challenge strengthens your understanding of: String parsing Edge case handling Integer overflow prevention #LeetCode #Coding #Python #ProblemSolving #Atoi #StringToInteger #DataStructures #Algorithms #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA Progress – Day 102 ✅ Problem #1657: Determine if Two Strings Are Close 🧠 Difficulty: Medium | Topics: String, Hash Table, Sorting, Frequency Counting 🔍 Approach: Implemented a frequency-based comparison approach to determine whether two strings can be transformed into each other using specific operations. Step 1 (Length Check): If the strings have different lengths → they can never be close. Step 2 (Frequency Counting): Created two frequency arrays of size 26 (for each lowercase English letter) and counted occurrences of each character in both strings. Step 3 (Character Set Validation): Checked that both strings use the same set of unique characters. If a character exists in one but not the other → return False. Step 4 (Frequency Pattern Check): Sorted both frequency arrays and compared them. If both have the same frequency distribution, they can be transformed into each other → return True. This ensures we only check for the pattern and presence of characters, not their positions. 🕒 Time Complexity: O(n + 26 log 26) ≈ O(n) 💾 Space Complexity: O(1) (fixed-size frequency arrays) 📁 File: https://lnkd.in/gyMwmsei 📚 Repo: https://lnkd.in/g8Cn-EwH 💡 Learned: This problem was a great exercise in identifying core equivalence patterns between strings. It taught me to look beyond direct character order and instead focus on frequency structures and sets — two powerful tools in string transformation logic. Breaking the problem into steps like length check → character set → frequency pattern made the solution clean, efficient, and interview-friendly. ✅ Day 102 complete — decoded the secret symmetry between two “close” strings! 🔤🔁✨ #LeetCode #DSA #Python #Strings #HashTable #Sorting #FrequencyAnalysis #DailyCoding #InterviewPrep #GitHubJourney
To view or add a comment, sign in
-
Day 35 / 100 – Subarray Sum Equals K (LeetCode #560) Today’s challenge was about finding the number of continuous subarrays whose sum equals a given value k. At first, the brute-force approach felt tempting — checking every possible subarray — but that would be too slow. Instead, I learned to use a Hash Map to store cumulative sums and find the solution in linear time. This problem truly deepened my understanding of prefix sums and how storing previous computations can make complex problems simple and elegant. 🔍 Key Learnings Prefix Sum helps keep track of cumulative totals efficiently. Hash Maps allow quick lookups, reducing time complexity from O(n²) to O(n). Sometimes, the key to optimization is remembering what you’ve already calculated. 💭 Thought of the Day Today reminded me that not every problem needs to be solved from scratch — sometimes, the best solutions come from building on what you already know. Logic and memory, when used together, create magic in code ✨ 🔗 Problem Link: https://lnkd.in/gVGGGm6J #100DaysOfCode #Day35 #LeetCode #Python #HashMap #ProblemSolving #DataStructures #Algorithms #CodingChallenge #CodeEveryday #LearningJourney #Optimization #CleanCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 96 Problem: String to Integer (atoi) 🔢➡️💻 This is a classic implementation problem that tests careful handling of edge cases, parsing logic, and boundary conditions. 🧠 Problem Summary: Implement the function myAtoi(string s) that converts a string into a 32-bit signed integer following specific parsing rules. Steps to follow: 1️⃣ Ignore leading whitespaces. 2️⃣ Check the sign (+ or -). 3️⃣ Read digits until a non-digit character is found. 4️⃣ Handle overflow/underflow by clamping the number within the 32-bit signed integer range: Range = [−2³¹, 2³¹ − 1] 5️⃣ Return the final integer. ⚙️ My Approach: Trim leading spaces using lstrip(). Identify the sign based on the first non-space character. Iterate through the string and build the number digit by digit. Multiply by the sign and ensure the result stays within integer limits using max() and min(). 📈 Complexity Analysis: Time: O(n) — traverse each character once. Space: O(1) — only a few variables used. ✨ Key Takeaway: This problem is a great example of careful boundary handling and parsing logic — it’s not just about coding, but about thinking through every possible input case. 🔖 #DSA #100DaysOfCode #LeetCode #ProblemSolving #Python #CodingChallenge #myAtoi #StringParsing #AlgorithmDesign #InterviewPrep #TechCommunity #LearningEveryday
To view or add a comment, sign in
-
-
💡 Day 36 of 100 — Count Operations to Obtain Zero (#LeetCode 2169) Today’s problem was a simple yet oddly satisfying one it felt like a math puzzle disguised as a loop. It reminded me how sometimes, even the easiest problems can hold a small “aha!” moment when you spot the pattern. 🧠 What I figured out The problem is basically a modified version of the Euclidean algorithm for finding the GCD. Instead of just returning the GCD, you count how many subtraction (or division) steps it takes until one number becomes zero. Using division instead of repeated subtraction makes the solution much more efficient. 💻 My thought process I first thought of literally subtracting the smaller number from the larger one repeatedly but that was painfully slow. Then I realized I could just count how many times it fits using integer division, and the logic becomes clean and fast. 📊 Complexity: Time — O(log(min(num1, num2))) Space — O(1) 💬 Reflection This problem reminded me that optimization isn’t always about big algorithms sometimes it’s just about seeing the pattern. It’s funny how often elegant solutions hide behind simple loops. #100DaysOfLeetCode #Day36 #LeetCodeJourney #ProblemSolving #Python #DSA
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about frequency mapping and subarray logic — solving the Picking Numbers problem from HackerRank. 🔗 Problem: pickingNumbers(a) (HackerRank) 📌 Challenge: Given an array of integers, find the length of the longest subarray where the absolute difference between any two elements is ≤ 1. 🔍 Approach: → Used Python’s Counter to map frequencies of each number → For each number num, calculated freq[num] + freq[num + 1] → Tracked the maximum such sum to find the longest valid subarray → Avoided brute-force by leveraging frequency patterns instead of scanning all subarrays 💡 What made it click: → Realized that valid subarrays must contain only num and num + 1 → Frequency mapping reveals hidden structure in the data → Clean logic with max() and get() made the solution elegant and readable 📚 What I learned: ✅ Frequency-based thinking can simplify subarray problems ✅ Counter is a powerful tool for pattern detection ✅ Avoiding brute-force leads to scalable, efficient solutions ✅ Sharing dry runs and visual walkthroughs helps others grasp the intuition faster Have you tackled Picking Numbers before? Did you go with sorting, brute-force, or frequency mapping like I did? Let’s swap strategies 💬 #Day31 #HackerRank #SubarrayLogic #FrequencyMapping #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 85 Problem: Check if All Integers in a Range Are Covered ✅📏 This problem was an elegant use of the Prefix Sum technique, where I used range updates to efficiently check coverage over an interval. 🧠 Problem Summary: You are given several inclusive integer intervals and a target range [left, right]. You must verify if every integer within [left, right] is covered by at least one of the given intervals. ⚙️ My Approach: 1️⃣ Initialize an array line to track coverage at each integer position. 2️⃣ For every range [a, b], increment line[a] and decrement line[b + 1] — this marks the start and end of coverage. 3️⃣ Convert line into a prefix sum array, so each position reflects how many intervals cover that number. 4️⃣ Finally, iterate through [left, right] to ensure each integer has coverage (> 0). 📈 Complexity: Time: O(n + 52) → Linear scan and prefix sum computation. Space: O(52) → Fixed-size array since ranges are small. ✨ Key Takeaway: Prefix sum is not just for subarray sums — it’s a powerful trick for range marking and coverage problems, offering O(1) updates and O(n) verification. ⚡ 🔖 #DSA #100DaysOfCode #LeetCode #PrefixSum #RangeUpdate #ProblemSolving #Algorithms #CodingChallenge #Python #EfficientCode #Optimization #TechCommunity #InterviewPrep #CodeEveryday #LearningByBuilding
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