-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_61.cpp
90 lines (70 loc) · 1.8 KB
/
day_61.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Name - Himanshu Pokhriyal
Date - 25 May , 2024
Version - C++ 17
Ques-1 Kefa and First Steps
Rating - 900
Link - https://codeforces.com/problemset/problem/580/A
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
int curr_length=1,ans=INT_MIN; // Initialize vector with size n
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
// sort(arr.begin(), arr.end());
for (int i = 1; i < n; ++i) {
if( arr[i] >= arr[i-1]){
curr_length++;
}
else{
ans=max(ans,curr_length);
curr_length=1;
}
}
ans=max(ans,curr_length);
cout<<ans<<endl;
return 0;
}
Time complexity - O(n)
Space complexity - O(n)
Ques-2 Dubstep
Rating -900
Link - https://codeforces.com/problemset/problem/208/A
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
// Replace all "WUB" with spaces
string wub = "WUB";
size_t pos = 0;
while ((pos = s.find(wub, pos)) != string::npos) {
s.replace(pos, wub.length(), " ");
pos += 1; // Move past this position
}
// Now we have the string with possible multiple spaces, let's clean them up
string result;
bool inWord = false;
for (char ch : s) {
if (ch != ' ') {
result += ch;
inWord = true;
} else if (inWord) {
result += ' ';
inWord = false;
}
}
// Remove trailing space if any
if (!result.empty() && result.back() == ' ') {
result.pop_back();
}
cout << result << endl;
return 0;
}
Time complexity - O(n)
Space complexity - O(n) ## n here is size of string
*/