Skip to content

Commit 8e45f0f

Browse files
committed
Add complete support (rough-untested) for Java and C++
1 parent e80ab20 commit 8e45f0f

File tree

156 files changed

+4170
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+4170
-4
lines changed

src/code/cpp/array/prefix_sum.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
7+
vector<int> fn(vector<int>& arr) {
8+
int n = arr.size();
9+
vector<int> prefix;
10+
prefix.push_back(arr[0]);
11+
12+
for (int i = 1; i < n; ++i) {
13+
prefix.push_back(prefix.back() + arr[i]);
14+
}
15+
16+
return prefix;
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
int fn(vector<int>& arr) {
7+
int n = arr.size();
8+
int window = 0;
9+
int left = 0;
10+
int ans = 0;
11+
12+
for (int right = 0; right < n; right++) {
13+
// TODO: add arr[right] to window
14+
window += arr[right];
15+
16+
while (WINDOW_CONDITION_BROKEN) {
17+
// TODO: remove arr[left] from window
18+
window -= arr[left];
19+
left += 1;
20+
}
21+
22+
// TODO: update ans
23+
}
24+
25+
return ans;
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
string fn(vector<char>& arr) {
2+
return string(arr.begin(), arr.end())
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
int fn(vector<int>& arr) {
7+
int ans = 0;
8+
int left = 0;
9+
int right = arr.size() - 1;
10+
11+
while (left < right) {
12+
// TODO: logic with left and right
13+
if (CONDITION) {
14+
left += 1;
15+
} else {
16+
right -= 1;
17+
}
18+
}
19+
20+
return ans;
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
int fn(vector<int>& arr1, vector<int>& arr2) {
7+
int i = 0;
8+
int j = 0;
9+
int ans = 0;
10+
11+
while (i < arr1.size() && j < arr2.size()) {
12+
// TODO: logic
13+
if (CONDITION) {
14+
i += 1;
15+
} else {
16+
j += 1;
17+
}
18+
}
19+
20+
while (i < arr1.size()) {
21+
// TODO: logic
22+
i += 1;
23+
}
24+
25+
while (j < arr2.size()) {
26+
// TODO: logic
27+
j += 1;
28+
}
29+
30+
return ans;
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
int backtrack(int curr, OTHER_ARGUMENTS...) {
2+
if (BASE_CASE) {
3+
// TODO: modify answer
4+
return 0;
5+
}
6+
7+
int ans = 0;
8+
9+
for (ITERATE_OVER_INPUT) {
10+
// TODO: modify current state
11+
ans += backtrack(curr, OTHER_ARGUMENTS...);
12+
// TODO: undo modification of current state
13+
}
14+
15+
return ans;
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
int fn(vector<int>& arr, int target) {
7+
int left = 0;
8+
int right = arr.size() - 1;
9+
10+
while (left <= right) {
11+
int mid = left + (right - left) / 2;
12+
13+
if (arr[mid] == target) {
14+
// TODO: logic
15+
return;
16+
}
17+
if (arr[mid] > target) {
18+
right = mid - 1;
19+
} else {
20+
left = mid + 1;
21+
}
22+
}
23+
24+
return left;
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
int fn(vector<int>& arr, int target) {
7+
int left = 0;
8+
int right = arr.size();
9+
10+
while (left < right) {
11+
int mid = left + (right - left) / 2;
12+
13+
if (arr[mid] >= target) {
14+
right = mid;
15+
} else {
16+
left = mid + 1;
17+
}
18+
}
19+
20+
return left;
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
int fn(vector<int>& arr, int target) {
7+
int left = 0;
8+
int right = arr.size();
9+
10+
while (left < right) {
11+
int mid = left + (right - left) / 2;
12+
13+
if (arr[mid] > target) {
14+
right = mid;
15+
} else {
16+
left = mid + 1;
17+
}
18+
}
19+
20+
return left;
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <vector>
2+
3+
using namespace std;
4+
5+
6+
bool check(int x) {
7+
return BOOLEAN;
8+
}
9+
10+
int fn(vector<int>& arr) {
11+
int left = MINIMUM_POSSIBLE_ANSWER;
12+
int right = MAXIMUM_POSSIBLE_ANSWER;
13+
14+
while (left <= right) {
15+
int mid = left + (right - left) / 2;
16+
17+
if (check(mid)) {
18+
left = mid + 1;
19+
} else {
20+
right = mid - 1;
21+
}
22+
}
23+
24+
return right;
25+
}

0 commit comments

Comments
 (0)