From 4c12c84346c8dfe8c28ac5f68ed587d77c14ac8a Mon Sep 17 00:00:00 2001
From: Praddyumn Shukla <spraddyumn@gmail.com>
Date: Thu, 1 Oct 2020 19:33:50 +0530
Subject: [PATCH 01/11] Create
 leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3458

C++ Solution to "Insert Interval" Problem in September Leetcoding Challenge of Week 2
---
 ...5-week-2-september-8th-september-14th-3458 | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3458

diff --git a/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3458 b/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3458
new file mode 100644
index 0000000..62cf206
--- /dev/null
+++ b/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3458
@@ -0,0 +1,24 @@
+class Solution {
+public:
+    vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
+        
+        vector<vector<int>> result;
+        int i = 0 , n = intervals.size();
+        
+        while(i < n && intervals[i][1] < newInterval[0]) result.push_back(intervals[i++]);
+        
+        vector<int> mi = newInterval;
+        while(i < n && intervals[i][0] <= newInterval[1]){
+            mi[0] = min(mi[0] , intervals[i][0]);
+            mi[1] = max(mi[1] , intervals[i++][1]);
+        }
+        
+        result.push_back(mi);
+        
+        while(i < n ) result.push_back(intervals[i++]);
+        
+        return result;
+    }
+};
+
+

From 4b8e8d24f158d099368646a4b121111f03958ae2 Mon Sep 17 00:00:00 2001
From: Praddyumn Shukla <spraddyumn@gmail.com>
Date: Thu, 1 Oct 2020 19:38:30 +0530
Subject: [PATCH 02/11] Create
 leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3456

C++ Solution to the problem "Maximum Product Subarray" of the Week 2 of the 30 days September Leetcode Challenge.
---
 ...5-week-2-september-8th-september-14th-3456 | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3456

diff --git a/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3456 b/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3456
new file mode 100644
index 0000000..bc7649a
--- /dev/null
+++ b/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3456
@@ -0,0 +1,27 @@
+class Solution {
+public:
+    int maxProduct(vector<int>& nums) {
+        
+        int prev_max_product = nums[0] , prev_min_product = nums[0];
+        int curr_max_product = nums[0] , curr_min_product = nums[0];
+        int result = nums[0];
+        
+        for(int i = 1; i < nums.size() ; i++){
+            
+            curr_max_product = max(prev_max_product*nums[i] , prev_min_product*nums[i]);
+            curr_max_product = max(curr_max_product , nums[i]);
+            
+            curr_min_product = min(prev_max_product*nums[i] , prev_min_product*nums[i]);
+            curr_min_product = min(curr_min_product , nums[i]);
+            
+            result = max(curr_max_product , result);
+            
+            prev_max_product = curr_max_product;
+            prev_min_product = curr_min_product; 
+            
+            }
+        return result;
+    }
+};
+
+

From a1f9ffff6e36bc35a979883232c95c1199d8bb81 Mon Sep 17 00:00:00 2001
From: "ishuraj2010@gmail.com" <ishuraj2010@gmail.com>
Date: Sat, 3 Oct 2020 12:56:10 +0530
Subject: [PATCH 03/11] 39

---
 39.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 39.cpp

diff --git a/39.cpp b/39.cpp
new file mode 100644
index 0000000..d1586a1
--- /dev/null
+++ b/39.cpp
@@ -0,0 +1,55 @@
+//https://leetcode.com/problems/combination-sum/
+//Difficulty Level: Medium
+//Tags: Array, Backtracking
+//since we have to print all, and not just count or max or min, we won't use DP but backtracking
+
+class Solution {
+public:
+    vector<vector<int>> combinationSum(vector<int>& candidates, int target) 
+    {
+        sort(candidates.begin(), candidates.end());
+        
+        //Note that we don't have duplicates in the array, else we had to delete the duplicates here bcoz 
+        //we can already take each element multiple times, so duplicate elements don't make a difference
+        
+        int index = candidates.size()-1;
+        while(index >=0 && candidates[index] > target)
+        {
+            index--;
+        }
+        
+        vector<int> v;
+        vector<vector<int>> res;  //stores result
+        backtrack(candidates, target, 0, index, v, res);
+        return res;
+    }
+    
+    void backtrack(vector<int> candidates, int target, int curr_sum, int index, vector<int> v, vector<vector<int>>& res)
+    {
+        if(curr_sum == target)     //if the sum of elements of v add up to target, push v to result vector
+        {
+            res.push_back(v);
+            return;
+        }
+        
+        //check all the elements <= target - curr_sum
+        for(int i=index; i>=0; i--)
+        {
+            curr_sum += candidates[i];
+            
+            if(curr_sum > target)    //don't include the element if sum is exceeding the target
+            {
+                curr_sum -= candidates[i];
+                continue;
+            }
+            v.push_back(candidates[i]);
+            
+            //backtrack to find rest of the elements of v
+            //note that we have passed 'i' and not 'i+1' since we could include the same element any no. of times
+            backtrack(candidates, target, curr_sum, i, v, res);   
+            
+            curr_sum -= candidates[i];
+            v.pop_back();
+        }
+    }
+};
\ No newline at end of file

From 36651f4eaad47fda21d850f1c8dbb02740658960 Mon Sep 17 00:00:00 2001
From: Gidijala uday srinu <55196913+udaysrinu@users.noreply.github.com>
Date: Sat, 3 Oct 2020 21:18:53 +0530
Subject: [PATCH 04/11] 84.cpp

largest area of histogram
---
 84.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)
 create mode 100644 84.cpp

diff --git a/84.cpp b/84.cpp
new file mode 100644
index 0000000..c749c38
--- /dev/null
+++ b/84.cpp
@@ -0,0 +1,124 @@
+class Solution {
+public:
+    int largestRectangleArea(vector<int>& A) {
+         int n=A.size();
+    stack<int>s;
+    vector<int>nsr;
+    for(int i=n-1;i>=0;i--)
+    {
+        if(s.empty())
+        {
+            nsr.push_back(n);
+        }
+        else if(A[s.top()]<A[i])
+        {
+            nsr.push_back(s.top());
+        }
+        else if(A[s.top()]>=A[i])
+        {
+            while(!s.empty()&&A[s.top()]>=A[i])
+            {
+                s.pop();
+            }
+            if(s.empty())
+            {
+                nsr.push_back(n);
+            }
+            else
+            nsr.push_back(s.top());
+        }
+        s.push(i);
+    }
+    reverse(nsr.begin(),nsr.end());
+    stack<int>ss;
+    vector<int>nsl;
+    for(int i=0;i<n;i++)
+    {
+        if(ss.empty())
+        {
+            nsl.push_back(-1);            
+        }
+        else if(A[ss.top()]<A[i])
+        {
+            nsl.push_back(ss.top());
+        }
+        else if(A[ss.top()]>=A[i])
+        {
+            while(!ss.empty()&&A[ss.top()]>=A[i])
+            ss.pop();
+            if(ss.empty())
+            {
+                nsl.push_back(-1);
+            }
+            else
+            nsl.push_back(ss.top());
+        }
+        ss.push(i);
+    }
+    int ans=0;
+    for(int i=0;i<n;i++)
+    {
+        ans=max(ans,(nsr[i]-nsl[i]-1)*A[i]);
+    }
+    return ans;  n=A.size();
+    stack<int>s;
+    vector<int>nsr;
+    for(int i=n-1;i>=0;i--)
+    {
+        if(s.empty())
+        {
+            nsr.push_back(n);
+        }
+        else if(A[s.top()]<A[i])
+        {
+            nsr.push_back(s.top());
+        }
+        else if(A[s.top()]>=A[i])
+        {
+            while(!s.empty()&&A[s.top()]>=A[i])
+            {
+                s.pop();
+            }
+            if(s.empty())
+            {
+                nsr.push_back(n);
+            }
+            else
+            nsr.push_back(s.top());
+        }
+        s.push(i);
+    }
+    reverse(nsr.begin(),nsr.end());
+    stack<int>ss;
+    vector<int>nsl;
+    for(int i=0;i<n;i++)
+    {
+        if(ss.empty())
+        {
+            nsl.push_back(-1);            
+        }
+        else if(A[ss.top()]<A[i])
+        {
+            nsl.push_back(ss.top());
+        }
+        else if(A[ss.top()]>=A[i])
+        {
+            while(!ss.empty()&&A[ss.top()]>=A[i])
+            ss.pop();
+            if(ss.empty())
+            {
+                nsl.push_back(-1);
+            }
+            else
+            nsl.push_back(ss.top());
+        }
+        ss.push(i);
+    }
+    int ans=0;
+    for(int i=0;i<n;i++)
+    {
+        ans=max(ans,(nsr[i]-nsl[i]-1)*A[i]);
+    }
+    return ans;
+    }
+};

From b800377b71692e331f38695ee97f15d98435ddb1 Mon Sep 17 00:00:00 2001
From: AshishKumar077 <72354811+AshishKumar077@users.noreply.github.com>
Date: Mon, 5 Oct 2020 00:04:05 +0530
Subject: [PATCH 05/11] Create 2 sum solution

---
 2 sum solution | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 2 sum solution

diff --git a/2 sum solution b/2 sum solution
new file mode 100644
index 0000000..a41c582
--- /dev/null
+++ b/2 sum solution	
@@ -0,0 +1,30 @@
+class Solution {
+public:
+    vector<int> twoSum(vector<int>& nums, int target) 
+    {
+        int size = nums.size();
+        
+        // x, target-x -> add to target.
+        
+        map<int, int> pos_map;
+        
+        for(int i=0; i<size;i++)
+        {
+            int curr_num = nums[i];
+            
+            int to_find = target-curr_num;
+            
+            if (pos_map[to_find]!=0)
+            {
+                // currnum + to_find = target
+                return vector<int>{i, pos_map[to_find]-1};
+                
+            }
+            
+            pos_map[curr_num] = i+1;
+            // done :)
+            
+        }
+        
+        return vector<int>{-1,-1};
+    }

From 1cba5895b1ab527a9417fa293cc4998f2bd7fb16 Mon Sep 17 00:00:00 2001
From: Praddyumn Shukla <spraddyumn@gmail.com>
Date: Mon, 5 Oct 2020 11:52:33 +0530
Subject: [PATCH 06/11] Create
 leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3453

c++ Solution to the question "Sum of Root To Leaf Binary Numbers" for week 2 of September 30 days Leetcode Challenge
---
 ...5-week-2-september-8th-september-14th-3453 | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3453

diff --git a/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3453 b/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3453
new file mode 100644
index 0000000..4914d53
--- /dev/null
+++ b/leetcode.com-explore-challenge-card-september-leetcoding-challenge-555-week-2-september-8th-september-14th-3453
@@ -0,0 +1,25 @@
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ *     int val;
+ *     TreeNode *left;
+ *     TreeNode *right;
+ *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+ * };
+ */
+class Solution {
+    int sum1(TreeNode* root , int sum){
+        if(!root) return 0;
+        sum = (sum << 1) + root->val;
+        if(!root->right && !root->left) return sum;
+        return sum1(root->left , sum) + sum1(root->right , sum);
+    }
+public:
+    int sumRootToLeaf(TreeNode* root) {
+        return sum1(root , 0);
+    }
+};
+
+

From 7338fffb44c85b73f02a4867d669c979b69942e1 Mon Sep 17 00:00:00 2001
From: ayushi <ayujain1109@gmail.com>
Date: Fri, 9 Oct 2020 22:07:04 +0530
Subject: [PATCH 07/11] added Median_of_two_sorted_arrays.cpp

---
 Median_of_two_sorted_arrays.cpp | 42 +++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Median_of_two_sorted_arrays.cpp

diff --git a/Median_of_two_sorted_arrays.cpp b/Median_of_two_sorted_arrays.cpp
new file mode 100644
index 0000000..0f40251
--- /dev/null
+++ b/Median_of_two_sorted_arrays.cpp
@@ -0,0 +1,42 @@
+class Solution {
+public:
+    double find(vector<int>& nums1, vector<int>& nums2)
+    {
+           int n = nums1.size(),m = nums2.size();
+     
+        int l = 0,h = n;
+        while(l<=h)
+        {
+            int part1= (l+h)/2;
+            int part2=(n+m+1)/2 - part1;
+            
+            int l1=(part1==0)? INT_MIN: nums1[part1-1];
+            int r1= (part1==n)? INT_MAX: nums1[part1];
+            int l2=(part2==0)? INT_MIN: nums2[part2-1];
+            int r2= (part2==m)? INT_MAX: nums2[part2];
+            
+            if(l1<=r2 && l2<=r1)
+            {
+                if((n+m)%2)
+                    return (double)max(l1,l2);
+                else
+                {
+                    return (double)(max(l1,l2)+ min(r1,r2))/2.0;
+                }
+            }
+            
+            else if(l1>r2)
+                h=part1-1;
+            else
+                l=part1+1;
+        }
+        return 0;
+    }
+    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
+        int n=nums1.size(),m=nums2.size();
+        if(n>m)return find(nums2,nums1);
+        else return find(nums1,nums2);
+        
+    }
+    
+};
\ No newline at end of file

From 7a1e5a771bd6ef6bddb6fa07be6371b2f9175d5f Mon Sep 17 00:00:00 2001
From: Sourav <souravrao3110@gmail.com>
Date: Wed, 14 Oct 2020 19:42:04 +0530
Subject: [PATCH 08/11]  56 Merge Intervals

---
 56.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 56.cpp

diff --git a/56.cpp b/56.cpp
new file mode 100644
index 0000000..bb016e0
--- /dev/null
+++ b/56.cpp
@@ -0,0 +1,21 @@
+class Solution {
+public:
+    vector<vector<int>> merge(vector<vector<int>>& intervals) {
+        vector<int>arr(2);
+        vector<vector<int>>ans;
+        if(intervals.size()==0) return ans;
+        sort(intervals.begin(),intervals.end());
+        arr[0]=intervals[0][0];arr[1]=intervals[0][1];
+        for(int i=1;i<intervals.size();i++)
+        {   if(arr[1]>=intervals[i][0])
+                arr[1]=max(intervals[i][1],arr[1]);
+            else
+            {   ans.push_back({arr[0],arr[1]});
+                arr[0]=intervals[i][0];
+                arr[1]=intervals[i][1];  
+            }
+        }
+        ans.push_back({arr[0],arr[1]});
+        return ans;
+    }
+};
\ No newline at end of file

From 6c4c600be5631692ebe5de3c6072aa9af2ee6bc9 Mon Sep 17 00:00:00 2001
From: Sourav <souravrao3110@gmail.com>
Date: Wed, 14 Oct 2020 19:45:13 +0530
Subject: [PATCH 09/11] 59

---
 59.cpp | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 59.cpp

diff --git a/59.cpp b/59.cpp
new file mode 100644
index 0000000..f29428d
--- /dev/null
+++ b/59.cpp
@@ -0,0 +1,35 @@
+class Solution {
+public:
+
+    vector<vector<int>> generateMatrix(int n) {
+        vector<vector<int>> matrix;
+        matrix.resize(n, std::vector<int>(n, -1));
+        
+        int top = 0;
+        int bottom = n-1;
+        int left = 0;
+        int right = n-1;
+        int val = 1;
+        while (left<=right) {
+            
+            for (int i = left;i<=right;i++) {
+                matrix[left][i] = val++;
+            }
+            top++;
+            
+            for (int i = top;i<=bottom;i++) {
+                matrix[i][right] = val++;
+            }
+            right--;
+            for (int i = right;i>=left;i--) {
+                matrix[bottom][i] = val++;
+            }
+            bottom--;
+            for (int i = bottom;i>=top;i--) {
+                matrix[i][left] = val++;
+            }
+            left++;
+        }
+        return matrix;
+    }
+};
\ No newline at end of file

From 5d60e5f688c1c13fff7b922b3858b83b8aa4295f Mon Sep 17 00:00:00 2001
From: Sourav <souravrao3110@gmail.com>
Date: Wed, 14 Oct 2020 19:48:50 +0530
Subject: [PATCH 10/11] 60

---
 60.cpp | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 60.cpp

diff --git a/60.cpp b/60.cpp
new file mode 100644
index 0000000..ed28542
--- /dev/null
+++ b/60.cpp
@@ -0,0 +1,24 @@
+class Solution {
+public:
+    string getPermutation(int n, int k) {
+        string st(n,'0');
+        int fact=1;
+        for(int i=1;i<=n;i++){
+            fact*=i;
+            st[i-1]+=(i);
+        }
+        for(int i=0;i<n;i++){
+            int block_num=fact/(n-i);
+            fact/=(n-i);
+            int first_index=i+(k-1)/(block_num);
+            char c=st[first_index];
+            k=k-(((k-1)/(block_num))*(block_num));
+            for(int j=first_index;j>=i+1;j--){
+                st[j]=st[j-1];
+            }
+            st[i]=c;
+            cout<<st<<" "<<k<<" ";
+        }
+        return st;
+    }
+};
\ No newline at end of file

From c4430cfcee5cf41b2019ea962764ef960ad4d531 Mon Sep 17 00:00:00 2001
From: Gibran <44020043+glgibran7@users.noreply.github.com>
Date: Mon, 19 Oct 2020 21:32:29 +0800
Subject: [PATCH 11/11] Create 12321.cpp

---
 12321.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 12321.cpp

diff --git a/12321.cpp b/12321.cpp
new file mode 100644
index 0000000..ec322b4
--- /dev/null
+++ b/12321.cpp
@@ -0,0 +1,51 @@
+#include <iostream.h>
+
+#include <conio.h>
+
+int volume(int &l){
+
+int t;
+
+cout<<“masukan nilai t :”;
+
+cin>>t;
+
+l =l*t;
+
+return l;
+
+}
+
+int luas(int p, int l)  {
+
+int x;
+
+x=p*l;
+
+cout<<“tampilkan nilai luas :”<<x<<endl;
+
+volume(x);
+
+return x;
+
+}
+
+void main (){
+
+int p,l,j;
+
+cout<<“masukan nilai p :”;
+
+cin>>p;
+
+cout<<“masukan nilai l :”;
+
+cin>>l;
+
+j=luas(p,l);
+
+cout<<“volume balok adalah : “<<j<<endl;
+
+getch();
+
+}