Day 184: Moving Nodes and Counting Words I am now on Day 184! Today, I practiced more Linked List logic and started working with Strings. Here is what I did today in very simple steps: 1. Rotate List (LeetCode 61) 🔄 I learned how to take the end of a list and move it to the front. How? First, I find the length of the list. Then, I find the right place to "cut" the list and connect the end back to the start. 2. Swap Nodes in Pairs (LeetCode 24) 🤝 I learned how to swap every two nodes. For example, 1 -> 2 -> 3 -> 4 becomes 2 -> 1 -> 4 -> 3. The Trick: I used a "Sentinel" node to keep track of the head. I also tried a Recursive version, which made the code very short and clean! 3. Length of Last Word (LeetCode 58) 📏 I moved to Strings! I had to find the length of the very last word in a sentence. Manual Way: Instead of using easy shortcuts, I started from the end of the string, skipped the empty spaces, and counted the letters until I hit another space. It is a great way to practice loops. My takeaway: Whether it is cutting a list or counting letters backward, logic is all about finding the right starting point! #JavaScript #Coding #Programming #WebDevelopment #DataStructures #Algorithms #SoftwareEngineer #Logic #SimpleLearning #StringManipulation #LinkedList #TechCommunity #DailyCoding #ProblemSolving #CareerGrowth #CodeNewbie
Linked List Practice: Rotating, Swapping, and Counting
More Relevant Posts
-
It's 5:45 am & I am still looking at my dreams. Today[2/28/2026] is day 23 of learning javascript Today & tommorow i will learn are: 1. Difference between let, const & var 2. How to use the default parameter 3. Template string, Multiline string, Dynamic string 4. Arrow Function Syntax, params 5. Spread Operator, Array Max, Copy Arrays 6. Object & Array destructuring 7. Keys, Values, Entries, Delete, Seal, Freeze 8. Accessing Object Data: Nested Object, Optional Chaining 9. Looping Object 10. Primitive Type, Non Primitive Type 11. Null Vs Undefines 12. Truthy & Falsy Values 13. ==, === , implicit conversion 14. Block Scope, Global Scope, Simple Unders. of Hoisting 15. Closure 16. Callback Function & pass different function 17. Function Arguments, pass by ref. pass by value 18. Map, ForEach 19. Filter, Find, Reduce #letsconnect #programmer #frontenddeveloper #mernstakedeveloper #Coding
To view or add a comment, sign in
-
Day 26 of 30-day Coding Sprint 992. Subarrays with K Different Integers - The Problem: Count every single contiguous subarray that contains exactly k different integers. - The Challenge: A standard sliding window is "greedy"; it finds the largest or smallest window that fits a condition. But here, multiple windows of different sizes ending at the same index r could all have exactly k integers. Approach 1: Brute Force - Generating all subarrays and checking unique counts using a HashMap. - Complexity: O(n^2). This will TLE (Time Limit Exceeded) on any competitive platform with a large input. Approach 2: The "Exactly K" via "At Most K" Logic (Optimal) - The Strategy: Just like we did with binary sums on Day 21, we use the formula: Exactly(K) = AtMost(K) - AtMost(K-1) - The Helper: helper(nums, k) counts how many subarrays have at most $k$ distinct elements. - Why it works: Finding "at most" is easy with a sliding window: if map.size > k, we shrink from the left. The number of subarrays ending at r that satisfy "at most k" is simply (r - l + 1). - Complexity: O(n) time and O(k) space. #30DaysOfCode #DSASprint #LeetCode #JavaScript #SlidingWindow #HardProblem #Algorithms #Consistency
To view or add a comment, sign in
-
-
Object.freeze() VS Object.seal() 👇 - In freeze, object's structure and values are totally locked. existing properties can't be changed or deleted. new properties can't be added. - In seal, only object's structure is locked. existing properties can be changed but not deleted. new properties can't be added. Important Points 👇 - Both freeze and seal are shallow which means they only affect the outer main object and not the nested objects. - The structure and properties of nested objects can still be changed. - To make seal or freeze deep, we have to apply it recursively on all nested objects through functions or loops. Hitesh Choudhary Piyush Garg Chai Aur Code Akash Kadlag Jay Kadlag #JavaScript #WebDevelopment #FrontendDevelopment #WebDev #Coding #Programming #Developer #LearnJavaScript #LearningInPublic #100DaysOfCode #TechCommunity #SoftwareDevelopment #ObjectOrientedProgramming #ChaiAurCode #ReactJS
To view or add a comment, sign in
-
😂 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝗶𝗻 𝘁𝘄𝗼 𝗲𝗿𝗮𝘀, 𝘀𝗮𝗺𝗲 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: 𝗼𝘃𝗲𝗿𝗰𝗼𝗺𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗻𝗴 𝘀𝗶𝗺𝗽𝗹𝗲 𝗹𝗼𝗴𝗶𝗰 2020: solve a basic odd/even check with a giant chain of if statements 😅 2026: wrap a tiny problem in an unnecessary abstraction / helper call 📦💀 Different style… same issue: using too much for something simple. Real lesson (and it matters) 👇 Good programming is not about writing more code. It’s not about using more libraries either. It’s about: ✅ knowing the simplest correct solution ✅ understanding built-in language features ✅ using libraries when they solve a real problem (not a 1-line one) ✅ keeping code readable, testable, and easy to maintain Libraries are powerful. 🛠️ But engineering judgment is knowing when not to add one. Sometimes the best code is: ◆ smaller ◆ boring ◆ obvious ◆ and done ✅ 💾 Save this for later 🔁 Repost if this is too real 😅 ➕ Follow Rahul Choudhary for more dev humor + practical tips w3schools.com JavaScript Mastery #Programming #SoftwareEngineering #DeveloperHumor #CleanCode #JavaScript #Coding #ProblemSolving #DeveloperMindset #WebDevelopment
To view or add a comment, sign in
-
-
Day 27 of 30-day Coding Sprint 76. Minimum Window Substring - The Goal: Find the smallest substring in s that contains all characters of t (including duplicates). - The Strategy: Expand & Contract - Preprocessing: Build a frequency map (using a 256-size array) for all characters in t. - Expansion (r pointer): Move the right pointer to expand the window. If the current character is part of t and we still need more of it, increment our count. - Contraction (l pointer): Once count == m (meaning the window is "valid"), try to shrink it from the left to find the minimum possible length. - The "Squeeze": As we move l, we update our frequency map. If moving l causes us to lose a required character from t, the window becomes invalid, and we go back to expanding. Result: Efficient O(N + M) time complexity and O(256) space. #30DaysOfCode #DSASprint #LeetCode #JavaScript #SlidingWindow #HardProblem #Algorithms #Consistency
To view or add a comment, sign in
-
-
JavaScript’s sort() can silently break your algorithms. I was solving LeetCode #350 (Intersection of Two Arrays II) using the two-pointer approach and hit an unexpected issue. I sorted the arrays like this: nums.sort() It looked fine… until it wasn’t. Example: [1, 2, 10, 5].sort() // → [1, 10, 2, 5] Why? Because JavaScript sorts lexicographically (as strings) by default. So the engine actually compares: "1", "10", "2", "5" Correct numeric sorting requires a comparator: nums.sort((a, b) => a - b) Without this, algorithms that rely on sorted arrays (binary search, two-pointer techniques, etc.) can produce incorrect results. #JavaScript #WebDevelopment #Programming #CodingTips #LeetCode #Algorithms #SoftwareEngineering #FrontendDevelopment
To view or add a comment, sign in
-
-
Most developers learn reduce() as “the method to sum numbers.” That’s only scratching the surface. reduce() exists to help you transform arrays into a single result — whether that’s: • A total • A grouped object • A flattened array • A computed data structure It encourages functional programming patterns and helps eliminate complex loops and mutable state. Understanding why reduce() exists changes how you approach data transformation in JavaScript. If you're growing as a developer, mastering reduce() is a turning point. What was the moment reduce() finally clicked for you? #JavaScript #SoftwareDevelopment #WebDevelopment #Frontend #Programming #Tech
To view or add a comment, sign in
-
Just published a new blog on JavaScript Arrays. When we start programming, we often store values like this: let movieOne = "Inception" let movieTwo = "Interstellar" let movieThree = "Dune: Part Two" This works for small data, but imagine storing 50 movies or 100 student marks. Managing individual variables quickly becomes messy. That is where arrays help. In this blog I covered: What arrays are in JavaScript Different ways to create arrays Accessing elements using indexes Updating array values Understanding the length property Looping through arrays using a simple for loop Arrays are one of the most commonly used data structures in JavaScript and understanding them early makes working with data much easier. link: https://lnkd.in/dYQtZ4P6 #javascript #coding #programming #learninpublic #chaicode
To view or add a comment, sign in
-
-
😂 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝗶𝗻 𝘁𝘄𝗼 𝗲𝗿𝗮𝘀, 𝘀𝗮𝗺𝗲 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: 𝗼𝘃𝗲𝗿𝗰𝗼𝗺𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗻𝗴 𝘀𝗶𝗺𝗽𝗹𝗲 𝗹𝗼𝗴𝗶𝗰 2020: solve a basic odd/even check with a giant chain of if statements 😅 2026: wrap a tiny problem in an unnecessary abstraction / helper call 📦💀 Different style… same issue: using too much for something simple. Real lesson (and it matters) 👇 Good programming is not about writing more code. It’s not about using more libraries either. It’s about: ✅ knowing the simplest correct solution ✅ understanding built-in language features ✅ using libraries when they solve a real problem (not a 1-line one) ✅ keeping code readable, testable, and easy to maintain Libraries are powerful. 🛠️ But engineering judgment is knowing when not to add one. Sometimes the best code is: ◆ smaller ◆ boring ◆ obvious ◆ and done ✅ #Programming #SoftwareEngineering #DeveloperHumor #CleanCode #JavaScript #Coding #ProblemSolving #DeveloperMindset #WebDevelopment
To view or add a comment, sign in
-
-
build a small practice programme: unit convertor Registry Pattern: Instead of massive if/else chains, I used a lookup object (reg) to define unit types and factors. Base Unit Normalization: I converted everything to a "Base Unit" first (e.g., meters), then to the target. This avoids needing a unique formula for every possible pair (like km -> cm). Type Validation: I added a strict check (from.type !== to.type) to prevent incompatible conversions, like trying to convert Weight to Length. Handling Exceptions: Since Temperature requires offsets (like +32) and not just multiplication factors, I separated it into its own switch case logic. #Javascript #WebDev #LearningInPublic #Coding
To view or add a comment, sign in
-
Explore related topics
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