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
38 changes: 38 additions & 0 deletions dash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
string s = "5F3Z-2e-9-w";
int k = 4;

string temp = "";


for (char c : s) {
if (c != '-') {
temp += toupper(c);
}
}


string result = "";
int count = 0;

for (int i = temp.size() - 1; i >= 0; i--) {
result.push_back(temp[i]);
count++;

if (count == k && i != 0) {
result.push_back('-');
count = 0;
}
}


reverse(result.begin(), result.end());


cout << result << endl;

return 0;
}
30 changes: 30 additions & 0 deletions subbstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <vector>
#include <string>
using namespace std;

class Solution {
public:
int countBinarySubstrings(string s) {
vector<int> groups;
int count = 1;

// Step 1: Count consecutive groups
for (int i = 1; i < s.size(); i++) {
if (s[i] != s[i - 1]) {
groups.push_back(count);
count = 1;
} else {
count++;
}
}
groups.push_back(count);

// Step 2: Count valid substrings
int result = 0;
for (int i = 1; i < groups.size(); i++) {
result += min(groups[i - 1], groups[i]);
}

return result;
}
};
27 changes: 27 additions & 0 deletions water.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
vector<int> height = {1,8,6,2,5,4,8,3,7};

int maxWater = 0;
int left = 0;
int right = height.size() - 1;

while (left < right) {
int h = min(height[left], height[right]);
int w = right - left;
int area = h * w;
maxWater = max(maxWater, area);

if (height[left] < height[right]) {
left++;
} else {
right--;
}
}

cout << "Maximum Water: " << maxWater << endl;

return 0;
}