💡 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
Madhankumar M’s Post
More Relevant Posts
-
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
-
-
🔥 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗖𝗼𝗱𝗶𝗻𝗴 — 𝗙𝗶𝗹𝗲 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 Got inspired after watching Akshay Saini 🚀’s Machine coding series — and decided to take on a fun machine coding challenge: Building a file explorer from scratch. 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁 👇 ✅ Render a tree-structure from JSON (folders/files with expand-collapse) ✅ Add new files or folders dynamically at any level ✅ Keep everything sorted alphabetically — folders first, then files 𝗧𝗲𝗰𝗵𝗻𝗶𝗾𝘂𝗲𝘀 𝗜 𝘂𝘀𝗲𝗱: 1. Recursive function to render nested structures. 2. React Context API to manage shared states (active folder, add mode, etc). 3. Pure immutable state updates using structured cloning for clean re-renders. 4. Smart sorting logic — folders and files handled separately and merged elegantly. 💻 𝗟𝗶𝘃𝗲 𝗱𝗲𝗺𝗼 : https://lnkd.in/gJapscTm 🔗 𝗚𝗶𝘁𝗛𝘂𝗯 (𝗰𝗼𝗱𝗲): https://lnkd.in/gCnpu39P 🎥 𝗔𝗸𝘀𝗵𝗮𝘆'𝘀 𝗬𝗧 𝘃𝗶𝗱𝗲𝗼: https://lnkd.in/gXch9JKE 𝗗𝗿𝗼𝗽 𝘆𝗼𝘂𝗿 𝘁𝗵𝗼𝘂𝗴𝗵𝘁𝘀 👇 — 𝘄𝗼𝘂𝗹𝗱 𝗹𝗼𝘃𝗲 𝘁𝗼 𝗱𝗶𝘀𝗰𝘂𝘀𝘀 𝗱𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵𝗲𝘀! #ReactJS #MachineCoding #FrontendDevelopment #JavaScript #CleanCode #WebDevelopment #SoftwareEngineering #CodingInterview #Learning
To view or add a comment, sign in
-
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
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
-
-
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
-
-
🚀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
-
-
🚀 #Day10 DSA & JavaScript Algorithms Journey 🔥 Power of Recursion Today, I explored one of the most famous sequences in mathematics — The Fibonacci Sequence 🌀 ✨ Problem Statement: Given a number n, find the nth element of the Fibonacci sequence. In Fibonacci, each number is the sum of the two preceding ones. 📌 Examples using Recursive Fibonacci: recursiveFibonacci(0) = 1 recursiveFibonacci(1) = 1 recursiveFibonacci(6) = 8 🧠 My Approach: I solved this problem using Recursion. If F represents a function to calculate the Fibonacci number, then: 👉 F(n) = F(n - 1) + F(n - 2) 👉 For example: F(2) = F(1) + F(0) 👉 f(2) = 1 + 0✅ 💡 2 Tips for Recursive Solutions: 1️⃣ Break down the problem into smaller versions of the same problem. 2️⃣ Identify the base case clearly — this stops the recursion. ⚡ Complexity Insight: The Recursive Fibonacci solution is more time-consuming compared to the Iterative Fibonacci approach. ✅ Iterative is faster and more optimal, while Recursive helps in understanding the problem structure better. #Day9 #DSA #100DaysOfCode #Fibonacci #Recursion #JavaScript #Algorithms #LearningJourney #SherazLearns #ProblemSolving #Coding #TechJourney #Developer
To view or add a comment, sign in
-
-
📘 Today’s Learning: Big O Notation 🔍 Today I explored one of the most important concepts in programming — Big O Notation 🚀 Big O helps us understand how efficient our code is — how fast or slow it runs as the size of input grows. It’s all about analyzing time complexity and space complexity. 💡 What I learned & practiced: Understanding O(1), O(n), O(n²) and more Comparing how different data structures like Array and Set perform Experimenting with forEach, map, and loops to see how operations scale with input size Writing small test cases to visualize performance differences 🧠 Key Takeaway: Big O is not about exact speed — it’s about how your algorithm scales. Optimizing for efficiency is what separates good developers from great ones 💪 #BigONotation #TimeComplexity #CodingJourney #JavaScript #LearningEveryday
To view or add a comment, sign in
-
-
You don’t need more tutorials. You need cleaner code. Start with this: linting. What the hell is linting? 👇 Linting = automated code review. It catches the dumb stuff before your teammates do. ❌ Missing semicolons ❌ Bad formatting ❌ Unused imports ❌ Naming mess ❌ Logic bugs A linter doesn’t care how smart you are. It just makes your code not suck. Why does it matter? ✅ Makes your code consistent ✅ Reduces bugs ✅ Saves devs from stupid arguments ✅ Makes you look like a pro (even if you're not) Popular Linters: Python → ruff, pylint, flake8 JavaScript → eslint Rust → clippy Go → golint Pro tip: Set up pre-commit hooks with linting. Every time you commit → clean code. No excuses. TL;DR You can write messy code. Or write code your future self won’t hate. 📬 Want more no-fluff breakdowns like this? Subscribe → 𝗰𝗼𝗱𝗲𝟮𝗰𝗼𝗺𝗽𝗮𝘀𝘀.𝘀𝘂𝗯𝘀𝘁𝗮𝗰𝗸.𝗰𝗼𝗺 📺 Or binge the real dev stuff → @𝗰𝗼𝗱𝗲𝟮𝗰𝗼𝗺𝗽𝗮𝘀𝘀 #CodeQuality #Linting #CleanCode #DevTips #SoftwareEngineering #AIEngineer #Python #JavaScript #code2compass
To view or add a comment, sign in
-
🚀 Scheduled Task Automation – JS Code & Edit Node Flow Over the past 60 days, I’ve been diving deep into Python, JavaScript, and automation with n8n. One of the workflows I built showcases how simple automation can save time and structure daily tasks efficiently. Workflow Highlights: 1️⃣ Schedule Trigger Node – Automatically starts the workflow at a set time. 2️⃣ Code Node (JavaScript) – Cleans, trims, and sorts raw tasks into a structured JSON object. 3️⃣ Edit/Set Node – Maps the final tasks into a clean field for downstream automation. This workflow taught me the importance of structured automation in real-world scenarios, and how combining scheduling with code-driven logic can streamline repetitive processes. Excited to continue building more automation workflows, AI-driven tasks, and productivity boosters! #n8n #Automation #JavaScript #WorkflowAutomation #Productivity #Python #AI #LearningJourney #ProjectManagement
To view or add a comment, sign in
-
More from this author
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