Skip to content

Commit 2d0125a

Browse files
Merge pull request #15 from mairohanhoon/main
ADDED DAILY Problems of 9th October 2023
2 parents 7361cc4 + f13033f commit 2d0125a

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// Function to calculate minimum cost.
5+
long long minimumCost(vector<int> &cost, int n, int k)
6+
{
7+
// Write your code here.
8+
long long count = 0;
9+
int x = n-1;
10+
sort(cost.begin(), cost.end());
11+
for(int i=0; i<=x; i++){
12+
count+=cost[i];
13+
x = x-k;
14+
}
15+
return count;
16+
}
17+
18+
// Function to calculate maximum cost.
19+
long long maximumCost(vector<int> &cost, int n, int k)
20+
{
21+
// Write your code here.
22+
long long count = 0;
23+
int x = n-1;
24+
sort(cost.begin(), cost.end());
25+
reverse(cost.begin(), cost.end());
26+
for(int i=0; i<=x; i++){
27+
count+=cost[i];
28+
x=x-k;
29+
}
30+
return count;
31+
}
32+
33+
int main(){
34+
35+
int n = 5;
36+
int k = 2;
37+
vector<int> cost = {9, 8, 2, 6, 4};
38+
39+
cout << minimumCost(cost, n, k) << " " << maximumCost(cost, n, k) << endl;
40+
41+
return 0;
42+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void pushZerosAtEnd(vector<int> &arr)
5+
{
6+
// Write your code here.
7+
int count = 0;
8+
vector<int> res;
9+
for(int i=0; i<arr.size(); i++){
10+
if(arr[i] == 0){
11+
count++;
12+
}
13+
else{
14+
res.push_back(arr[i]);
15+
}
16+
}
17+
while(count--){
18+
res.push_back(0);
19+
}
20+
arr = res;
21+
}
22+
23+
int main(){
24+
25+
vector<int> arr = {2, 0, 4, 1, 3, 0, 28};
26+
pushZerosAtEnd(arr);
27+
28+
for(int i=0; i<arr.size(); i++){
29+
cout << arr[i] << " ";
30+
}
31+
32+
return 0;
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<int> rowWaveForm(vector<vector<int>> &mat) {
5+
// Write your code here.
6+
vector<int> res;
7+
for(int i=0; i<mat.size(); i++){
8+
if(i%2 == 0){
9+
for(int j=0; j<mat[0].size(); j++){
10+
res.push_back(mat[i][j]);
11+
}
12+
}
13+
else{
14+
for(int j=mat[0].size()-1; j>=0; j--){
15+
res.push_back(mat[i][j]);
16+
}
17+
}
18+
}
19+
return res;
20+
}
21+
22+
int main(){
23+
24+
vector<vector<int>> mat = {{1,2}, {0,5}};
25+
vector<int> res = rowWaveForm(mat);
26+
27+
for(int i=0; i<res.size(); i++){
28+
cout << res[i] << " ";
29+
}
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)