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

Array - 24: Check if multiplication of any two number matches to given value

Source Code:https://thecodingsimplified.com/check-if-multiplication-of-any-two-number-matches-to-given-value/ Solution - 1: Using two for loop - check with every number with other number if multiplication of two number matches to given value Time Complexity: O(n^2) Space Complexity: O(1) Solution - 2: Using Sorting - Sort the array - Now take two pointer from start & end - If multiplication of start & end index value is greater than given value decrease the end index by 1 - If multiplication of start & end index value is less than given value increase the start index by 1 - If multiplication of start & end index value is equal to given value return true Time Complexity: O(nlogn) Space Complexity: O(1) Solution - 3: Using HashSet - We initialize hashset - Traverse array & if val/a[i] doesn't exist in hashset, insert a[i] value in hashset - if val/a[i] exists in hashset then there exists a pair Time Complexity: O(n) Space Complexity: O(n) Do Watch video for more info CHECK OUT CODING SIMPLIFIED https://www.youtube.com/codingsimplified ★☆★ VIEW THE BLOG POST: ★☆★ http://thecodingsimplified.com I started my YouTube channel, Coding Simplified, during Dec of 2015. Since then, I've published over 400+ videos. ★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★ https://www.youtube.com/codingsimplified?sub_confirmation=1 ★☆★ Send us mail at: ★☆★ Email: thecodingsimplified@gmail.com

12+
16 просмотров
2 года назад
12+
16 просмотров
2 года назад

Source Code:https://thecodingsimplified.com/check-if-multiplication-of-any-two-number-matches-to-given-value/ Solution - 1: Using two for loop - check with every number with other number if multiplication of two number matches to given value Time Complexity: O(n^2) Space Complexity: O(1) Solution - 2: Using Sorting - Sort the array - Now take two pointer from start & end - If multiplication of start & end index value is greater than given value decrease the end index by 1 - If multiplication of start & end index value is less than given value increase the start index by 1 - If multiplication of start & end index value is equal to given value return true Time Complexity: O(nlogn) Space Complexity: O(1) Solution - 3: Using HashSet - We initialize hashset - Traverse array & if val/a[i] doesn't exist in hashset, insert a[i] value in hashset - if val/a[i] exists in hashset then there exists a pair Time Complexity: O(n) Space Complexity: O(n) Do Watch video for more info CHECK OUT CODING SIMPLIFIED https://www.youtube.com/codingsimplified ★☆★ VIEW THE BLOG POST: ★☆★ http://thecodingsimplified.com I started my YouTube channel, Coding Simplified, during Dec of 2015. Since then, I've published over 400+ videos. ★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★ https://www.youtube.com/codingsimplified?sub_confirmation=1 ★☆★ Send us mail at: ★☆★ Email: thecodingsimplified@gmail.com

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