🚀 Efficient Task Scheduling with JavaScript (LeetCode 621: Task Scheduler) Today I explored an interesting problem — scheduling tasks with cooldown periods efficiently. 🔹 Problem: Given a list of tasks (like ['A', 'A', 'A', 'B', 'B', 'B']) and a cooldown interval n, find the least number of intervals needed to finish all tasks without breaking the cooldown rule. 🔹 Key Idea: Count the frequency of each task. Sort to find the most frequent task. Use idle slots to manage cooldowns. Minimize idle time and calculate total intervals. 💡 Learning: This problem taught me how to use frequency counting, sorting, and greedy scheduling together to reduce idle time and improve performance. #JavaScript #TypeScript #Coding #ProblemSolving #LeetCode #WebDevelopment #TechLearning
Efficient Task Scheduling with JavaScript: LeetCode 621
More Relevant Posts
-
Let’s decode three of the most confusing JavaScript topics 👇 🔹 1. Scope Scope defines where your variables and functions are accessible. Global Scope: Accessible everywhere in the code. Function Scope: Accessible only inside a function. Block Scope: (introduced with let & const) accessible only within { }. 🔹 2. Hoisting JavaScript moves declarations to the top of their scope before code execution. But remember — only declarations are hoisted, not initializations. That’s why var behaves differently than let and const. 🔹 3. TDZ (Temporal Dead Zone) The period between entering a scope and initializing a variable declared with let or const. Accessing a variable in TDZ results in a ReferenceError — it exists but isn’t accessible yet! #JavaScript #FrontendDevelopment #WebDevelopment #Coding #Programming #LearnToCode #Scope #Hoisting #TDZ
To view or add a comment, sign in
-
-
🚀 Day 8 of My 30 Days of JavaScript Journey ✅ Challenge: Function Composition (LeetCode #2629) Build a function compose(functions) that returns a new function representing the composition of all given functions. When called with an input x, it evaluates from right to left, applying each function in sequence. If no functions are provided, it returns the identity function — meaning f(x) = x. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gEXnFK4d 💡 Solution: https://lnkd.in/gjKcFQvB 🧠 Concept Highlighted: This challenge explores function composition, a key concept in functional programming, showing how multiple simple functions can combine to form powerful transformations. It reinforces the importance of execution order and function chaining in JavaScript. #Day8 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #FunctionalProgramming #LearningEveryday #ProblemSolving
To view or add a comment, sign in
-
Day 8 of #30DaysOfJavaScript on LeetCode Today's challenge: 2629 — Function Composition The task was to implement a function that takes an array of functions [f1, f2, f3, ..., fn] and returns a new function that represents their composition. In simple terms, the composed function should apply all the given functions from right to left, just like: f(g(h(x))) Here’s my solution 👇 var compose = function(functions) { return function(x) { let res = x; for (let i = functions.length - 1; i >= 0; i--) { res = functions[i](res); } return res; } }; This challenge gave me a deeper understanding of how function chaining and composition work in JavaScript — building complex logic from smaller, reusable functions. It’s a beautiful example of how functional programming principles simplify problem-solving! Try it out here : https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Functions #Callbacks #Programming #Composition
To view or add a comment, sign in
-
-
Instead of const result = sanitize(validate(capitalize(truncate(trim(userInput)) )); which is nested, unreadable, and hard to debug, with a simple reusable pipe like the one below we can have const cleanTitle = pipe(trim,truncate,capitalize, validate,sanitize); const result = cleanTitle(userInput); which is declarative and reads like a story. For dig into more tips like these check functional programming arena in Javascript -> https://lnkd.in/d8XurWWs #JavaScript #SoftwareEngineering #SoftwareDevelopment #Coding #100DaysOfCode #FunctionalProgramming #DeclarativeProgramming #MaintainableCode
To view or add a comment, sign in
-
-
💡 Understanding Object Methods in JavaScript Working with objects is fundamental in JS. Here's a quick overview of some powerful methods: Object.keys(obj) → Returns all keys of the object. Object.values(obj) → Returns all values of the object. Object.entries(obj) → Returns key-value pairs as arrays. obj.hasOwnProperty("property") → Checks if the object has a specific property. Object.assign({}, obj, { newProperty: "newValue" }) → Creates a new object by merging existing ones. 👉 View the full example on GitHub: https://lnkd.in/dDN-vDkD #JavaScript #FullStack #100xDevs #WebDevelopment #Coding #JSConcepts #LearnJavaScript
To view or add a comment, sign in
-
Deep Javascript Series Question 1: interviewer: “Can you explain how the JS event loop functions?” me: The event loop works like a traffic supervisor. JavaScript handles one task at a time. When asynchronous actions occur, like setTimeout or fetch, they take place outside the main thread. Once the stack is clear, the event loop looks for: - Microtasks: Promises, MutationObservers - Macrotasks: setTimeout, setInterval, I/O Microtasks always come first. That’s why a Promise callback runs before a setTimeout(…, 0). JavaScript doesn’t run in parallel; it just waits. #JavaScript #WebDevelopment #FrontendDevelopment #Developers #BuildInPublic #Programming #DeepJavaScript #TechCommunity #CodingJourney
To view or add a comment, sign in
-
In today’s class, we explored some really interesting JavaScript concepts related to Arrays — and how we can add, remove, and modify elements dynamically. Here’s a quick overview of what we covered 👇 📘 Topics we practiced: 🔹 Adding elements using push() and unshift() 🔹 Removing elements using pop() and shift() 🔹 Copying parts of an array with slice() 🔹 Replacing or removing elements with splice() A big shoutout to Miss Fatima Khalid for explaining everything so clearly and making the session interactive and fun! 🙌 Every small concept we learn adds up — one step closer to writing cleaner, smarter code 💪✨ #JavaScript #WebDevelopment #LearningJourney #Coding #Arrays #WomenInTech #StudentLife
To view or add a comment, sign in
-
-
Day 7 of #30DaysOfJavaScript: Solved the Function Composition Challenge! 🎉 Today's problem involved creating a function that composes an array of functions and applies them from right to left, just like mathematical function composition 𝑓(𝑔(ℎ(𝑥))) f(g(h(x))). Using JavaScript's reduceRight, I built a clean, efficient solution that handles composing any number of functions—even when the array is empty (returning the identity function). This challenge sharpened my understanding of higher-order functions and functional programming concepts. Here’s a quick look at the core idea: js const compose = (functions) => (x) => functions.reduceRight((acc, fn) => fn(acc), x); Example: Input functions: [x => x + 1, x => x * x, x => 2 * x] Input value: 4 Output: 65 Excited to keep growing and sharing every step in this coding journey! #JavaScript #LeetCode #FunctionalProgramming #CodeChallenge #WebDevelopment #LearningJourney #Programming
To view or add a comment, sign in
-
🚀 Day 806 of #900DaysOfCode 📘 Important Built-in JavaScript Methods You Must Know JavaScript gives us a treasure of built-in methods that make coding easier, cleaner, and more efficient. In today’s post, I’ve covered some of the most powerful and commonly used JS methods that every developer should master — from arrays and strings to objects and numbers. These methods can save you lines of code, improve readability, and help you write smarter, more elegant JavaScript. 💡 If you want to go from writing code to crafting solutions — this post is for you! 💬 Which JS method do you find yourself using the most? Drop it in the comments 👇 #Day806 #learningoftheday #900daysofcodingchallenge #JavaScript #WebDevelopment #FrontendDevelopment #CleanCode #LearnToCode #Programming #CodeBetter
To view or add a comment, sign in
-
🚀 Starting My JavaScript Revision Journey! Body: Yesterday, I went back to the basics of JavaScript to strengthen my foundation. Here’s what I revised: 🟡 Variables — var, let, and const and when to use them 🟡 Scope — Global variables (accessible everywhere) — Local variables (accessible within a function/block) 🟡 Data Types — Primitive: string, number, boolean, null, undefined, symbol, bigint — Non-Primitive: objects, arrays, functions It’s amazing how revisiting fundamentals clears a lot of confusion! What JavaScript concept took you time to understand when starting out? #JavaScript #BackendDevelopment #LearningJourney #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