Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Kth Largest Element in an Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public:
int findKthLargest(vector<int>& nums, int k) {

int z=nums.size();int c=0,i=0;
sort(nums.begin(), nums.end(), greater<int>());
int a=nums[k-1];
return a;
}
};
29 changes: 29 additions & 0 deletions Plus One.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {

int n=digits.size();
vector<int>kbc;
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;

}
};
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions README1.md
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions README2.md
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions Running Sum of 1d Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
vector<int> runningSum(vector<int>& nums) {

int s=0;

for(int i=0;i<nums.size();i++)
{

s=s+nums[i];
nums[i]=s;
}
return nums;

}
};
36 changes: 36 additions & 0 deletions Subtract the Product and Sum of Digits of an Integer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Solution {
public:
int subtractProductAndSum(int n) {

int m,s=1,z,a,s1=0;
m=n;
a=n;
while(m!=0)
{
int k=m%10;
s=s*k;
m=m/10;

}
while(a!=0)
{
z=a%10;
s1=s1+z;
a=a/10;
}
int res=s-s1;
return res;

}
int main()
{
int n;
cin>>n;
int a= subtractProductAndSum(n);
cout<<a<<endl;
return 0;



}
};