Today I didn’t just solve the Two Sum problem on LeetCode — I truly understood it. Instead of rushing to pass test cases, I slowed down and asked myself: What is the problem really asking? Why do we return indices and not values? How can I solve this efficiently instead of checking every possible pair? The key insight was thinking in terms of complements: “If I have this number, what number do I need to reach the target?” By storing previously seen numbers in a hash map, I was able to reduce the solution to a single pass through the array. Here’s the solution in JavaScript: function twoSum(nums, target) { const seen = {}; for (let i = 0; i < nums.length; i++) { const needed = target - nums[i]; if (seen[needed] !== undefined) { return [seen[needed], i]; } seen[nums[i]] = i; } } This small win reminded me that becoming a better software engineer isn’t about memorizing solutions — it’s about thinking clearly, writing intentional code, and understanding why it works. On to the next problem 🚀 #JavaScript #LeetCode #ProblemSolving #LearningInPublic #SoftwareEngineering #FrontendDeveloper #CareerGrowth
Two Sum Problem Solution in JavaScript
More Relevant Posts
-
💻 3 Ways I Write Cleaner, More Maintainable Code in TypeScript Early in my career, I thought “if it works, ship it.” Now I think differently: if it’s readable and scalable, ship it. 😅 Here are 3 simple habits that seriously improved my TypeScript code quality 👇 1️⃣ Be strict with types (don’t fight the compiler) Turning on strict mode felt annoying at first… but it forced me to think better. Clear interfaces and proper types catch bugs before production ever sees them. 🛡️ 2️⃣ Keep functions small and focused If a function does 5 things, it’s doing too much. I try to follow one responsibility per function. Cleaner logic = easier debugging later. 3️⃣ Name things like a human would read them data, temp, value… we’ve all done it. But descriptive names like userProfile, calculateInvoiceTotal, or isSubscriptionActive make your code self-documenting. 📖 Bonus: I always ask myself — “If another developer opens this file 6 months later, will they thank me… or suffer?” 😄 Clean code isn’t about being perfect. It’s about being thoughtful. What’s one TypeScript habit that improved your code quality? 👇 #TypeScript #CleanCode #CodeQuality #SoftwareDevelopment #ProgrammingTips #DeveloperLife
To view or add a comment, sign in
-
-
4 months ago: 118 WPM, 99% accuracy. Today: 129 WPM - 100% accuracy. Not just faster. Cleaner. And honestly, that jump from 99% → 100% accuracy feels bigger than the extra 11 words per minute. Speed with zero errors is a different beast entirely. As a Full Stack Developer, typing isn't a "soft skill" to me - it's infrastructure. Every React component, every API endpoint, every late-night debugging session runs through your fingers first. The faster and cleaner that pipeline is, the better your output. What actually got me here wasn't talent. It was 10–15 minutes of deliberate daily practice on Monkeytype for 4 months straight - treating it the same way I treat learning a new framework. Consistently. With intention. 💡 What changes above 125 WPM: The gap between thinking and writing nearly disappears You stay in flow state longer because mechanics stop interrupting thought Code reviews, documentation, client communication - everything gets sharper You stop feeling like your hands are slowing your brain down The best developers I know don't just write good code - they write it with confidence and speed. Typing is where that starts. Fellow devs — what's your WPM? Have you ever trained it deliberately? 👇 #FullStackDeveloper #WebDevelopment #Productivity #CodingLife #SoftwareDeveloper #TechSkills #Programming #JavaScript #React #NodeJS #DeveloperProductivity #WebDev #SoftwareEngineering #CodeFaster #TechCommunity
To view or add a comment, sign in
-
-
Weekly Update – Building Towards Industry Readiness This week I focused on improving my backend understanding and practical coding skills. 📌 Practiced JavaScript array methods with real problem-solving 📌 Strengthened my understanding of scopes and functions 📌 Worked on API concepts and request–response flow 📌 Spent time debugging and improving code quality 💡 Lesson of the week: Understanding why something works is more important than just making it work. One step closer to becoming job-ready. #LearningInPublic #BackendDeveloper #JavaScript #MCAJourney #Consistency
To view or add a comment, sign in
-
Hoisting isn't magic. It's Memory Management. 🧠 Many developers think Hoisting means "JavaScript moves code to the top of the file." That is a myth. Your code doesn't move anywhere. What actually happens? JavaScript execution has two phases: Memory Creation Phase: The engine scans your code and allocates memory for variables/functions. Execution Phase: The code actually runs. This creates 3 distinct behaviors: ✅ Function Declarations: The engine copies the entire code into memory. (Fully usable). ⚠️ var Variables: The engine allocates memory but sets the value to undefined. ❌ let & const: The engine allocates memory but forbids access (Temporal Dead Zone). Understanding this difference separates a Junior Dev from a Senior Dev. It’s not just about syntax; it’s about understanding the Execution Context. Save this for your next architectural discussion! 💾 #javascript #programming #tech #webdev #coding #computerscience
To view or add a comment, sign in
-
The Reality of Backend Dev: Focus, Frustration, and "The Fix" 💻 They say coding is 10% writing and 90% debugging. Today, I lived that 90%. We’ve all been there: Your code is structured, your logic feels solid, and then… MODULE_NOT_FOUND. Node.js crashes, and your terminal turns into a wall of red text. It’s easy to get frustrated, but these "red walls" are actually where the real learning happens. The Lesson: Focus on Architecture, Not Just Syntax As I move deeper into Express.js and MVC (Model-View-Controller), I’ve realized that most bugs don’t come from a missing semicolon. They come from a lack of focus on the Structure. By shifting my focus to professional architecture, I’m learning how to beat the "nitty-gritty" details that cause these crashes: MVC for Mental Clarity: Splitting my code into Models (Data), Views (UI), and Controllers (Logic) means when an error happens, I know exactly which "department" to check. The Power of Frameworks: I’m letting Express.js do the heavy lifting of routing and parsing, so I can focus my brainpower on the Business Logic. Organized Debugging: Instead of guessing, I’m learning to trace the Middleware Funnel. If a request doesn't reach the response, I check the next() calls in my middleware chain. My Debugging Workflow 🛠️ Breathe: A crashed server isn't a failure; it’s a hint. Trace the Path: Did the route trigger the controller? Did the controller call the model?. Verify the "Handshake": In MVC, if the Controller and Model aren't talking correctly, the View will never render. The bottom line: Professionalism in coding isn't about never having errors—it's about building an architecture so organized that debugging becomes a science, not a guessing game. #NodeJS #WebDevelopment #MVC #SoftwareEngineering #Debugging #BuildInPublic #CleanCode #ExpressJS #CodingLife
To view or add a comment, sign in
-
-
𝗧𝘂𝘁𝗼𝗿𝗶𝗮𝗹 𝗖𝗼𝗱𝗲 𝘃𝘀 𝗣𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 𝗖𝗼𝗱𝗲: 𝗧𝗵𝗲 𝗥𝗲𝗮𝗹𝗶𝘁𝘆 𝗖𝗵𝗲𝗰𝗸 We've all been there... 𝗧𝘂𝘁𝗼𝗿𝗶𝗮𝗹 𝗰𝗼𝗱𝗲: Clean, organized, documented, follows best practices. Everything works perfectly. No bugs. Beautiful to look at. 𝗣𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 𝗰𝗼𝗱𝗲: 10,000+ lines, multiple developers, legacy dependencies, coffee-stained desk, sticky notes everywhere saying "Don't touch this!", "Fix later", and the classic "It works, don't touch it." The difference between what we learn and what we maintain is often hilarious – but that's real software development. 𝗛𝗲𝗿𝗲'𝘀 𝘄𝗵𝗮𝘁 𝘁𝘂𝘁𝗼𝗿𝗶𝗮𝗹𝘀 𝗱𝗼𝗻'𝘁 𝘁𝗲𝗮𝗰𝗵 𝘆𝗼𝘂: - How to work with code written by 5 different developers - Why that "temporary fix" from 2 years ago is now mission-critical - The art of debugging code with zero documentation - How to read someone else's "clever" solution at 2 AM 𝗕𝘂𝘁 𝗵𝗲𝗿𝗲'𝘀 𝘁𝗵𝗲 𝘁𝗿𝘂𝘁𝗵: Production code isn't messy because developers are bad. It's messy because: ✅ Requirements change constantly ✅ Deadlines are real ✅ Quick fixes become permanent ✅ Teams evolve and knowledge gets lost ✅ "Good enough" ships, "perfect" doesn't The real skill isn't writing perfect code – it's making sense of imperfect code and improving it incrementally. #SoftwareDevelopment #Coding #Programming #DeveloperLife #WebDevelopment #SoftwareEngineering #TechHumor #ProductionCode #CleanCode #RealityCheck #DevCommunity #CodeQuality #TechMemes #JavaScript #Python #React #NodeJS #FullStack #Frontend #Backend #WebDev #CodingLife #DeveloperHumor #TechLife #CodeNewbie #100DaysOfCode #LearnToCode #SoftwareDeveloper #TechCommunity #DevelopersOfLinkedIn #CodeReview #TechnicalDebt #LegacyCode #Debugging #SoftwareArchitecture
To view or add a comment, sign in
-
-
𝗛𝗼𝘄 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗔𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗘𝘅𝗲𝗰𝘂𝘁𝗲𝘀 𝗖𝗼𝗱𝗲 (𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻 𝗖𝗼𝗻𝘁𝗲𝘅𝘁 & 𝗖𝗮𝗹𝗹 𝗦𝘁𝗮𝗰𝗸) Recently, I explored how JavaScript executes code behind the scenes — especially Execution Context and the Call Stack. 𝗪𝗵𝗮𝘁 𝗜 𝗟𝗲𝗮𝗿𝗻𝗲𝗱 • Whenever a JavaScript program runs, a Global Execution Context is created. • Every execution context has two phases: 𝟭- 𝗠𝗲𝗺𝗼𝗿𝘆 𝗖𝗿𝗲𝗮𝘁𝗶𝗼𝗻 𝗣𝗵𝗮𝘀𝗲 • Memory is allocated for all variables and functions. • Variables are initialized with undefined. • Function declarations store their complete definition in memory. 𝟮- 𝗖𝗼𝗱𝗲 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻 𝗣𝗵𝗮𝘀𝗲 • Code executes line by line. • Actual values replace undefined. • When a function is invoked, a new execution context is created. 𝗘𝗮𝗰𝗵 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻 𝗰𝗮𝗹𝗹: • Gets its own execution context. • Is pushed onto the Call Stack. • Follows LIFO (Last In First Out) order. • Is removed from the stack after completion. 𝗧𝗵𝗲 𝗿𝗲𝘁𝘂𝗿𝗻 𝘀𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁: • Sends control back to the execution context where the function was invoked. • Replaces the assigned variable with the returned value. 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 JavaScript doesn’t just execute code line by line — it first prepares memory, then executes. Once you understand Execution Context and the Call Stack, you start predicting program behaviour instead of guessing it. #JavaScript #WebDevelopment #ExecutionContext #CallStack #FrontendDevelopment #Programming #CodingJourney #SoftwareEngineering #LearnInPublic #DeveloperLife #ComputerScience #JSInternals #TechLearning #FullStackDeveloper
To view or add a comment, sign in
-
-
JavaScript is not just syntax. Anyone can learn syntax. But real developers think before they code. ✔ Syntax is easy to learn ✔ Logic takes consistent practice ✔ Problem-solving builds confidence ✔ Practice improves thinking flow The real difference between a coder and a developer? 👉 Logic. Strong logic turns simple code into real-world solutions. It’s not about memorizing functions — it’s about understanding why and how things work. At Cupule Technologies, we focus on building thinking ability, not just teaching language syntax. Because in the industry, companies hire problem-solvers — not just code writers. 💡 Think better. Code smarter. Build stronger. 💥 Ready to elevate your journey? ✅ Join Our Community for More Info 👉 https://lnkd.in/g88h8xEF ✅ Fill This Form for 1:1 Counseling 🔗 https://lnkd.in/gbMpt6r8 ✅ Visit Our Website 🌐 https://lnkd.in/gVpcfM9q Let’s build careers, not just code. 📸 Follow us on Instagram for daily tech tips & updates: 👉 https://lnkd.in/ghUAdSrW #JavaScript #WebDevelopment #ProgrammingLogic #SoftwareDevelopment #DeveloperMindset #SkillBasedLearning #CupuleTechnologies #CupuleGwalior #CupuleChicago
To view or add a comment, sign in
-
-
Mastering JS? Small habits make huge impact. ✨ Nail naming conventions: `calculateTotalPrice` always beats `calc`. It saves hours of debugging and makes your code immediately understandable for others. Simplicity wins. ✅ Flatten complex logic. Deeply nested if/else statements create mental mazes. Employ early returns or guard clauses for clearer, more maintainable functions. 💡 Comments aren't for explaining *what* your code does, but *why*. Write them strategically to clarify complex decisions or workarounds, not trivialities. 🚀 Consistency builds trust. Use linters and formatters consistently across projects. This ensures uniformity and reinforces a predictable, reliable codebase. ⚙️ Want more practical tips to simplify your dev workflow? Follow me for insights from my full-stack journey. 🌟 #JavaScript #WebDevelopment #CodingTips #JuniorDev #JrToSr
To view or add a comment, sign in
-
Many developers start by removing duplicates in JavaScript using a for loop. It works. It gets the job done. But over time, clean code becomes more important than just working code. That’s where Set() changes the game. One line. Readable. Efficient. The difference between beginner and experienced developers often isn’t complexity — it’s simplicity. Great developers don’t write longer code. They write smarter code. Small improvements like this compound over time and make a real difference in maintainability and performance. ——————- I’m Dayo Jaiye, a software engineer. I share my journey, coding practices, and practical tips to help developers write cleaner, faster, and more maintainable code. Connect with me to learn from my experiences, level up your skills, and discover real-world software engineering insights. #javascript #webdevelopment #softwareengineering #coding #programming
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