Programming notes
256 subscribers
438 photos
1 video
1 file
130 links
Student at the University of Arkansas πŸ‡ΊπŸ‡Έ

In Uzbek @uzbekode
Download Telegram
πŸ–₯ 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
First medium problem of the Challenge.

Acceptance rate: 62.5%

πŸ’ͺ 10 Day Challenge: Day 7 βœ…

@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ’ͺ 10 Day Challenge: Day 8 βœ…

@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ’ͺ 10 Day Challenge: Day 9 βœ…

@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ’ͺ 10 Day Challenge: Day 10 βœ…

Challenge completed!
😎

@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM