From ede698164ebddd505db2260e7dfe3f4475b5a378 Mon Sep 17 00:00:00 2001 From: Aniket Tripathy <114935649+heisenberg070@users.noreply.github.com> Date: Tue, 4 Oct 2022 19:46:31 +0530 Subject: [PATCH 1/2] added product finder solution --- .../C++/Aniket_Tripathy/PRODUCT_FINDER.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 coding_freshmen/C++/Aniket_Tripathy/PRODUCT_FINDER.cpp diff --git a/coding_freshmen/C++/Aniket_Tripathy/PRODUCT_FINDER.cpp b/coding_freshmen/C++/Aniket_Tripathy/PRODUCT_FINDER.cpp new file mode 100644 index 0000000..da18cb2 --- /dev/null +++ b/coding_freshmen/C++/Aniket_Tripathy/PRODUCT_FINDER.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + + +int main(){ + int n; + cin>>n; + int arr[n]; + for(int i=0;i> arr[i]; + } + int pivot; + cin >> pivot; + int prod = 1; + + //edge case + if(pivot==0){ + for (int i = 0; i < n;i++){ + if(arr[i]==0){ + continue; + }else{ + prod *= arr[i]; + } + } + cout << prod << endl; + exit(0); + } + + //normal case + for(int i=0;i Date: Tue, 4 Oct 2022 19:52:44 +0530 Subject: [PATCH 2/2] added readme --- coding_freshmen/C++/Aniket_Tripathy/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 coding_freshmen/C++/Aniket_Tripathy/README.md diff --git a/coding_freshmen/C++/Aniket_Tripathy/README.md b/coding_freshmen/C++/Aniket_Tripathy/README.md new file mode 100644 index 0000000..eeadb8f --- /dev/null +++ b/coding_freshmen/C++/Aniket_Tripathy/README.md @@ -0,0 +1,12 @@ +# Problem Title: PRODUCT_FINDER + Find the product of the elements of the array except the given pivot element + +# Problem Explanation 🚀 +We need to find the product of all elements of the array while skipping the pivot element + +# Intuition and Logic🧠 +* Assuming that all the elements in the array are unique we can simply calculate the products of all the elements in a prod variable, and when we encounter the pivot element we can simply use the continue; statememt to skip that element. + +# Time Complexity and Space Complexity +* Time Complexity: O(n) +* Space Complexity: O(1)