Добавить
Уведомления

How to Solve "1464 Maximum Product of Two Elements in an Array" on LeetCode? - Javascript

Do you need more help with coding? ════════════════════════════ ✅ Apply for 1-1 coaching https://form.jotform.com/230156286763056 ════════════════════════════ How to Solve "1464 Maximum Product of Two Elements in an Array" on LeetCode? Problem: #1464 Maximum Product of Two Elements in an Array Language: Javascript Difficulty: Easy Strategy: Create variable to hold max value and 2nd max value. Time Complexity: O(n) Space Complexity: O(1) Pseudo Code: 1. Create a max variable. 2. Create a max2 variable. 3. Loop through nums. a. Create condition if current index value is greater than max and max2. i. Change max2 to max ii. Change the max to current index value. b. Else if the current index value is greater than max2. i. Change max2 to the current index value. 4. Return (max -1) * (max2 -1) GitHub Repo: https://github.com/anusontarangkul/leetcode-javascript-solutions/blob/main/1464-Maximum-Product-of-Two-Elements-in-an-Array/1464.js Let's Connect ?: ════════════════════════════ LinkedIn: https://www.linkedin.com/in/anusontarangkul/ TikTok: https://www.tiktok.com/@coding_david Instagram: https://www.instagram.com/coding_david_/ GitHub: https://github.com/anusontarangkul

Иконка канала JS Веб-гуру
73 подписчика
12+
16 просмотров
2 года назад
12+
16 просмотров
2 года назад

Do you need more help with coding? ════════════════════════════ ✅ Apply for 1-1 coaching https://form.jotform.com/230156286763056 ════════════════════════════ How to Solve "1464 Maximum Product of Two Elements in an Array" on LeetCode? Problem: #1464 Maximum Product of Two Elements in an Array Language: Javascript Difficulty: Easy Strategy: Create variable to hold max value and 2nd max value. Time Complexity: O(n) Space Complexity: O(1) Pseudo Code: 1. Create a max variable. 2. Create a max2 variable. 3. Loop through nums. a. Create condition if current index value is greater than max and max2. i. Change max2 to max ii. Change the max to current index value. b. Else if the current index value is greater than max2. i. Change max2 to the current index value. 4. Return (max -1) * (max2 -1) GitHub Repo: https://github.com/anusontarangkul/leetcode-javascript-solutions/blob/main/1464-Maximum-Product-of-Two-Elements-in-an-Array/1464.js Let's Connect ?: ════════════════════════════ LinkedIn: https://www.linkedin.com/in/anusontarangkul/ TikTok: https://www.tiktok.com/@coding_david Instagram: https://www.instagram.com/coding_david_/ GitHub: https://github.com/anusontarangkul

, чтобы оставлять комментарии