diff --git a/Kth Largest Element in an Array.cpp b/Kth Largest Element in an Array.cpp new file mode 100644 index 0000000..043af1a --- /dev/null +++ b/Kth Largest Element in an Array.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + int findKthLargest(vector& nums, int k) { + + int z=nums.size();int c=0,i=0; + sort(nums.begin(), nums.end(), greater()); + int a=nums[k-1]; + return a; + } + }; \ No newline at end of file diff --git a/Plus One.cpp b/Plus One.cpp new file mode 100644 index 0000000..726b439 --- /dev/null +++ b/Plus One.cpp @@ -0,0 +1,29 @@ +class Solution { +public: + vector plusOne(vector& digits) { + + int n=digits.size(); + vectorkbc; + int c=1; + + for(int i=n-1; i>=0; i--) + { + + if(digits[i]==9 && c==1) + kbc.push_back(0); + + + else kbc.push_back(digits[i]+c), + c=0; + + } + + + if(c==1) + kbc.push_back(c); + + reverse(kbc.begin(), kbc.end()); + return kbc; + + } +}; diff --git a/README.md b/README.md index 06b8eca..b09343f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,27 @@ -We are building a dataset of all Data-Structure and algorithm questions to be accessed later via APIs for our webapp backend. - -Please help us contribute. - -This dataset would be free to use for all. - +Given an integer number n, return the difference between the product of its digits and the sum of its digits. + + + +Example 1: + +Input: n = 234 +Output: 15 +Explanation: +Product of digits = 2 * 3 * 4 = 24 +Sum of digits = 2 + 3 + 4 = 9 +Result = 24 - 9 = 15 + +Example 2: + +Input: n = 4421 +Output: 21 +Explanation: +Product of digits = 4 * 4 * 2 * 1 = 32 +Sum of digits = 4 + 4 + 2 + 1 = 11 +Result = 32 - 11 = 21 + + + +Constraints: + + 1 <= n <= 10^5 diff --git a/README1.md b/README1.md new file mode 100644 index 0000000..2c4445d --- /dev/null +++ b/README1.md @@ -0,0 +1,29 @@ +Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). + +Return the running sum of nums. + + + +Example 1: + +Input: nums = [1,2,3,4] +Output: [1,3,6,10] +Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. + +Example 2: + +Input: nums = [1,1,1,1,1] +Output: [1,2,3,4,5] +Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1]. + +Example 3: + +Input: nums = [3,1,2,10,1] +Output: [3,4,6,16,17] + + + +Constraints: + + 1 <= nums.length <= 1000 + -10^6 <= nums[i] <= 10^6 diff --git a/README2.md b/README2.md new file mode 100644 index 0000000..1d2d1b1 --- /dev/null +++ b/README2.md @@ -0,0 +1,25 @@ +Given an integer array nums and an integer k, return the kth largest element in the array. + +Note that it is the kth largest element in the sorted order, not the kth distinct element. + +You must solve it in O(n) time complexity. + + + +Example 1: + +Input: nums = [3,2,1,5,6,4], k = 2 +Output: 5 + +Example 2: + +Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 +Output: 4 + + + +Constraints: + + 1 <= k <= nums.length <= 105 + -104 <= nums[i] <= 104 + diff --git a/Running Sum of 1d Array.cpp b/Running Sum of 1d Array.cpp new file mode 100644 index 0000000..03d3301 --- /dev/null +++ b/Running Sum of 1d Array.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + vector runningSum(vector& nums) { + + int s=0; + + for(int i=0;i>n; + int a= subtractProductAndSum(n); + cout<