Skip to content

DSA

Algorithms, Data Structures, Competitive Coding, and problems from LeetCode with complete Solution Approach, Pseudocode, and Explanation.

Cache With Time Limit - 2622

Cache With Time Limit – 2622

🔗LC2622 🟡 Medium 🧩 Pattern – Promises and Time, Map 📅 Day 17/30 Days of JavaScript Write a class that allows getting and setting key-value pairs, however a time until expiration is associated with each key. The class has three public methods: set(key, value, duration): accepts an integer key, an integer value, and a duration in milliseconds.… Read More »Cache With Time Limit – 2622

Promise Time Limit - 2637

Promise Time Limit – 2637

🔗LC2637 🟡 Medium 🧩 Pattern – Promises and Time 📅 Day 16/30 Days of JavaScript Given an asynchronous function fn and a time t in milliseconds, return a new time limited version of the input function. fn takes arguments provided to the time limited function. The time limited function should follow these rules: Example Solution

Interval Cancellation - 2725

Interval Cancellation – 2725

🔗LC2725 🟢 Easy 🧩 Pattern – Promises and Time 📅 Day 15/30 Days of JavaScript Given a function fn, an array of arguments args, and an interval time t, return a cancel function cancelFn. After a delay of cancelTimeMs, the returned cancel function cancelFn will be invoked. setTimeout(cancelFn, cancelTimeMs) The function fn should be called… Read More »Interval Cancellation – 2725

Timeout Cancellation - 2715

Timeout Cancellation – 2715

🔗LC2715 🟢 Easy 🧩 Pattern – Promises and Time 📅 Day 14/30 Days of JavaScript Given a function fn, an array of arguments args, and a timeout t in milliseconds, return a cancel function cancelFn. After a delay of cancelTimeMs, the returned cancel function cancelFn will be invoked. setTimeout(cancelFn, cancelTimeMs) Initially, the execution of… Read More »Timeout Cancellation – 2715

Sleep - 2621

Sleep – 2621

🔗LC2621 🟢 Easy 🧩 Pattern – Promises and Time 📅 Day 13/30 Days of JavaScript Given a positive integer millis, write an asynchronous function that sleeps for millis milliseconds. It can resolve any value. Example Solution The promise will wait until the setTimeout completes and calls the resolve method, and the setTimeout… Read More »Sleep – 2621

Add Two Promises - 2723

Add Two Promises – 2723

🔗LC2723 🟢 Easy 🧩 Pattern – Promises and Time 📅 Day 12/30 Days of JavaScript Given two promises promise1 and promise2, return a new promise. promise1 and promise2 will both resolve with a number. The returned promise should resolve with the sum of the two numbers. Example Solution