2665. Counter II
Fourth photo: Another solution I liked in Solutions section.
Fourth photo: Another solution I liked in Solutions section.
Programming notes
I have started โ30 days of JavaScriptโ study plan in Leetcode. Solved four problems and finished first section. First and second problems were quite easy. I will share my solution for remaining two problems. Letโs make 10 day challenge to solve at leastโฆ
LeetCode
30 Days of JavaScript - Study Plan - LeetCode
Learn JS Basics with 30 Qs
๐พ Memory: 48.79 MB. Beats 59.75%
โถ๏ธ Pre-allocate Memory: By creating a new array with new Array(arr.length), we allocate the required memory upfront, which can be more efficient for large arrays.
const newArray = new Array(arr.length);
โถ๏ธ Direct Assignment: Assigning the transformed value directly to the array index avoids the overhead of the push operation.
newArray[i] = fn(arr[i], i);
Will wait for reactions
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
๐พ Memory: 48.67 MB. Beats 81.42%
๐ Link: https://leetcode.com/problems/filter-elements-from-array/description/?envType=study-plan-v2&envId=30-days-of-javascript
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Precompute length
Storing nums.length in a variable avoids recomputing the length of the array on every iteration.
This reduced runtime from 53 ms to 42 ms.
@leetcode_javascript
Storing nums.length in a variable avoids recomputing the length of the array on every iteration.
This reduced runtime from 53 ms to 42 ms.
@leetcode_javascript
The reduceRight() method executes a reducer function for each array element.
The reduceRight() method works from right to left.
The reduceRight() method returns a single value: the function's accumulated result.
The reduceRight() method does not execute the function for empty elements.
๐ช 10 Day Challenge: Day 4 โ
@leetcode_javascript
The reduceRight() method works from right to left.
The reduceRight() method returns a single value: the function's accumulated result.
The reduceRight() method does not execute the function for empty elements.
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
๐ "Promise.all" takes an array of promises and returns a single promise that resolves when all of the promises in the array have resolved. The resolved value will be an array of the resolved values of the input promises.
๐ The "then" method is used to handle the resolved values of the promises. It takes a callback function that receives the resolved values as an array.
๐ช 10 Day Challenge: Day 6 โ
@leetcode_javascript
๐ The "then" method is used to handle the resolved values of the promises. It takes a callback function that receives the resolved values as an array.
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM