Programming notes
256 subscribers
438 photos
1 video
1 file
130 links
Student at the University of Arkansas ๐Ÿ‡บ๐Ÿ‡ธ

In Uzbek @uzbekode
Download Telegram
2704. To Be Or Not To Be
2665. Counter II

Fourth photo: Another
solution I liked in Solutions section.
๐Ÿ–ฅ Problem: 2635. Apply Transform Over Each Element in Array

โšก๏ธ Runtime: 55 ms. Beats 37.56%

๐Ÿ’พ Memory: 48.79 MB. Beats 59.75%

๐Ÿ’ช 10 Day Challenge: Day 2 โœ…

๐Ÿค” Optimization:

โ–ถ๏ธ 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
๐Ÿ–ฅ Problem: 2634. Filter Elements from Array

โšก๏ธ Runtime: 48 ms. Beats 83.58%

๐Ÿ’พ Memory: 48.67 MB. Beats 81.42%

๐Ÿ’ช 10 Day Challenge: Day 3 โœ…

๐Ÿ”— 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
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
Please open Telegram to view this post
VIEW IN TELEGRAM
Memory is quite good, but runtime ๐Ÿฅด

๐Ÿ’ช 10 Day Challenge: Day 5 โœ…
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
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM