Today, I solved an interesting LeetCode problem called “Max Sum of a Pair With Equal Sum of Digits(https://lnkd.in/gfE37qjM)". It looks simple — until you realize it’s actually two problems cleverly disguised as one. Let’s break it down: Problem 1 — Compute the Digit Sum For each number, we first need its digit sum — a classic number manipulation subproblem. 51 → 5 + 1 = 6 42 → 4 + 2 = 6 This step groups numbers by a common mathematical property — their digit sum. Problem 2 — Find the Maximum Pair Sum in Each Group Once we group numbers by their digit sum, the next challenge is to find two numbers with the same sum of digits that produce the largest total. This now becomes a hash map optimization problem: Use a map to store the largest number seen for each digit sum. For every new number, check if we already have one with the same digit sum. If yes → compute the potential pair sum → update the maximum. Approach Summary Digit Sum Calculation: O(logn) per number Hash Map Lookup: O(1) per operation Overall Time: O(n), efficient and clean Here is the solution Below #LeetCode #JavaScript #Coding
Solved LeetCode problem "Max Sum of a Pair With Equal Sum of Digits"
More Relevant Posts
-
DSA Practice — Day 10 Solved the “Merge Sorted Array” problem on LeetCode 🧩 At first glance, it looked simple — just merge and sort. But when I started optimizing, it turned into an interesting challenge. 🧠 My Approaches: 1️⃣ Brute Force: Directly add all elements into one array and sort. (Simple, but inefficient ) 2️⃣ Two Pointer + Extra Space: Created a copy of nums1 and merged both arrays efficiently. ➤ Time Complexity: O(m + n) ➤ Space Complexity: O(n) 3️⃣ Optimized In-Place Approach: Used two pointers starting from the end of both arrays — merging in reverse order without extra space. ➤ Time Complexity: O(m + n) ➤ Space Complexity: O(1) 💡 Lesson: The best solution often hides behind simple logic — you just have to look from the right direction. #DSA #LeetCode #ProblemSolving #JavaScript #LearningInPublic #CodingJourney #BackendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
-
DSA Practice — Day 13 Solved the “Missing Number” problem on LeetCode 🔢 🧠 Problem: You’re given an array of n distinct numbers from the range [0…n], and exactly one number is missing. The task: return the missing number. This problem felt very straightforward, but I still didn’t jump into the final code immediately. I first tried a brute-force mindset, explored edge cases, and then moved to a clean mathematical approach without using any built-in JS shortcuts. Approach: • Sum all numbers from 0 to n • Subtract the sum of the array • The difference = missing number → Time Complexity: O(n) → Space Complexity: O(1) “Simple problems become powerful when solved with the right fundamentals.” #DSA #LeetCode #ProblemSolving #JavaScript #LearningInPublic #CodingJourney #BackendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
-
💡 Brute Force vs. Mathematical Logic — Which One Wins? ⚔️ Tried a small coding challenge today: 👉 Find two numbers in an array whose sum equals a target (classic 2-sum problem 😎). code: https://lnkd.in/gtRVzcZY 🧠 Observation: Both give the same result — but the mathematical approach is cleaner, faster, and more efficient 💪 Sometimes, it’s not just about solving the problem… It’s about solving it smartly. 🚀 #JavaScript #CodingFun #LogicBuilding #ProblemSolving #WebDevelopment #LearnToCode #Efficiency #DeveloperLife
To view or add a comment, sign in
-
-
Start free on CSX and practice as you read: https://lnkd.in/eFtB-g27 In JavaScript, data types tell your code how to treat a value. Primitives are single values like text, numbers, and true/false. Composites group values together as labeled objects or ordered lists. Knowing the difference helps your conditions, loops, and functions behave predictably. Practice the data types lesson on CSX. Get instant feedback and beginner-friendly exercises. Follow for more tips.💻 ✨ #javascript #coding #webdevelopment #csx #datatypes #objects #arrays
To view or add a comment, sign in
-
Day 23/90 – 90 Days DSA Challenge Today I practiced another classic recursion problem — Sum of first N natural numbers using recursion 💡 🧠 Concept Recap: Recursion is when a function calls itself with a smaller input until it reaches a base condition. It’s like peeling an onion layer by layer — until you reach the core 🧅 ⚙️ Problem Statement: 👉 Write a function sum(n) that calculates the sum of the first n natural numbers. 🧩 Example: Input: 5 Process: 5 + 4 + 3 + 2 + 1 = 15 Output: 15 Time Complexity: O(n) 💾 Space Complexity: O(n) (due to call stack) ✨ Key takeaway: Recursion helps break down complex problems into smaller, simpler ones — it’s elegant, powerful, and mind-opening once you get the hang of it! #Day23 #DSA #Recursion #JavaScript #CodingChallenge #MechCode #LearningInPublic #FrontendDeveloper #CodeEveryday
To view or add a comment, sign in
-
-
🚀Day 30 of Cohort2.0 Today's class was about Javascript Data Types + Type System with The OG Harsh Vandana Sharma at Sheryians Coding School I've learned: 1️⃣. Primitive datatypes (string, boolean, number, null, undefined, symbol, bigint). 2️⃣. Reference datatypes (arrays, objects, functions). 3️⃣. Dynamic Typing and some quirks in JS. 4️⃣. Type coercion (== vs ===). 5️⃣. Truthy and falsy values. #responsiveness #responsivedesig #css #scss #html #Cohort2 #webdevelopment #Javascript
To view or add a comment, sign in
-
🧠 Day 20 of #100DaysOfDSA Today I practiced two classic problems from LeetCode — FizzBuzz and Reverse String. 📘 What I learned: These might look like simple problems, but they help sharpen logic building, loops, and condition handling — essential building blocks for bigger challenges. 💻 Problems Solved: 1️⃣ FizzBuzz – A fun way to practice modular arithmetic and condition prioritization. 2️⃣ Reverse String – Implemented using the two-pointer approach for an in-place reversal. 💡 Key Takeaways: FizzBuzz reinforces thinking through branching logic. The two-pointer method is efficient for array and string manipulation. Small problems like these build the foundation for complex algorithms. 🔗 Check out my implementations here: https://lnkd.in/gxs9yaen #100DaysOfCode #DSA #LeetCode #JavaScript #CodingJourney #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
🔍 Day 171 of #200DaysOfCode Today, I implemented a function to check whether a specific value exists in an array — without using built-in methods like .includes(). This challenge helped strengthen my understanding of: • Array traversal using loops • Conditional comparisons • Manual search logic • Returning Boolean results effectively 🌍 Though simple, this concept plays a big role in real-world applications like: ✅ Searching records in a dataset ✅ Validating user inputs ✅ Checking access permissions ✅ Matching values in dynamic arrays 💡 Every “basic” problem hides a core principle that drives advanced algorithms. Mastering small steps leads to giant leaps in logic building! #JavaScript #171DaysOfCode #ProblemSolving #LearnInPublic #BackToBasics #WebDevelopment #CodingChallenge #DeveloperMindset #LogicBuilding
To view or add a comment, sign in
-
-
🚀Day 85 of #100DaysOfCode 👉 Today I explored the JavaScript Math object. It’s a built-in tool packed with methods for quick math calculations—no setup needed. examples: ▪️Math.ceil(4.6) --> rounds to 5 ▪️Math.floor(4.9) --> rounds down to 4 ▪️Math.pow(2, 3) --> returns 8 ▪️Math.abs(-5) --> returns 5 (gives positive number) Math object makes coding calculations simple and fast. #JavaScript #MathObject #LearnToCode #100DaysOfCode
To view or add a comment, sign in
-
-
⚡ Day 34 | Mastering Operators & Conditionals in JavaScript Today’s session (Lec-41) was packed with logic and power! 🔥 I explored how JavaScript makes decisions and performs calculations — the true backbone of programming. 💡 Key Highlights: ● Arithmetic, Comparison, Logical & Bitwise Operators ● Short-circuit evaluation & ternary conditions ● if, else if, and switch statements in real-world logic These concepts make code think — transforming simple scripts into intelligent, responsive programs. 🙏 Thanks to @Love for simplifying complex logic beautifully! ✅ Day 35 complete — 46 more to go 🚀 🔗 GitHub Repo: https://lnkd.in/dtdU9-zZ #JavaScript #WebDevelopment #Frontend #CodingJourney #LearnWithMe #Programming #LoveForCoding ❤️
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