Phitron Problem Solving Notes Basic Data Structures
Phitron Problem Solving Notes Basic Data Structures
Python Documentation
Python Docs
Installation Files
Python Installation Guideline
Python : [Link]
VS Code: [Link]
1. Python
2. Jupyter
1. Jupyter
2. Ipykernel
Temp1
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
long long n;
cin >> n;
mx = a[0] + a[n-1];
}
// sort([Link](),[Link]());
cout<<max(mx,sum)<<"\n";
return 0;
}
💥 Problem Solving Club
AtCoder Tags
Lecture 1
[Link]
ios_base::sync_with_stdio(false);
[Link](NULL);
START 200
[Link]
Rating-CC-1133
Solve 1
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int len = n;
string s = "abc", res;
while(n--){
res += s;
}
cout<<[Link](0, len)<<endl;
}
}
✅ 1. What does f(S) mean?
In math and in programming problems,
f( ) is just a function notation.
So:
Examples:
○ So f("abba") = 4
This means the string must not contain too many unique palindromes.
❗ Key Observation
If we pick a string like "aaaaa...", it creates HUGE numbers of palindromes.
abcabcabcabc...
So f(S) = 3 basically.
Breakdown:
abcabcabcabcabc...
🎉 Final Summary
● f(S) = number of distinct palindromic substrings.
● Want f(S) ≤ 5.
[Link]
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int g = 0;
Solve
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
From numbers:
1, 2, 3, ..., n
gcd(a, b)
Pairs:
● (1,2) → gcd = 1
● (1,3) → gcd = 1
● (2,3) → gcd = 1
✅ Maximum = 1
Case: n = 4
Pairs:
● (2,4) → gcd = 2 ✅
● (3,4) → gcd = 1
● (1,4) → gcd = 1
✅ Maximum = 2
Case: n = 5
Pairs:
● (2,4) → gcd = 2
✅ Maximum = 2
Case: n = 6
Pairs:
● (3,6) → gcd = 3 ✅
● (2,4) → gcd = 2
● (4,6) → gcd = 2
✅ Maximum = 3
Case: n = 7
Pairs:
● (3,6) → gcd = 3
● (4,6) → gcd = 2
● (5,7) → gcd = 1
✅ Maximum = 3
Case: n = 8
Pairs:
● (4,8) → gcd = 4 ✅
● (3,6) → gcd = 3
● (2,6) → gcd = 2
✅ Maximum = 4
n answe
r
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
That means:
●
(g, 2g)
Example:
● gcd = 3 → (3,6)
● gcd = 4 → (4,8)
● gcd = 5 → (5,10)
2g ≤ n
Which means:
g ≤ n / 2
Take:
g = floor(n / 2)
Then choose:
a = g
b = 2g
Example:
● n = 7 → g = 3 → (3,6)
● n = 10 → g = 5 → (5,10)
gcd(g, 2g) = g
Example: n = 10
● Try gcd = 6
🧠 Human conclusion
● The best gcd always comes from a number and its double
●
●
print n / 2
[Link]
Solve
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
// this block of code does the magic of storing the last index of
the array elements ,here the values are used as indices and their indices
are stored in their value location
//************************************ */
idx[x] = i;
}
//*********************************** */
int mx = 0;
if (idx[y] == -1)
{
continue;
}
if(__gcd(x,y) == 1)
{
if (mx == 0)
{
cout << -1 << "\n";
}
else
{
cout << mx << "\n";
}
}
return 0;
}
We are given:
● an array a of length n
Example:
[1, 3, 5, 2, 4, 7, 7]
index:1 2 3 4 5 6 7
● index 7 → value = 7
● index 6 → value = 7
● index 5 → value = 4
💡 Observation:
We don’t care about all indices — we care about the
largest index where a value appears.
1 ≤ ai ≤ 1000
This is HUGE.
That means:
Array: [1,3,5,2,4,7,7]
1 → 1
2 → 4
3 → 2
4 → 5
5 → 3
7 → 7
Example:
x y g indi su
c ces m
d
✅
7 4 1 7+ 12
5
7 2 1 7+ 11
4
5 4 1 3+ 8
5
3 2 1 2+ 6
4
Maximum = 12
i = j
So if a value is:
Then:
answer = k + k = 2k
[Link]
Subset GCD problem Solution | Starters 118 | Explanation + Live Coding (C++)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin>>t;
while (t--)
{
int n,k;
cin>>n>>k;
int a = n/k;
// cout<<a<<"\n";
cout<<i*a<<" ";
}
cout<<"\n";
}
return 0;
}
🤕 LCM Problems
Week-06
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
Solve 1
#include <bits/stdc++.h>
using namespace std;
// CF-*800
int main()
{
int t;
cin >> t;
while (t--)
{
long long l, r;
long long x = l;
long long y = l * 2;
if (y <= r)
{
cout << x << " " << y << "\n";
}
else
{
cout << -1 << " " << -1 << "\n";
}
}
return 0;
}
Solve 2
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--) {
long long l, r;
cin >> l >> r;
return 0;
}
Problem in plain words
You’re given a range [l, r].
You must pick two different numbers inside this range such that:
l = 10, r = 40
x y LCM(x,y)
10 15 30
10 18 90 ❌
12 18 36
15 20 60 ❌
You’ll notice something:
x y divides? LCM
10 20 10 divides 20 20
12 24 12 divides 24 24
7 14 7 divides 14 14
x = 6, y = 10
● LCM(6,10) = 30
(6, 30)
Check:
● 6 divides 30 ✅
● LCM(6, 30) = 30
x divides y
l = 7, r = 50
14 = 2 × 7
x = 7
y = 14
LCM = 14
l = 30, r = 50
2 × 30 = 60 ❌ (outside range)
Other multiples?
All worse ❌
So no solution exists.
🧠 NOW translate back to symbols (after
understanding)
Human idea Math version
x divides y `x
Smallest multiple 2x
Check if possible 2l ≤ r
● 2 × 13 = 26 ❌
● No valid pair
Input:
l = 13, r = 30
● 2 × 13 = 26 ✅
● Output: 13 26
😬 Tow Pointer Problems
C. Prepend and Append
Solve 1
#include <bits/stdc++.h>
using namespace std;
// [Link]
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s;
cin >> s;
int l = 0, r = n - 1;
bool flag = true;
while (l <= r)
{
if (s[l] == '1' && s[r] == '1' || s[l] == '0' && s[r] == '0')
{
flag = false;
break;
}
else
{
l++;
r--;
}
}
int ans = 0;
if (!flag)
{
ans = n - (l*2);
// cout << "size of the given string was : " << n << "\n";
cout << ans << "\n";
}
else
{
// cout << "size of the given string was : " << n << "\n";
Solve 2
B. Number of Smaller
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
[Link](NULL);
int n;
cin>>n;
map<int,int> last_index;
long long int ans = 0;
for (int j = 1, i = 1; j <= n; j++)
{
int x;
cin>> x;
i = max(i,last_index[x] + 1);
last_index[x] = j;
cout<<ans<<"\n";
return 0;
}
Distinct Values Subarrays II
Variable Size Sliding Window
[Link]
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
[Link](nullptr);
long long n, s;
if (!(cin >> n >> s)) return 0;
vector<long long> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
// Brute force: try every starting index l and every ending index r >=
l
for (int l = 0; l < n; ++l) {
long long sum = 0;
for (int r = l; r < n; ++r) {
sum += a[r];
if (sum <= s) {
long long len = r - l + 1;
if (len > best) best = len;
}
// optional early break: if sum already > s and all a[i] are
positive,
// further extending r will only increase sum, so we could
break.
// But since this is a brute-force demonstration, leaving it
is fine.
// if (sum > s) break;
}
}
Dry Run
Perfect 👍 Let’s dry-run the brute-force code step-by-step on the sample input:
n = 7, s = 20
a = [2, 6, 4, 3, 6, 8, 9]
Goal
🧩 Outer loop: l = 0
We start from index 0 (a[0] = 2).
0 [2] 2 ✅ yes 1 1
1 [2,6] 8 ✅ yes 2 2
2 [2,6,4] 12 ✅ yes 3 3
3 [2,6,4,3] 15 ✅ yes 4 4
4 [2,6,4,3,6] 21 ❌ no - 4
5 [2,6,4,3,6,8] >21 ❌ - 4
6 [2,6,4,3,6,8,9] >21 ❌ - 4
→ For l=0, the best segment ends at r=3 (sum = 15, len = 4).
🧩 Outer loop: l = 1
We start from index 1 (a[1] = 6).
1 [6] 6 ✅ 1 4
2 [6,4] 10 ✅ 2 4
3 [6,4,3] 13 ✅ 3 4
4 [6,4,3,6] 19 ✅ 4 4
5 [6,4,3,6,8] 27 ❌ - 4
🧩 Outer loop: l = 2
Start at a[2] = 4.
2 [4] 4 ✅ 1 4
3 [4,3] 7 ✅ 2 4
4 [4,3,6] 13 ✅ 3 4
5 [4,3,6,8] 21 ❌ - 4
Still best = 4.
🧩 Outer loop: l = 3
Start at a[3] = 3.
3 [3] 3 ✅ 1 4
4 [3,6] 9 ✅ 2 4
5 [3,6,8] 17 ✅ 3 4
6 [3,6,8,9] 26 ❌ - 4
Still best = 4.
🧩 Outer loop: l = 4
r Segmen Sum <=20? Length bes
t t
4 [6] 6 ✅ 1 4
5 [6,8] 14 ✅ 2 4
6 [6,8,9] 23 ❌ - 4
🧩 Outer loop: l = 5
r Segmen Sum <=20? Length bes
t t
5 [8] 8 ✅ 1 4
6 [8,9] 17 ✅ 2 4
🧩 Outer loop: l = 6
r Segmen Sum <=20? Length bes
t t
6 [9] 9 ✅ 1 4
✅ Final Answer: 4
💡 Explanation
The longest “good” segment is any of these (all length = 4):
● [2, 6, 4, 3]
● [6, 4, 3, 6]
int n = [Link]();
int l = 0, r = 0, ans = -1;
map<char,int> cnt;
while(r<n)
{
cnt[s[r]]++;
if([Link]() == k)
{
ans = max(ans,r-l+1);
}
else
{
while([Link]() > k && l <= r)
{
cnt[s[l]]--;
if(cnt[s[l]] == 0)
{
[Link](s[l]);
}
l++;
}
}
r++;
}
return ans;
🙏 Contests-Upsolve
Speed Contest 4
C
[Link]
[Link]
Solve 1
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
int one=0,zero=0;
for (int i = 0; i < n; i++)
{
one+=arr[i]==1;
zero+=arr[i]==0;
}
cout << (zero%2==0 ? "YES" : "NO") << "\n";
int main() {
ios::sync_with_stdio(false);
[Link](NULL);
return 0;
}
Solve 2
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](NULL);
return 0;
}
CodeShef
Contests Page
[Link]
START 200
[Link]
Rating-CC-1133
Solve 1
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int len = n;
string s = "abc", res;
while(n--){
res += s;
}
cout<<[Link](0, len)<<endl;
}
Explanation
abcabcabcabc...
● "b"
● "c"
Which is ≤ 5.
Therefore: ANY length N substring of "abcabcabc…" is good.
abcabcabcabc...
Then:
● Any prefix of it (any length ≤ 100) still has only 3 palindromic substrings.
Solve 2
START207
[Link]
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s;
cin >> s;
// int l = 0 , r = n-1;
int cnt0 = 0;
}
for (int i = n-1; i >= 0; i--)
{
if (right_1 == false && s[i] == '1')
{
right_1 = true;
right_1_idx = i;
}
}
if (left_1_idx == -1)
{
cout << 0 << "\n";
continue;
}
else
{
for (int i = left_1_idx; i < right_1_idx; i++)
{
if (s[i] == '0')
{
cnt0++;
}
}
return 0;
}
[Link]
START208 Div-4
[Link]
#include <bits/stdc++.h>
using namespace std;
// START-208-Div-4-C
// Sabotage-CC-984
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
int n, x, k;
cin >> n >> x >> k;
vector<int> v(n);
int r = 1;
sort([Link](), [Link]());
[Link]
#include <bits/stdc++.h>
using namespace std;
// START-208-Div-4-D
// GCND-CC-1477
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int> a(n);
set<int> st;
if([Link]() == 1)
{
cout<<*([Link]()) - 1<<"\n";
}
else if([Link]() > 2)
{
cout<<*([Link]()) -1<<"\n";
}
else
{
int mx = *([Link]());
int mn = *([Link]());
return 0;
}
START 209
C. Small GCD
[Link]
#include <bits/stdc++.h>
using namespace std;
}
return [Link] < [Link]; // when score is equal making the player
with the lower number position first in the sort
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
players.push_back({score,i});
}
return 0;
}
[Link]
[Link]
START213
Div-4
[Link]
[Link]
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin>>t;
while (t--)
{
int n,x;
cin>>n>>x;
vector<int> a(n);
sort([Link](),[Link]());
int l = 0 ;
while(l+1<n)
{
if(a[l] < x && a[l+1] > x || a[l] > x && a[l+1] < x )
{
noflag = true;
break;
}
l++;
if(noflag)
{
cout<<"No"<<"\n";
}
else
{
cout<<"Yes"<<"\n";
}
}
return 0;
}
START215
[Link]
D
START 218
[Link]
Solve
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;cin>>t;
while(t--)
{
int n;cin>>n;
vector<int> a(n+1),c(n+1);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
cin>>c[i];
}
ll sum=0;
int cnt=INT_MAX;
for(int i=1;i<=n;i++)
{
if(c[i]<cnt)
{
cnt=c[i];
}
sum+= (a[i]*cnt);
cout<<sum<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
[Link](NULL);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
Explanation
○ A gets reindexed
○ C stays fixed
Why?
Because:
● Once a small C appears, you can keep deleting elements using that same small cost
So for position i:
“As I go from left to right, I keep track of the smallest cost seen so far,
and I multiply the current A[i] by that smallest cost.”
That’s it.
That’s the greedy strategy.
Step-by-step
i a[i] c[i] cnt = min so far cost
added
1 4 2 2 4×2=8
2 2 1 1 2×1=2
Total = 10 ✅
🧪 Dry run — Sample 2
Input
A = [4, 2]
C = [1, 2]
1 4 1 1 4×1=4
2 2 2 1 2×1=2
Total = 6 ✅
Why does 2 get multiplied by 1?
Because after deleting the first element, the remaining element shifts to index 1.
i cnt adde
d
1 10 10
2 4 4
3 4 4
4 4 4
5 3 3
Total = 25 ✅
🧠 Why this greedy is ALWAYS optimal
Think in reverse:
● So every element should be charged with the minimum cost available before it
🎯 Final verdict
✅ Your solution is correct
✅ Time complexity: O(N)
✅ Space: O(1) extra
✅ Much cleaner than simulation
✅ Exactly what the problem wants
This is contest-level greedy thinking, not beginner stuff.
Speed Contest 5
A
Solve 1
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios::sync_with_stdio(false); \
[Link](nullptr);
#define ll long long
#define haa cout << "Yes\n";
#define naa cout << "No\n";
#define endl cout << "\n";
#define nl "\n"
void solve()
{
int x, y;
cin >> x >> y;
int gap = x - 1;
int k = y / gap;
cout << k << nl;
}
int main()
{
fast;
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Solve 2
int main()
{
khela_hobe;
barbar_sudhu_amar_uporei_KENOO
{
ll n;
cin >> n;
vector<ll> a(n);
ll res = 0;
sort([Link](), [Link]());
ll counter = 0;
for (ll i = 0; i < n; i++)
{
// cout << a[i] << "-" << counter << br;
res += abs(a[i] - counter);
counter++;
}
Solve 3
// D
#include <bits/stdc++.h>
using namespace std;
void solve() {
int x, y;
cin >> x >> y;
cout << y / (x - 1) << nl;
}
int main() {
ios::sync_with_stdio(false);
[Link](nullptr);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
E
Solve 1
// gcd lcm
#include <bits/stdc++.h>
using namespace std;
ll lcm(ll a, ll b) {
return (a / __gcd(a, b)) * b;
}
void solve() {
ll x, y, k;
cin >> x >> y >> k;
while (k--) {
if (x == y)
break;
if (x > y) {
x = __gcd(x, y);
y = lcm(x, y);
} else {
y = __gcd(x, y);
x = lcm(x, y);
}
}
cout << x + y << nl;
}
int main() {
ios::sync_with_stdio(false);
[Link](nullptr);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
CodeForces Div-3
Dashboard - Codeforces Round 1072 (Div. 3)
😐 Binary String Problems
C. Prepend and Append
#include <bits/stdc++.h>
using namespace std;
// [Link]
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s;
cin >> s;
int l = 0, r = n - 1;
bool flag = true;
while (l <= r)
{
if (s[l] == '1' && s[r] == '1' || s[l] == '0' && s[r] == '0')
{
flag = false;
break;
}
else
{
l++;
r--;
}
}
int ans = 0;
if (!flag)
{
ans = n - (l*2);
// cout << "size of the given string was : " << n << "\n";
cout << ans << "\n";
}
else
{
// cout << "size of the given string was : " << n << "\n";
C. Two TVs
🧩 Problem Breakdown
You are given:
⚙️ Constraints
● 1 ≤ n, q ≤ 2e5
● 1 ≤ li ≤ ri ≤ 2e5
count[li] += 1;
count[ri + 1] -= 1;
Compute:
🧠 Complexity
Step Complexity
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
[Link](nullptr);
int n, k, q;
cin >> n >> k >> q;
return 0;
}
🥱 Prefix_Sum
Prefix Sum
2D Prefix Sum
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin>>t;
while(t--)
{
int n,m,q;
cin>>n>>m>>q;
vector<int> b(m);
for(auto &val : b)
{
cin>>val;
}
sort([Link](),[Link]());
while(q--)
{
int a;
cin>>a;
auto it = upper_bound([Link](),[Link](), a);
if(it == [Link]())
{
it--;
cout<< n - *it<<"\n";
}
else if(it == [Link]())
{
}
else
{
int porer_teacher = *it;
it--;
int ager_teacher = *it;
int len = (porer_teacher - ager_teacher) -1;
cout<<(len + 1)/2<<"\n";
}
}
}
return 0;
}
👉 The answer is essentially the minimum distance to the nearest teacher, assuming David
moves optimally away.
🔍 Key Logic
1. Sort the teachers’ positions.
Case 1️⃣: No teacher to the right (David is to the right of all teachers)
answer = n - lastTeacher
answer = firstTeacher - 1
len = (R - L) - 1
answer = (len + 1) / 2 // David can run towards center
1
10 3 3
1 4 8
2 3 10
Query 1: a = 2
L = 1, R = 4
len = (4 - 1) - 1 = 2
answer = (2 + 1)/2 = 1
➡ Output: 1
Query 2: a = 3
upper_bound(b, 3) → points to 4
Left teacher = 1
L = 1, R = 4
len = (4 - 1) - 1 = 2
answer = (2 + 1)/2 = 1
➡ Output: 1
Query 3: a = 10
answer = n - 8 = 10 - 8 = 2
➡ Output: 2
Final Output:
1
1
2
Total complexity:
Here's a simple example of how to get the number of unique elements using a set in C++.
int main() {
vector<int> arr = {4, 2, 4, 7, 2, 9, 7};
return 0;
}
✔ Explanation
🔧 Output
For the array {4, 2, 4, 7, 2, 9, 7}, the unique elements are {2, 4, 7, 9} so:
Unique characters: 5
Now Map
Here's a clear example of how to find the frequency of each unique element using a map in
C++.
int main() {
vector<int> arr = {4, 2, 4, 7, 2, 9, 7, 7};
// Counting frequencies
for(int x : arr) {
freq[x]++; // increment count for element x
}
// Printing results
cout << "Element -> Frequency\n";
for(auto &p : freq) {
cout << [Link] << " -> " << [Link] << "\n";
}
return 0;
}
✔ Explanation
● freq[x]++;
○ When accessing a key that doesn't exist, map will create it with value 0, then
increment.
● Loop prints each unique element and its count, sorted by the key automatically.
for(char c : s) {
freq[c]++;
}
Output:
a -> 2
b -> 1
c -> 2
d -> 1
e -> 2
📌 Pick one:
1️⃣ unordered_map version (faster frequency counting)
2️⃣ Find the most frequent element
3️⃣ Find the least frequent element
4️⃣ Sort elements by frequency (highest → lowest)
5️⃣ Sort elements by frequency (lowest → highest)
6️⃣ Frequency of words in a sentence
Here is a simple example of counting the frequency of unique elements using unordered_map
in C++:
int main() {
vector<int> arr = {1, 2, 2, 3, 3, 3, 4, 5, 5};
// Count frequency
for(int x : arr) {
freq[x]++;
}
// Print frequencies
cout << "Frequency of elements:\n";
for(auto &p : freq) {
cout << [Link] << " -> " << [Link] << "\n";
}
return 0;
}
🔍 Why unordered_map?
Feature unordered_map
Here is a clear example where we are given a vector<string> containing multiple words,
and we find the frequency of each unique string using map (which keeps keys sorted).
int main() {
vector<string> words = {
"apple", "banana", "apple", "orange", "banana", "apple",
"grape"
};
// Print results
cout << "Frequency of strings:\n";
for (auto &p : freq) {
cout << [Link] << " -> " << [Link] << "\n";
}
return 0;
}
🧾 Output:
Frequency of strings:
apple -> 3
banana -> 2
grape -> 1
orange -> 1
Feature Value
examples for:
string s = “abcdef”
Input
Output
Traverse
😷 PBDS-Ordered Set
PBDS
(Ordered set)
D. Counting Pairs
// CF-Rating-1200
//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// // for set
// // for multiset
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
long long int n, x, y;
cin >> n >> x >> y;
[Link]({v[i],i});
sum += v[i];
}
[Link]({v[i],i});
}
cout << ans << "\n";
}
return 0;
}
F. Greetings
Josephus Problem I
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int n;
cin>>n;
pbds<int> s;
int idx = 1 % n;
while (n--)
{
auto it = s.find_by_order(idx);
cout<<*it<<" ";
[Link](it);
if(n)
{
idx = (idx + 1) % n;
}
}
return 0;
}
Josephus Problem II
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
cin>>n>>k;
pbds<int> s;
int idx = k % n;
while (n--)
{
auto it = s.find_by_order(idx);
cout<<*it<<" ";
[Link](it);
if(n)
{
idx = (idx + k) % n;
}
}
return 0;
}
😁 Other Stuff
Modular Arithmetic
[Link]
MEX
🤕 Basic Math Problems
[Link]
Solve 1
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin>>t;
while (t--)
{
int n;
cin>>n;
vector<int> a(n);
sort([Link](),[Link]());
cout<<a[n-1]<<"\n";
}
return 0;
}
Explanation
Why?
Because average is always between min and max of the elements in the subarray.
Solve
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int ans = 0;
while(n != 50)
{
if(n<50)
{
n = n + 2;
ans++;
}
else if(n>50)
{
n = n - 3;
ans++;
}
}
cout<<ans<<"\n";
}
return 0;
}
Solve 1
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
int n;
cin>>n;
int cnt=0;
for (int i = 0; i <=n; i+=2)
{
int rem=n-i;
if(rem%4==0) cnt++;
}
cout << cnt << "\n";
}
int main() {
ios::sync_with_stdio(false);
[Link](NULL);
return 0;
}
Solve 2
😗 implementation
Rating 800
[Link]
🙉 1500+,1600+ rated problems
Rating - 1638
[Link]
1600+ Rated
1500+ Rated
🤐 Math & Number Theory
Week 6 -
[Link]
My Solve
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin >> t;
while (t--)
{
long long a, b;
cout<<LCM(a,a) - __gcd(b,a)<<"\n";
}
return 0;
}
Solve 2 (by others)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl '\n'
int main() {
ios_base::sync_with_stdio(0); [Link](0);
int tc;
cin >> tc;
while (tc--)
{
long long int a, b;
cin >> a >> b;
if (b % a == 0)
{
long long int x = b;
long long int lcm = (a * x) / __gcd(a, x);
cout << lcm - __gcd(b, x) << endl;
}
else {
long long int x = __gcd(a, b);
long long int lcm = (a * x) / (__gcd(a, x));
long long int gcd = __gcd(b, x);
cout << lcm - gcd << endl;
}
}
return 0;
}
P
[Link]
#include <bits/stdc++.h>
using namespace std;
//CC-*1108
int main()
{
ios::sync_with_stdio(false);
[Link](nullptr);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int> a(n);
}
}
if(even_found)
{
cout<<"NO"<<"\n";
}
else
{
cout<<"YES"<<"\n";
}
}
return 0;
}
Explanation
Chef wants to stop him by finding one odd number that is:
X % a1 == 0
X % a2 == 0
X % a3 == 0
...
In other words:
1, 3, 5, 7, 9, ...
● 2 → even
● 4 → even
Question:
❌
Answer:
No
Why?
👉 Immediately impossible
Answer: NO
Example 2
Numbers: [7]
Try:
● Impossible combination
Why?
Example:
[3, 5, 7]
LCM = 105 (odd)
👉 YES
So:
That’s it.
No need to calculate LCM.
No need to build big numbers.
divisibility
GCD / LCM
1. Capacity
a. [Link]() -> returns the size of the string.
b. s.max_size() -> returns the maximum size that string can hold.
c. [Link]() -> returns current available capacity of the string.
d. [Link]() -> clear the string.
e. [Link]() -> return true/false if the string is empty.
f. [Link]() -> change the size of the string.
2. Element access
a. S[i] -> access the ith index of the string.
b. [Link](i) -> access the ith index of the string.
c. [Link]() -> access the last element of the string.
d. [Link]() -> access the first element of the string.
3. Modifiers
a. s+= -> append another string.
b. [Link]() -> append another string.
c. s.push_back() -> add character to the last of the string.
d. s.pop_back() -> remove the last character of the string.
e. s= -> assign string.
f. [Link]() -> assign string.
g. [Link]() -> erase characters from the string.
h. [Link]() -> replace a portion of the string.
i. [Link]() -> insert a portion to a specific position.
4. Iterators
a. [Link]() -> pointer to the first element.
b. [Link]() -> pointer to the next element after the last element of the
string.
Stringstream
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin,s);
stringstream ss(s);
string word;
return 0;
}
[Link]-Data-Structures
Vector Built-in Functions:
1. Initialization
2. Capacity
Name Details Time Complexity
Using vector
#include<bits/stdc++.h>
using namespace std;
void concat(int s)
{
vector<int> a(s);
vector<int> b(s);
[Link]([Link](),[Link](),[Link]());
vector<int> c;
[Link]([Link](),[Link](),[Link]());
int main()
{
int n;
cin>>n;
concat(n);
return 0;
}
Using Basic Array and manual copying
#include<bits/stdc++.h>
using namespace std;
void concat(int s)
{
int a[s];
int b[s];
int c[2*s];
int main()
{
int n;
cin>>n;
concat(n);
return 0;
}
2. C. Replacement (Solve using vector)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> a(n);
return 0;
}
Topics:
1. Vector
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin>>v[i];
}
return 0;
}
2. C. Replacement (Solve using vector)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> a(n);
return 0;
}
5. Y. Range sum query (You’ll get TLE, no problem, don’t ask for support, we will solve
it on next module)
6. After solving each problem, calculate your solution’s time complexity.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin>>v[i];
}
return 0;
}
Module-3-
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
cin>>n>>q;
int a[n];
return 0;
}
Module 4 - Exam
[Link]
es
Module-5
a. Why do you think linked-list requires more memory than an array when storing
the same number of elements?
b. Write down Three Limitations of the array which can be solved by the use of
Linked List
Module-6
Implement the following Operations for Singly Linked List
class Node
{
public:
int val;
Node* next;
Node(int val)
{
this->val = val;
this->next = NULL;
}
};
tail->next = newnode;
tail = tail->next;
}
}
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while (true) //infinite loop //O(n)
{
cin>>val;
if(val == -1)
{
break;//break condition for infinite loop
}
insert_at_tail(head,tail,val);//O(1)
}
print_linked_List(head);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node(int val)
{
this->val = val;
this->next = NULL;
}
};
temp = temp->next;
count ++;
}
return count;
}
}
tail->next= newnode;
tail = tail->next;
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(1)
{
cin>>val;
if(val==-1)
{
break;
}
insert_in_linked_list(head,tail,val);
// print_linked_list(head);
cout<<size<<endl;
return 0;
}
3. Display List
Question: Create a singly linked list and print the size of the linked list.
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node(int val)
{
this->val = val;
this->next = NULL;
}
};
temp = temp->next;
count ++;
}
return count;
}
void print_linked_list(Node* head)
{
Node* temp = head;
while(temp !=NULL)
{
cout<<temp->val<<endl;
temp = temp->next;
}
}
}
tail->next= newnode;
tail = tail->next;
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(1)
{
cin>>val;
if(val==-1)
{
break;
}
insert_in_linked_list(head,tail,val);
// print_linked_list(head);
cout<<size<<endl;
return 0;
}
Question: Create a singly linked list and check if the linked list contains any
duplicate value. You can assume that the maximum value will be 100.
245674 YES
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node(int val)
{
this->val = val;
this->next = NULL;
}
};
freq[temp->val]++;
temp = temp->next;
}
void print_linked_list(Node* head)
{
Node* temp = head;
while(temp !=NULL)
{
cout<<temp->val<<endl;
temp = temp->next;
}
}
}
tail->next= newnode;
tail = tail->next;
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(1)
{
cin>>val;
if(val==-1)
{
break;
}
insert_in_linked_list(head,tail,val);
// print_linked_list(head);
if(find == 1)
{
cout<<"YES";
}
else if(find == 0)
{
cout<<"NO";
}
return 0;
}
Question: Create a singly linked list and print the middle element. If there are
multiple values in the middle print both.
123456 34
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node(int val)
{
this->val = val;
this->next = NULL;
}
};
temp = temp->next;
count ++;
}
return count;
}
}
tail->next= newnode;
tail = tail->next;
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(1)
{
cin>>val;
if(val==-1)
{
break;
}
insert_in_linked_list(head,tail,val);
// print_linked_list(head);
if(size%2 != 0)
{
for (int i = 1; i <= mid; i++)
{
temp = temp->next;
if(i==mid)
{
cout<<temp->val;
}
}
}
else
{
for (int i = 1; i <= mid-1; i++)
{
temp = temp->next;
if(i==mid-1)
{
cout<<temp->val<<" "<<temp->next->val;
}
}
}
return 0;
}
Question: Create a singly linked list and check if the linked list is sorted in
ascending order.
246584 NO
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node(int val)
{
this->val = val;
this->next = NULL;
}
};
temp = temp->next;
count ++;
}
return count;
}
}
tail->next= newnode;
tail = tail->next;
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(1)
{
cin>>val;
if(val==-1)
{
break;
}
insert_in_linked_list(head,tail,val);
// print_linked_list(head);
int size = count_size_of_linked_list(head);
int find = 0;
if(temp->val>temp->next->val)
{
find = 1;
break;
}
temp = temp->next;
if(find==1)
{
cout<<"NO";
}
else
{
cout<<"YES";
}
return 0;
}
Introduction to Basic Data Structures
Question: Take two singly linked lists as input and check if their sizes are same or
not.
5 1 4 5 -1 NO
5 1 4 -1
Question: Take a singly linked list as input and print the reverse of the linked list.
1 2 3 4 -1 4321
Question: Take a singly linked list as input, then print the maximum value of
them.
5 4 1 2 5 6 8 4 1 3 -1 8
Question: Take a singly linked list as input, then take q queries. In each query you
will be given an index and value. You need to insert those values in the given index
and print the linked list. If the index is invalid print “Invalid”.
20 40 30 10 50 60 -1 60 50 40 30 20 10
Module 8 - Exam
[Link]
s-a-batch-07/challenges
Module - 9 : Doubly Linked List
1. Constructor
2. Capacity
Name Details Time Complexity
6. Iterators
Name Details Time Complexity
Topics:
1. Doubly Linked List
Question: Take two doubly linked lists as input and check if they are the same or
not.
10 20 30 40 50 -1 NO
10 20 30 40 -1
10 20 30 40 -1 NO
10 20 30 40 50 -1
10 20 30 40 -1 NO
40 30 20 10 -1
1 2 3 4 5 -1 NO
5 4 1 2 6 -1
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node* prev;
Node(int val)
{
this->val = val;
this->next = NULL;
this->prev = NULL;
}
};
}
return flag;
}
int main()
{
print_doubly_linked_list_forward(head1);
print_doubly_linked_list_forward(head2);
if(size1 != size2)
{
cout<<"NO"<<endl;
}
else if(size1 == size2)
{
int same = check_if_doubly_linked_list_same(head1,head2,size1);
if(same == 1)
{
cout<<"NO"<<endl;
}
else if(same == 0)
{
cout<<"YES"<<endl;
}
return 0;
}
Question: Take a doubly linked list as input and reverse it. After that print the
linked list.
10 20 30 40 -1 40 30 20 10
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node* prev;
Node(int val)
{
this->val = val;
this->next = NULL;
this->prev = NULL;
}
};
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(cin>>val)
{
if(val==-1)
{
break;
}
insert_at_tail(head,tail,val);
}
print_doubly_linked_list_forward(head);
reverse_doubly_linked_list(head,tail);
print_doubly_linked_list_forward(head);
return 0;
}
Question: Take a doubly linked list as input and check if it forms any palindrome
or not.
10 20 30 40 20 10 -1 NO
10 20 30 20 40 -1 NO
10 20 30 10 10 -1 NO
10 20 20 20 10 -1 YES
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node* prev;
Node(int val)
{
this->val = val;
this->next = NULL;
this->prev = NULL;
}
};
int flag = 0;
for(Node* i = head ,* j = tail; i != j && i->prev != j; i =
i->next,j = j->prev )
{
if(i->val != j->val)
{
flag = 1;
}
}
return flag;
int main()
{
int val;
while(cin>>val)
{
if(val==-1)
{
break;
}
insert_at_tail(head,tail,val);
}
if(pal == 0)
{
cout<<"YES";
}
else if(pal == 1 )
{
cout<<"NO";
}
return 0;
}
Question: You have a doubly linked list which is empty initially. You need to take
a value Q which refers to queries. For each query you will be given X and V. You
will insert the value V to the Xth index of the doubly linked list and print the list in
both left to right and right to left. If the index is invalid then print “Invalid”.
class Node
{
public:
int val;
Node* next;
Node* prev;
Node(int val)
{
this->val = val;
this->next = NULL;
this->prev = NULL;
}
};
int main()
{
int x;
int v;
cin>>x;
cin>>v;
return 0;
}
Question: Take a doubly linked list as input and sort it in ascending order. Then
print the list.
20 40 30 10 50 60 -1 10 20 30 40 50 60
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* next;
Node* prev;
Node(int val)
{
this->val = val;
this->next = NULL;
this->prev = NULL;
}
};
int main()
{
Node* head = NULL;
Node* tail = NULL;
int val;
while(cin>>val)
{
if(val==-1)
{
break;
}
input_doubly_linked_list(head,tail,val);
vector<int> v;
Node* temp = head;
while(temp != NULL)
{
v.push_back(temp->val);
temp = temp->next;
}
sort([Link](),[Link]());
for(int x:v)
{
cout<<x<<" ";
}
return 0;
}
Module 14 - Queue
Question: Take two stacks of size N and M as input and check if both of them are
the same or not. Don’t use STL stack to solve this problem.
Question: Take a stack of size N and a queue of size M as input. Then check if
both of them are the same or not in the order of removing. You should use STL to
solve this problem.
Sample Input Sample Output
5 NO
10 20 30 40 50
5
10 20 30 40 50
5 NO
10 20 30 40 50
4
10 20 30 40
5 YES
10 20 30 40 50
5
50 40 30 20 10
Question: Take a stack of size N as input and copy those elements to another stack
to get the values in the order they were inserted and print them. You should use
STL to solve this problem.
Question: Take a queue of size N as input. You need to copy those elements in
another queue in reverse order. You might use stack here. You should use STL to
solve this problem. After copying in another queue, print the elements of that
queue.
Sample Input Sample Output
5 50 40 30 20 10
10 20 30 40 50
Tree
Binary Tree
N-ary Tree
Binary Tree -Level Order Traversal
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* left;
Node* right;
Node(int val)
{
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
Node* f = [Link]();
[Link]();
cout<<f->val<<" ";
//3 push the children
if(f->left != NULL)
{
[Link](f->left);
}
if(f->right != NULL)
{
[Link](f->right);
}
int main()
{
Node* root = new Node(10);
Node* a = new Node(20);
Node* b = new Node(30);
Node* c = new Node(40);
Node* d = new Node(50);
Node* e = new Node(60);
root->left = a;
root->right = b;
a->left = c;
b->left = d;
b->right = e;
level_order(root);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* left;
Node* right;
Node(int val)
{
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
Node* input_tree()
{
int val;
cin>>val;
Node* root ;
if(val == -1) root = NULL;
else root = new Node(val);
queue<Node*> q;
if (root) [Link](root);
while(![Link]())
{
//1 ber kore ana
Node* f = [Link]();
[Link]();
int l,r;
cin>>l>>r;
f->left = myLeft;
f->right = myRight;
if(f->left)
{
[Link](f->left);
}
if(f->right)
{
[Link](f->right);
}
}
return root;
}
queue<Node*> q;
[Link](root);
while(![Link]())
{
//1 ber kore ana - Eject from queue
Node* f = [Link]();
[Link]();
cout<<f->val<<" ";
if(f->left != NULL)
{
[Link](f->left);
}
if(f->right != NULL)
{
[Link](f->right);
}
int main()
{
level_order(root);
return 0;
}
class Node
{
public:
int val;
Node* left;
Node* right;
Node(int val)
{
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
Node* input_tree()
{
int val;
cin>>val;
Node* root ;
if(val == -1) root = NULL;
else root = new Node(val);
queue<Node*> q;
if (root) [Link](root);
while(![Link]())
{
//1 ber kore ana
Node* f = [Link]();
[Link]();
int l,r;
cin>>l>>r;
f->left = myLeft;
f->right = myRight;
if(f->left)
{
[Link](f->left);
}
if(f->right)
{
[Link](f->right);
}
}
return root;
}
int count = 0;
queue<Node*> q;
[Link](root);
while(![Link]())
{
//1 ber kore ana - Eject from queue
Node* f = [Link]();
[Link]();
cout<<f->val<<" ";
count++;
if(f->left != NULL)
{
[Link](f->left);
}
if(f->right != NULL)
{
[Link](f->right);
}
}
cout<<endl;
cout<<"size : "<<count<<endl;
int main()
{
level_order(root);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* left;
Node* right;
Node(int val)
{
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
Node* input_binary_tree()
{
int val;
cin>>val;
Node* root;
if(val == -1)
{
root = NULL;
}
else
{
root = new Node(val);
}
queue<Node*> q;
if(root != NULL)
{
[Link](root);
}
while(![Link]())
{
Node* p = [Link]() ;
[Link]();
int l,r;
cin>>l>>r;
Node * myLeft,*myRight;
p->left = myLeft;
p->right = myRight;
if(p->left)
{
[Link](myLeft);
}
if(p->right)
{
[Link](myRight);
}
return root;
int main()
{
Node* root = input_binary_tree();
cout<<count_nodes(root)<<endl;
return 0;
}
Count Leaf Nodes In binary tree
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node* left;
Node* right;
Node(int val)
{
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
Node* input_binary_tree()
{
int val;
cin>>val;
Node* root;
if(val == -1)
{
root = NULL;
}
else
{
root = new Node(val);
}
queue<Node*> q;
if(root != NULL)
{
[Link](root);
}
while(![Link]())
{
Node* p = [Link]() ;
[Link]();
int l,r;
cin>>l>>r;
Node * myLeft,*myRight;
p->left = myLeft;
p->right = myRight;
if(p->left)
{
[Link](myLeft);
}
if(p->right)
{
[Link](myRight);
}
return root;
int l = count_leaf_nodes(root->left);
int r = count_leaf_nodes(root->right);
return l+r;
}
int main()
{
Node* root = input_binary_tree();
cout<<count_leaf_nodes(root)<<endl;
return 0;
}
300 20 30 40 -1 50 60 -1 -1 -1 -1 -1 -1
10
20 30
40 70 -1 50
90 110 -1 -1 80 60
-1 -1 -1 -1 100 -1 -1 -1
-1 -1
*
18 7 21 -1 12 20 26 9 15 -1 -1 -1 -1 -1 -1 -1 -1
10 6 23 -1 9 19 29 7 -1 12 -1 -1 35 -1 -1 -1 -1 -1 -1
Map
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin,s);
stringstream ss(s);
string word;
map<string,int> mp;
return 0;
}
[Link]-To-Algorithms
Graph
BFS
DFS
#include<bits/stdc++.h>
using namespace std;
//Graph Components
//inputs
// 8 6
// 1 2
// 0 5
// 2 3
// 6 7
// 4 5
// 1 3
//output 3
vector<int> adj_list[1005];
bool vis[1005];
int main()
{
int n,e;
cin>>n>>e;
int count = 0;
while(e--)
{
int a,b;
cin>>a>>b;
adj_list[a].push_back(b);
adj_list[b].push_back(a);
}
memset(vis,false,sizeof(vis));
}
}
cout<<count<<endl;
return 0;
}
Bellman-Ford-Funtion
#include<bits/stdc++.h>
using namespace std;
//Directed Graph
// 4 4
// 0 2 5
// 0 3 12
// 2 1 2
// 1 3 3
// 4 4
// 0 1 5
// 1 2 3
// 2 3 2
// 3 1 -6
class Edge
{
public:
int a,b,c;
Edge(int a,int b,int c)
{
this->a = a;
this->b = b;
this->c = c;
}
};
int n,e;
int dis[1005];
vector<Edge> edge_list;
void bellman_ford()
{
for (int i = 0; i < n-1; i++) //o(v)
{
for(auto ed : edge_list) //O(E)
{
int a,b,c;
a= ed.a;
b = ed.b;
c = ed.c;
if(dis[a] != INT_MAX && dis[a] + c < dis[b])
{
dis[b] = dis[a] + c;
}
}
}
} //O(VE)
int main()
{
cin>>n>>e;
while(e--)
{
int a,b,c;
cin>>a>>b>>c;
edge_list.push_back(Edge(a,b,c));
dis[0] = 0;
bellman_ford();
// for(auto ed : edge_list)
// {
// cout<<ed.a<<" "<<ed.b<<" "<<ed.c<<endl;
// }
return 0;
}
Bellman-Ford
#include<bits/stdc++.h>
using namespace std;
//directed graph
// 4 4
// 0 2 5
// 0 3 12
// 2 1 2
// 1 3 3
class Edge
{
public:
int a,b,c;
Edge(int a,int b,int c)
{
this->a = a;
this->b = b;
this->c = c;
}
};
int dis[1005];
int main()
{
int n,e;
cin>>n>>e;
vector<Edge> edge_list;
while(e--)
{
int a,b,c;
cin>>a>>b>>c;
edge_list.push_back(Edge(a,b,c));
}
for (int i = 0; i < n; i++)
{
dis[i] = INT_MAX;
}
dis[0] = 0;
a= ed.a;
b = ed.b;
c = ed.c;
if(dis[a] != INT_MAX && dis[a] + c < dis[b])
{
dis[b] = dis[a] + c;
}
}
}
// for(auto ed : edge_list)
// {
// cout<<ed.a<<" "<<ed.b<<" "<<ed.c<<endl;
// }
return 0;
}
// Directed Graph
// 4 4
// 0 2 5
// 0 3 12
// 2 1 2
// 1 3 3
// 4 4
// 0 1 5
// 1 2 3
// 2 3 2
// 3 1 -6
class Edge
{
public:
int a, b, c;
Edge(int a, int b, int c)
{
this->a = a;
this->b = b;
this->c = c;
}
};
int n, e;
int dis[1005];
vector<Edge> edge_list;
void bellman_ford()
{
for (int i = 0; i < n - 1; i++) // o(v)
{
for (auto ed : edge_list) // O(E)
{
int a, b, c;
a = ed.a;
b = ed.b;
c = ed.c;
if (dis[a] != INT_MAX && dis[a] + c < dis[b])
{
dis[b] = dis[a] + c;
}
}
}
a = ed.a;
b = ed.b;
c = ed.c;
if (dis[a] != INT_MAX && dis[a] + c < dis[b])
{
flag = true;
}
}
if (flag)
{
cout << "Negative Weighted Cycle Detected" << endl;
}
else
{
cout << "No Negative Weighted Cycle" << endl;
for (int i = 0; i < n; i++)
{
cout << i << "-> " << dis[i] << endl;
}
}
} // O(VE)
int main()
{
while (e--)
{
int a, b, c;
cin >> a >> b >> c;
edge_list.push_back(Edge(a, b, c));
}
dis[0] = 0;
bellman_ford();
// for(auto ed : edge_list)
// {
// cout<<ed.a<<" "<<ed.b<<" "<<ed.c<<endl;
// }
return 0;
}
int fibo[50];
fibo[0] = 0;
fibo[1] = 1;
fibo[2] = 2;
return fibo[n];
}
};
Visualizer link: [Link]
LeetCode-Algorithm Problems
1.Keys and Rooms [Easy]
- Asked in [Google, Amazon]
solution link
class Solution {
public:
bool vis[105][105];
vector<pair<int,int>> d = {{1,0},{-1,0},{0,-1},{0,1}};
int n,m,cnt;
bool flag = true;
memset(vis,false,sizeof(vis));
cnt = 0;
for(int i = 0 ; i<n ; i++)
{
for(int j = 0 ; j<m ; j++)
{
if(!vis[i][j] && grid[i][j] == 0 )
{
flag = true;
dfs(i,j,grid);
if(flag == true)
{
cnt++;
}
}
}
}
return cnt;
}
};
class Solution {
public:
bool vis[105][105];
vector<pair<int,int>> d = {{1,0},{-1,0},{0,-1},{0,1}};
int n,m,cnt;
bool flag = true;
memset(vis,false,sizeof(vis));
cnt = 0;
flag = true;
bfs(i,j,grid);
if(flag == true)
{
cnt++;
}
}
}
}
return cnt;
}
};
LeetCode Problem List:
1.Solve all the problems of today’s module with BFS and DFS both.
প্রবলেমগুলো কমপ্লেক্স এবং হার্ড । টোটালি অপশনাল এগুলো। যদি আপনার হাতে সময় থাকে
এবং আরো প্র্যাকটিস করতে চান সেক্ষেত্রে ট্রাই করুন। নাহলে ইগনোর করুন।
Module 6.5: Practice Day 01
(GeeksforGeeks, CSES, LeetCode)
Topics:
1. Cycle Detection
2. BFS
3. DFS
Problem Links:
Extra Problems From Mod 5 & 6(Optional):
Topics:
1. BFS
2. DFS
3. BFS, DFS on 2D Grid
4. Components
Problem Links:
Topics:
1. Dijkstra Algorithm
Problem Links:
class Solution {
public:
vector<pair<int,int>> adj[100005];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
[Link]({0,src});//O(logV)
dis[src] = 0;
while(![Link]()) //O(v)
{
pair<int,int> par = [Link]();
[Link]();//O(VlogV)
return dis;
}
};
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool vis[100005];
int main()
{
int n,m;
cin>>n>>m;
vector<int> roads;
while(m--)
{
int a,b;
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
memset(vis,false,sizeof(vis));
cout<<cnt<<endl;
return 0;
}
class Solution {
public:
vector<pair<int,int>> adj[105];
int dis[105];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<
int,int>>> pq;
[Link]({0,src});
dis[src] = 0;
while(![Link]())
{
pair<int,int> par = [Link]();
[Link]();
int par_dis = [Link];
int par_node = [Link];
dijkstra(k);
return ans;
}
};
class Solution {
public:
class Edge
{
public:
int a,b,c;
Edge(int a,int b,int c)
{
this->a = a;
this->b = b;
this->c = c;
}
};
for(auto ed : edges)
{
edge_list.push_back(Edge(ed[0],ed[1],ed[2]));
}
vector<int> dis(V);
dis[src] = 0;
a = ed.a;
b = ed.b;
c = ed.c;
if (dis[a] != 1e8 && dis[a] + c < dis[b])
{
dis[b] = dis[a] + c;
}
}
}
return dis;
}
};
2.All Paths From Source to Target [Medium]
- Asked in [Google, Amazon]
solution link
class Solution {
public:
vector<vector<int>> nodes;
vector<int> v;
int n;
v.push_back(src);
if(src == n-1)
{
nodes.push_back(v);
}
else
{
for(int child : graph[src])
{
dfs(child,graph);
}
}
v.pop_back();
vector<vector<int>>
allPathsSourceTarget(vector<vector<int>>& graph) {
n = [Link]();
dfs(0,graph);
return nodes;
}
};
Climbing Stairs [Easy]DP
- Asked in [Amazon, Google, Apple, Facebook, Microsoft]
solution link
Bottom Up DP
class Solution {
public:
int climbStairs(int n) {
int fibo[50];
fibo[0] = 0;
fibo[1] = 1;
fibo[2] = 2;
return fibo[n];
}
};
Recursion+DP
class Solution {
public:
int dp[50];
int fibo(int n)
{
if(n<3)
{
return n;
}
if(dp[n] != -1)
{
return dp[n];
}
dp[n] = fibo(n-1)+fibo(n-2);
return dp[n];
int climbStairs(int n) {
memset(dp,-1,sizeof(dp));
return ans;
}
};
House-robber[Medium]
Solve
class Solution {
public:
int dp[105];
if(dp[idx] != -1 )
{
return dp[idx];
}
dp[idx] = max(op1,op2);
return dp[idx];
memset(dp,-1,sizeof(dp));
int n = [Link]();
return recur(n-1,nums);
}
};
Practice Modules
Introduction to Algorithms
Topics:
1. Graph Representation
2. BFS
Problem Links:
Topics:
1. BFS
2. DFS
3. BFS, DFS on 2D Grid
4. Components
Problem Links:
1.Counting Rooms [CSES]
Topics:
1. Cycle Detection
2. BFS
3. DFS
Problem Links:
Extra Problems From Mod 5 & 6(Optional):
Topics:
1. Dijkstra Algorithm
Problem Links:
Topics:
1. Bellman Ford Algorithm
2. Floyd Warshall Algorithm
3. Dijkstra Algorithm
Problem Links:
1.Bellman-Ford
2.Floyd-Warshall
3.Dijkstra? [Optional - just try it. Don’t look for support, we will solve it in
next module]
Topics:
1. DSU
Problem Links:
par[leader1] = leader2;
}
2. Building Roads [CSES] [Try to solve this using DSU]
3. Roads not only in Berland [Codeforces] (Optional. Read this tutorial -
[Link] )
class Solution {
public:
bool vis[505][505];
vector<pair<int,int>> d = {{0,1},{0,-1},{1,0},{-1,0}};
int n,m;
bool flag;
int cnt;
if(!valid(ci,cj))
{
flag = false;
}
else if(!vis[ci][cj] && grid[ci][cj] == 1)
{
dfs(ci,cj,grid);
}
n = [Link]();
m = grid[0].size();
int ans = 0;
return ans;
}
};
Topics:
1. Dynamic Programming
Problem links:
1.Print Digits using Recursion
2.Factorial
3.Reach Value
4.Fibonacci Number [Easy]
- Asked in [Facebook, Amazon, Apple, Microsoft]
solution link
Bottom-Up-DP(Loop)
class Solution {
public:
int fib(int n) {
int fibo[50];
fibo[0] = 0;
fibo[1] = 1;
return fibo[n];
}
};
Top-Down-Recursive-DP-Memoization
class Solution {
public:
int dp[50];
int f(int n)
{
if(n<2)
{
return n;
}
if(dp[n] != -1)
{
return dp[n];
}
int fib(int n) {
memset(dp,-1,sizeof(dp));
}
};
Top-Down-DP-Memoization-Recursive
class Solution {
public:
int dp[50];
int f(int n)
{
if(n<2)
{
return n;
}
if(n == 2)
{
return 1;
}
if(dp[n] != -1)
{
return dp[n];
}
return dp[n];
}
int tribonacci(int n) {
memset(dp,-1,sizeof(dp));
Bottom Up DP - Loop
class Solution {
public:
int tribonacci(int n) {
int fibo[50];
fibo[0] = 0;
fibo[1] = 1;
fibo[2] = 1;
return fibo[n];
}
};
Extra Problem links:
Problem links:
1.U. Knapsack
#include <bits/stdc++.h>
using namespace std;
//CodeForces
int dp[1005][1005];
if (dp[i][mx_weight] != -1)
return dp[i][mx_weight];
int main()
{
int n, mx_weight;
return 0;
}
class Solution {
public:
int dp[205][205];
int n,m;
if(i>=n || j>=m)
return INT_MAX;
if(i == n-1 && j == m-1)
return grid[i][j];
if(dp[i][j] != -1 )
return dp[i][j];
n = [Link]();
m = grid[0].size();
memset(dp,-1,sizeof(dp));
return rec(0,0,grid);
}
};
class Solution {
public:
int dp[105];
dp[idx] = max(op1,op2);
return dp[idx];
memset(dp,-1,sizeof(dp));
int n = [Link]();
return recur(n-1,nums);
}
};
class Solution {
public:
int dp[105];
int rec(int idx,vector<int>& nums)
{
if(idx < 0)
{
return 0;
}
if(dp[idx] != -1)
{
return dp[idx];
}
dp[idx] = max(op1,op2);
return dp[idx];
}
if(n == 1)
{
return nums[0];
}
memset(dp,-1,sizeof(dp));
int ans1 = rec([Link]()-2,nums);
memset(dp,-1,sizeof(dp));
[Link]([Link]());
int ans2 = rec([Link]()-1,nums);
return max(ans1,ans2);
}
};
}
};
class Solution {
public:
bool hasCycle(ListNode *head) {
ListNode* slow = head;
ListNode* fast = head;
bool flag = false;
while(fast != NULL && fast->next != NULL )
{
slow = slow->next;
fast = fast->next->next;
if(slow==fast)
{
flag = true;
break;
}
}
return flag;
}
};
3. Remove Duplicates from Sorted List [Easy]
- Asked in [Goole, Amazon, Apple, Microsoft, Uber]
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* temp = head;
if(head==NULL)
{
return head;
}
while(temp->next != NULL)
{
if(temp->val == temp->next->val)
{
temp->next = temp->next->next;
}
else
{
temp = temp->next;
}
}
return head;
}
};
class Solution {
public:
}
};
class Solution {
public:
while(temp != NULL )
{
insert_at_tail(newhead,newtail,temp->val);
temp = temp->next;
}
reverse_recursion(newhead,newhead);
temp = head;
ListNode* temp2 = newhead;
while(temp!=NULL)
{
if(temp->val != temp2->val )
{
return false;
}
temp = temp->next;
temp2= temp2->next;
}
return true;
}
};
class Solution {
public:
vector<int> v;
ListNode* temp = head;
while(temp != NULL )
{
v.push_back(temp->val);
temp = temp->next;
}
vector<int> v2;
v2 = v;
reverse([Link](),[Link]());
if(v != v2)
{
return false;
}
return true;
}
};
class Solution {
public:
void deleteNode(ListNode* node) {
node->val = node->next->val;
node->next = node->next->next;
}
};
Module 11.5: Practice Day 02
(Leetcode Links)
Topics:
1. Singly Linked List
1. Remove Linked List Elements [Easy]
- Asked in [Facebook, Amazon, Microsoft]
solution explained with animation
class Solution {
public:
int size_singly_linked_list(ListNode* head)
{
ListNode* temp = head;
int count = 0;
while(temp != NULL)
{
temp = temp->next;
count++;
}
return count ;
}
int fcount = 1;
int lcount = 1;
swap(first->val,last->val);
return head;
};
5. Merge Nodes in Between Zeros [Medium]
- Asked in [Google, Facebook, Amazon, Microsoft]
Module-13-Extra Problems
এক্সট্রা প্র্যাকটিস প্রবলেম গুলো অপশনাল হিসেবে দেওয়া হয়। সবার করাটা বাধ্যতামূলক নয়। না
পারলে টেনশন এর কিছু নেই। আমরা এখনো মডিউলে স্ট্যাক নিয়ে প্রবলেম সলভিং দেখি নাই। এই
উইকের লাস্ট মডিউলে আমরা দেখব। তখন ইজিলি হয়ে যাবে।
তারপরও উপরের দুটি প্রবলেম এর সল্যুশন লিংক দিয়ে দিচ্ছি।
আগে নিজে ট্রাই করে তারপর দেখে নিতে পারেন। বাট কারো থেকে হেল্প নিয়ে জোড় করে করতে হবে
না। সামনে স্ট্যাক নিয়ে প্রবলেম সল্ভিং মডিউল আসলে তখন পেরে যাবেন।
conceptual DS 4-1
1.Baseball Game [Easy]
- Asked in [Amazon]
solution link
Module 15
1.Valid Parentheses [Easy]
- Asked in [Google, Amazon, Apple, Facebook, Microsoft, Adobe,
Samsung, IBM, Intel, Uber, Linkedin]
solution link
#include <bits/stdc++.h>
stack<int> pushAtBottom(stack<int>& myStack, int x)
{
stack<int> st;
while(![Link]())
{
[Link]([Link]());
[Link]();
}
[Link](x);
while(![Link]())
{
[Link]([Link]());
[Link]();
}
return myStack;
}
4.Maximum Equal Stack Sum - Coding Ninjas
Topics:
1. Stack
2. Queue
Problem Links:
Answer:
Preorder = 1,7,2,6,5,11,9,9,5
Inorder = 2,7,5,6,11,1,9,5,9
Postorder = 2,5,11,6,7,5,9,9,1
Module 18.5: Practice Day 01
(Problem Links)
Topics:
1. Binary Tree
Problem Links:
1.Postorder Traversal [Easy]
- Asked in [Google, Amazon, Facebook, Adobe]
solution link
Solve 1
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
map<int,int> mp;
for(int x: nums)
{
mp[x]++;
}
return false;
}
};
Solve 2
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
set<int> s;
for(int x: nums)
{
[Link](x);
}
}
};
2.Valid Anagram [Easy]
- Asked in [Google, Amazon, Facebook, Microsoft, Apple]
solution link
Module 23.5: Practice Day 02
(Leetcode Links)
Topics:
1. Priority Queue
2. Set
3. Map
4. Recap of Linkedlist, Stack, Tree
Problem Links:
1.Kth Largest Element in an Array [Medium]
- Asked in [Google, Amazon, Facebook, Microsoft, Apple]
solution link
Solve
class Solution {
public:
int findKthLargest(vector<int>& nums, int k) {
priority_queue<int,vector<int>,greater<int>> minheap;
for(int x: nums)
{
[Link](x);
if([Link]() > k )
{
[Link]();
}
}
return [Link]();
}
};
class Solution {
public:
int lastStoneWeight(vector<int>& stones) {
priority_queue<int> maxheap;
for(int x : stones)
{
[Link](x);
}
while(![Link]() )
{
int top1 = [Link]();
[Link]();
if([Link]())
{
return top1;
}
int top2 = [Link]();
[Link]();
if([Link]())
{
return 0;
}
return [Link]();
}
};
Solve 2
class Solution {
public:
int lastStoneWeight(vector<int>& stones) {
priority_queue<int> pq;
for(int x : stones)
[Link](x);
while(![Link]())
{
int first = [Link]();
[Link]();
if([Link]()) return first;
int sec = [Link]();
[Link]();
if(first != sec)
[Link](first - sec);
}
return 0;
}
};
3.Contains Duplicate [Easy]
- Asked in [Amazon, Microsoft, Apple, Adobe]
solution link
Recap Problems:
#include<bits/stdc++.h>
using namespace std;
//CodeForces-Sheet-2-Loops-Z-Three-Numbers
int main()
{
int k,s;
cin>>k>>s;
int x=0;
int y=0;
int z=0;
int count = 0;
}
}
}
cout<<count;
return 0;
}
N-Shift Zeros
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
return 0;
}
Solve 2
#include<bits/stdc++.h>
using namespace std;
void shift_zero(int n)
{
int a[n];
int idx = 0;
int main()
{
int n;
cin>>n;
shift_zero(n);
return 0;
}
C-Choose Elements
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cin>> sumnum;
int count = 0;
for (int i = 0; i < n && count < sumnum; i++)
{
if (a[i] > 0)
{
sum =sum + a[i];
count++;
}
else
{
break;
}
}
cout<<sum<<endl;
return 0;
}
Roads not only in Berland [Codeforces-Algorithm Problem]
#include<bits/stdc++.h>
using namespace std;
//input
// 7
// 1 2
// 2 3
// 3 1
// 4 5
// 5 6
// 6 7
//output
// 1
// 3 1 3 7
int par[1005];
int group_size[1005];
if(leader1 == leader2)
{
return;
}
}
else
{
par[leader1] = leader2;
group_size[leader2] += group_size[leader1];
int main()
{
int n;
cin>>n;
for (int i = 0; i < 1005; i++)
{
par[i] = -1;
group_size[i] = 1;
}
vector<pair<int,int>> rmv;
vector<pair<int,int>> create;
int a,b;
cin>>a>>b;
if(leaderA == leaderB)
{
rmv.push_back({a,b});
}
else
{
dsu_union(a,b);
}
}
for (int i = 2; i <=n; i++)
{
int leader_1 = find(1);
int leader_node = find(i);
if(leader_1 != leader_node)
{
create.push_back({1,i});
dsu_union(1,i);
}
cout<<[Link]()<<endl;
return 0;
}
Dijkstra? [Codeforces-Algorithm Problem]
#include<bits/stdc++.h>
using namespace std;
//input
// 5 6
// 1 2 2
// 2 5 5
// 2 3 4
// 1 4 1
// 4 3 3
// 3 5
//output
// 1 4 3 5
vector<pair<ll,ll>> adj_list[1000006];
ll dis[1000006];
ll parent[1000005];
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
pq;
dis[src] = 0;
[Link]({0,src});
while(![Link]())
{
pair<ll,ll> par = [Link]();
[Link]();
ll par_node = [Link];
ll par_dis = [Link];
for(auto child : adj_list[par_node])
{
ll child_node = [Link];
ll child_dis = [Link];
[Link]({dis[child_node],child_node});
parent[child_node] = par_node;
}
}
}
int main()
{
ll n,m;
cin>>n>>m;
while(m--)
{
ll a,b,c;
cin>>a>>b>>c;
adj_list[a].push_back({b,c});
adj_list[b].push_back({a,c});
dijkstra(1);
if(dis[n] == LLONG_MAX )
{
cout<< -1 <<endl;
}
else
{
ll node = n;
vector<ll>path;
while( node != -1)
{
path.push_back(node);
node = parent[node];
}
reverse([Link](),[Link]());
for(auto val : path)
{
cout<<val<<" ";
}
cout<<endl;
}
return 0;
}
Knapsack [Codeforces]
Sheet#4(Strings)
Extra Practice - Module - 5 - C++
H. N Times
A. Create A New String
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin,s);
string t;
getline(cin,t);
cout<<[Link]()<<" "<<[Link]()<<endl;
[Link]([Link]()," ");
[Link]([Link](),t);
cout<<s<<endl;
return 0;
}
Solve 2 (not so retarded)
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
cout<<size1<<" "<<size2<<endl;
cout<<s1<<" "<<s2<<endl;
return 0;
}
C. Compare
Solve
#include<bits/stdc++.h>
using namespace std;
int main()
{
string x,y;
cin>>x>>y;
if(x<=y)
{
cout<<x;
}
else
{
cout<<y;
}
return 0;
}
G. Conversion
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
cout<<s<<'\n';
return 0;
}
C solve
#include <stdio.h>
#include <string.h>
int main()
{
char s[100001];
scanf("%s",s);
int size = strlen(s);
for(int i = 0; i<size; i++)
{
if(s[i]==',')
{
s[i]= ' ';
}
if( 'a'<=s[i] && s[i]<='z')
{
s[i]= s[i]-32;
}
else if( 'A'<=s[i] && s[i]<='Z')
{
s[i]= s[i]+32;
}
}
printf("%s",s);
return 0;
}
H. Good or Bad
#include<bits/stdc++.h>
using namespace std;
//CodeForces_Sheet_4_Strings
int main()
{
int t;
cin>>t;
for (int i = 0; i < t; i++)
{
string s;
cin>>s;
if([Link]("010")!= -1 || [Link]("101")!= -1 )
{
cout<<"Good"<<endl;
}
else cout<<"Bad"<<endl;
}
return 0;
}
I. Palindrome
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,s2;
cin>>s;
s2 = s;
reverse([Link](),[Link]() );
if(s == s2)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
return 0;
}
Solve with c
#include <stdio.h>
int main()
{
char s[1001];
scanf("%s",s);
int size = strlen(s);
int pal=1;
for(int i = 0; i<size; i++)
{
if(s[i]!=s[size-1-i])
{
pal = 0;
break;
}
}
if(pal)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}
J. Count letters
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(char c : s)
{
freq[c - 'a']++ ;
}
return 0;
}
K. I Love strings
Solve 1
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
[Link]();
for (int i = 0; i < n; i++)
{
string s;
cin>>s;
string t;
cin>>t;
string s2;
int len1 = [Link]();
int len2 = [Link]();
// cout<<s2<<endl;
// cout<<s<<endl;
// cout<<t<<endl;
int j;
for( j = 0; j < len1 && j<len2 ; j++)
{
cout<<s[j]<<t[j];
}
while(j<len1)
{
cout<<s[j];
j++;
}
while(j<len2)
{
cout<<t[j];
j++;
}
cout<<endl;
}
return 0;
}
Solve 2
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string s1,s2;
cin>>s1>>s2;
}
return 0;
}
L. String Functions
Sheet#7(Recursion)
Sheet#3(Array)
K - Sum Digits Codeforces
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
for(char c : s)
{
sum = sum + (c - '0') ;
cout<<sum<<"\n";
return 0;
}
CodeNinjas
Module 19-Problem solving
My Solve
if(root == NULL)
{
return false;
}
queue<BinaryTreeNode<int> *> q;
[Link](root);
while(![Link]())
{
//1 ber kore ana - Eject from queue
BinaryTreeNode<int> * f = [Link]();
[Link]();
if(f->data == x)
{
return true;
}
//3 push the children
if(f->left != NULL)
{
[Link](f->left);
}
if(f->right != NULL)
{
[Link](f->right);
}
return false;
}
Module Solve
if(root == NULL)
{
return false;
}
if(root->data == x)
{
return true;
}
int l = isNodePresent(root->left,x);
int r = isNodePresent(root->right,x);
return (l || r);
}
2.Node Level - Coding Ninjas
House Robber[CodeStudio]
if(n == 0)
{
return 0;
}
vector<int> ans(n);
ans[0] = houses[0];
ans[i] = max(opt1,opt2);
return ans[n-1];
}
⚒️ CSES online judge
1.Message Route - CSES
#include<bits/stdc++.h>
using namespace std;
//output
// 3
// 1 4 5
vector<int> adj_list[1000000];
bool vis[1000000];
int lvl[1000000];
int parent[1000000];
while(![Link]())
{
//ber kore ana
//puch children
int main()
{
int n,m;
cin>>n>>m;
while(m--)
{
int a,b;
cin>>a>>b;
adj_list[a].push_back(b);
adj_list[b].push_back(a);
memset(vis,false,sizeof(vis));
memset(lvl,-1,sizeof(lvl));
memset(parent,-1,sizeof(parent));
int src = 1;
int des = n;
bfs(src);
if(vis[des] == true)
{
cout<<lvl[des]<<endl;
int node = des;
vector<int> path;
while(node != -1)
{
path.push_back(node);
node = parent[node];
}
reverse([Link](),[Link]());
for(auto x : path)
{
cout<<x<<" ";
}
}
else
{
cout<<"IMPOSSIBLE"<<endl;
}
return 0;
}
2 Shortest Routes II
#include<bits/stdc++.h>
using namespace std;
//undirected Graph
// 4 3 5
// 1 2 5
// 1 3 9
// 2 3 3
// 1 2
// 2 1
// 1 3
// 1 4
// 3 2
int main()
{
long long int n,e,q;
cin>>n>>e>>q;
}
else
{
adj_mat[i][j] = LLONG_MAX;
}
}
while(e--)
{
long long int a,b,c;
cin>>a>>b>>c;
adj_mat[a][b] = min(adj_mat[a][b],c);
adj_mat[b][a] = min(adj_mat[b][a],c);
// }
while(q--)
{
cin>>na>>nb;
if(adj_mat[na][nb] == LLONG_MAX )
{
cout<<-1<<endl;
}
else
{
cout<<adj_mat[na][nb]<<endl;
return 0;
}
[Link] Roads [CSES]
BFS
DFS
#include<bits/stdc++.h>
using namespace std;
//input
// 4 2
// 1 2
// 3 4
//output
// 1
// 1 3
vector<int> adj[100005];
bool vis[100005];
int main()
{
int n,m;
cin>>n>>m;
vector<int> roads;
while(m--)
{
int a,b;
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
memset(vis,false,sizeof(vis));
cout<<cnt<<endl;
for (int i = 0; i < (int)[Link]()-1; i++)
{
cout<<roads[i]<<" "<<roads[i+1]<<endl;
}
return 0;
}
DSU
#include<bits/stdc++.h>
using namespace std;
int par[100005];
int group_size[100005];
}
int main()
{
int n,e;
cin>>n>>e;
memset(par,-1,sizeof(par));
memset(group_size,1,sizeof(group_size));
while(e--)
{
int a,b;
cin>>a>>b;
if(leaderA != leaderB)
{
dsu_union(a,b);
}
}
int cnt = 0;
vector<int> v;
if(leader_1 != leader_node)
{
cnt++;
dsu_union(leader_1,leader_node);
v.push_back(leader_node);
}
}
cout<<cnt<<endl;
for(int i : v)
{
cout<<1<<" "<<i<<endl;
}
return 0;
}
[Link] Construction [CSES]
DSU
#include<bits/stdc++.h>
using namespace std;
int par[100005];
int group_size[100005];
int cmp ;
int mx ;
if(leader1 == leader2)
{
return;
}
cmp--;
int main()
{
int n,e;
cin>>n>>e;
cmp = n;
mx = 1;
// memset(par,-1,sizeof(par));
// memset(group_size,1,sizeof(group_size));
dsu_union(a,b);
cout<<cmp<<" "<<mx<<endl;
return 0;
}
5 Concert Tickets
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
[Link](NULL);
int n,m;
cin>>n>>m;
multiset<int> tickets;
// vector<int> tickets(n);
for (int i = 0; i < n; i++)
{
int val;
cin>>val;
[Link](val);
}
// for (int i = 0; i < n; i++)
// {
// cin>>tickets[i];
// }
// vector<int> mx_price(m);
for (int i = 0; i < m; i++)
{
int mx_price;
cin>>mx_price;
auto it = tickets.upper_bound(mx_price); //upper_bound
returns next greater number
if(it == [Link]()) //means all tickets are greater
then the max price
{
cout<<-1<<'\n';
}
else
{
it--;
cout<<*it<<'\n';
[Link](it);
}
}
return 0;
}
Problem Solvers Club
CSES - Playlist
1 Problem 1
2 Problem 2
3 Problem 3
4 Problem 4
5 Problem 5
6 Problem 6
7 Problem 7
8 Problem 8
9 Problem 9
10 Problem 10
11 Problem 11
12 Problem 12
13 Problem 13
14 Problem 14
15 Problem 15
16 Problem 16
17 Problem 17
18 Problem 18
19 Problem 19
20 Problem 20
Problem 1
Solve
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[101];
cin>>s;
int upcount = 0;
int lowcount = 0;
// cout<<upcount<<endl;
// cout<<lowcount<<endl;
if(upcount>lowcount)
{
for (int i = 0; i < size; i++)
{
if( 'a' <= s[i] && s[i] <= 'z')
{
s[i] = s[i] - 32;
}
}
else if(upcount<lowcount)
{
for (int i = 0; i < size; i++)
{
if( 'A' <= s[i] && s[i] <= 'Z')
{
s[i] = s[i] + 32;
}
}
else
{
for (int i = 0; i < size; i++)
{
if( 'A' <= s[i] && s[i] <= 'Z')
{
s[i] = s[i] + 32;
}
}
}
cout<<s;
return 0;
}
Problem 19
Solve
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> a1(n),a2(n);
for (int i = 0; i < n; i++)
{
cin>>a1[i];
}
for (int i = 0; i < n; i++)
{
a2[i] = a1[i] ;
}
sort([Link](),[Link]());
int l = 0;
int r = n-1;
if(l>=n)
{
cout<<"yes"<<endl;
cout<<1<<" "<<1;
return 0 ;
reverse([Link]()+l,[Link]()+r+1);
if(a1==a2)
{
cout<<"yes"<<endl;
cout<<l+1<<" "<<r+1;
}
else
{
cout<<"no"<<endl;
}
return 0;
}
XPSC
DSA Overview Session Week-1,2,3 14/09/2025
[Link]
[Link]
[Link]
Practice List
[Link]
class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
map<int,int> mp;
for(auto x : nums)
{
mp[x]++;
}
priority_queue<pair<int,int>> pq;
return res;
}
};
ITA-Week-04-Conceptual Session 2
Bottom Up -Recursion
#include<bits/stdc++.h>
using namespace std;
//codeforces
//Bottom-Up-Recursion
if(cnt == n)
{
return true;
}
int main()
{
int t;
cin>>t;
while(t--)
{
long long int n;
cin>>n;
if(rec(1,n))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
Top-Down Recursion
#include<bits/stdc++.h>
using namespace std;
//codeforces
//Top-Down-Recursion
if(n == 0)
{
return false;
}
bool op1 = false,op2 = false;
if(n%10 == 0 )
{
op1 = rec(n/10);
}
if(n%20 == 0)
{
op2 = rec(n/20);
}
int main()
{
int t;
cin>>t;
while(t--)
{
long long int n;
cin>>n;
if(rec(n))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
Self Practice
E. Base Conversion
#include <bits/stdc++.h>
using namespace std;
if (n == 0)
{
return ;
}
binary(n/2);
cout<<(n%2);
}
int main()
{
long long int t;
cin>>t;
while(t--)
{
long long int n;
cin>>n;
if(n==0)
{
cout<<0;
}
else
{
binary(n);
cout<<endl;
}
return 0;
}
Top-Down-Recursion
#include<bits/stdc++.h>
using namespace std;
long long int a[1005];
void rec(int i)
{
if(i<0)
{
return ;
}
if(i % 2 == 0)
{
cout<<a[i]<<" ";
}
rec(i-1);
int main()
{
long long int n;
cin>>n;
cin>> a[i];
}
rec(n-1);
cout<<endl;
return 0;
}
Phitron Exams
Profile Link :
[Link]
User Name : @ahmedragibhasan7
ios_base::sync_with_stdio(false);
[Link](NULL);
[Link]
es
Algorithm Mid
[Link]
allenges
Algorithm Assignment 2
[Link]
#include <bits/stdc++.h>
#define ll long long int
#define all(x) [Link](), [Link]()
#define nl '\n'
#define fastIO() ios_base::sync_with_stdio(0), [Link](0), [Link](0)
using namespace std;
#ifndef ONLINE_JUDGE
// #include "../DebugTemplate/debug.h"
#else
#define debug(x...)
#define dbgsize(x)
#endif
int main()
{
fastIO();
return 0;
}
Temp
Sphere Online Judge
[Link]
GeeksForGeeks Online Judge
1.Bellman-Ford [GFG]
class Solution {
public:
class Edge
{
public:
int a,b,c;
Edge(int a,int b,int c)
{
this->a = a;
this->b = b;
this->c = c;
}
};
for(auto ed : edges)
{
edge_list.push_back(Edge(ed[0],ed[1],ed[2]));
}
vector<int> dis(V);
for (int i = 0; i < V; i++)
{
dis[i] = 1e8;
}
dis[src] = 0;
a = ed.a;
b = ed.b;
c = ed.c;
if (dis[a] != 1e8 && dis[a] + c < dis[b])
{
dis[b] = dis[a] + c;
}
}
}
a = ed.a;
b = ed.b;
c = ed.c;
if (dis[a] != 1e8 && dis[a] + c < dis[b])
{
return { -1};
}
}
return dis;
}
};
par[leader1] = leader2;
}
CodeChef
Covered In Phitron Sessions
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a,b;
cin>>a>>b;
int cnt = 0;
while(true)
{
a--;
b -= 2;
if(a<0 || b<0)
{
break;
}
else
{
cnt +=3;
}
cout<<cnt<<endl;
}
return 0;
}
Mark Points Div-4
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin>>n;
string s;
cin>>s;
int cnt = 0;
}
else
{
if(cnt == 1 || cnt == 2)
{
flag = false;
break;
}
cnt = 0;
}
}
if(cnt == 1 || cnt == 2)
{
flag = false;
if(flag)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int x,y;
cin>>x>>y;
if(flag)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Self Practice
[Link]
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
cout<<180-(a+b)<<endl;
[Link]
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int sum_time = n * k;
cout<<hours<<" "<<minutes<<endl;
return 0;
}
Outslook Online Judge
LeetCode-MasterBranch
Palindrome Number[easy-Math]
Retarded Solution
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0)
{
return false;
}
vector<int> v;
vector<int> v2;
while(x != 0)
{
int last = x % 10;
v.push_back(last);
x = x / 10;
}
v2 = v;
reverse([Link](),[Link]());
if(v == v2)
{
return true;
}
else
{
return false;
}
}
};
House-robber[Medium]
Solve
LeetCode Grid/Matrix Problems
1.Island Perimeter [Easy]
- Asked in [Google, Facebook, Amazon, Apple, Microsoft]
solution link
class Solution {
public:
bool vis[105][105];
int level[105][105];
vector<pair<int,int>> d = {{1,0},{-1,0},{0,-1},{0,1}};
int n,m;
}
return -1;
n = [Link]();
m = maze[0].size();
memset(vis,false,sizeof(vis));
return bfs(entrance[0],entrance[1],maze);
}
};
70 Leetcode Problems
1 Contains Duplicate - LeetCode
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
set<int> s;
for(int x: nums)
{
[Link](x);
}
}
};
class Solution {
public:
int n = [Link]() ;
sort([Link](),[Link]());
int miss;
return miss;
}
};
3 Two Sum - LeetCode
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
int n = [Link]();
vector<int> ans;
}
}
}
return ans;
}
};
4 How Many Numbers Are Smaller Than the Current Number - LeetCode
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
vector<int> smaller;
int n = [Link]();
int cnt = 0;
}
smaller.push_back(cnt);
cnt = 0;
}
return smaller;
}
};
class Solution {
public:
int minTimeToVisitAllPoints(vector<vector<int>>& points) {
//Chebyshev Distance
int sec = 0;
int n = [Link]();
for(int i = 0 ; i < n-1 ; i ++ )
{
int srcx = points[i][0];
int srcy = points[i][1];
return sec;
}
};
Shariah
[Link]
'লা ইলাহা ইল্লা আনতা সুবহানাকা ইন্নী কুনতু মিনায যা-লিমীন।'
অর্থাৎ, তু মি ব্যতীত কোনো উপাস্য নেই; তু মি পবিত্র, মহান! নিশ্চয় আমি অত্যাচারীদের অন্তর্ভু ক্ত।
Time-table
[Link]
Full Course | Understand Quran and Salaah Easy Way | illustrated | 100 Episodes | Learn …
১গোসলের নিয়ত করা, 'বিসমিল্লাহ' বলে গোসল শুরু করা। দুই হাত কবজি পর্যন্ত ধোওয়া (বুখারী ২৪৮)
২ পানি ঢেলে বাম হাত দিয়ে লজ্জাস্থান পরিষ্কার করা (বুখারী ২৫৭)
৪ নামাজের ওজুর মতো ভালভাবে পূর্ণরূপে ওজু করা। এক্ষেত্রে শুধু পা দুটো বাকি রাখলেও চলবে, যা গোসলের শেষে ধুয়ে
ফেলতে হবে। (বুখারী ২৫৭, ২৫৯, ২৬৫)।
৫ মাথায় পানি ঢেলে চু লের গোড়া ভালভাবে আঙ্গুল দিয়ে ভিজানো। (বুখারী ২৫৮)।
৬ পুরো শরীরে পানি ঢালা; প্রথমে ডানে ৩বার, পরে বামে ৩বার, শেষে মাথার উপর ৩ বার (বুখারী ১৬৮)।
৭ (যেন শরীরের কোন অংশ বা কোন লোমও শুকনো না থাকে। পুরুষের দাড়ি ও মাথার চু ল এবং মহিলাদের চু ল ভালোভাবে
ভিজতে হবে।
নাভি, বগল ও অন্যান্য কুঁ চকানো জায়গায় অবশ্যই পানি ঢালতে হবে)।
গোসলের জায়গা থেকে একটু সরে গিয়ে দুই পা ধোওয়া। (বুখারী ২৫৭)।
যেকোনো হালাল বিষয়ে সিদ্ধান্ত নেওয়ার আগে ইস্তিখারা করুন!
ইস্তিখারা কী?
*যখন আমরা কোনো গুরুত্বপূর্ণ সিদ্ধান্তে দ্বিধায় পড়ি (বিয়ে, চাকরি, ব্যবসা, পড়াশোনা, কোথাও যাওয়া ইত্যাদি), তখন আল্লাহর কাছে সাহায্য
চাইতেই ইস্তিখারা করা হয়।
কারণ—
“হে আল্লাহ, আপনি জানেন, আমি জানি না—আমার জন্য যেটা ভালো সেটাই করে দিন।”
ইস্তিখারার দু'আ:
কোন কাজে ভালো মন্দ বুঝতে না পারলে, মনে ঠিক-বেঠিক, উচিত-অনুচিত বা লাভ-নোকসানের দ্বন্দ্ব আল্লাহর নিকট মঙ্গল প্রার্থনা করতে দুই
রাকআত নফল নামায পড়ে নিম্নের দুআ পঠনীয়।
َ اللَّ ُه َّم ِإنْ ُك ْنتَ َتعْ َل ُم َأنَّ ه ََذا اَألمْ ر، ب
ِ َو َتعْ َل ُم َوال َأعْ َل ُم َوَأ ْنتَ عَ ال ُم ْال ُغيُو، َفِإ َّنكَ َت ْق ِد ُر َوال َأ ْق ِد ُر، َوَأسْ َألُكَ مِنْ َفضْ لِكَ ْالعَ ظِ ِيم، َ َوَأسْ َتعِي ُنكَ ِبقُ ْدرَ تِك، َاللَّ ُه َّم ِإ ِّني َأسْ َتخِيرُكَ ِبع ِْلمِك
َاركْ لِي فِي ِه َوِإنْ ُك ْنتَ َتعْ َل ُم َأنَّ ه ََذا اَألمْ رَ َشرٌّ لِي فِي دِينِي َومَعَ اشِ ي َوعَ ا ِق َب ِة مْ ِري
َأ ُ َأ
ِ َفا ْقدُرْ هُ لِي َو َيسِّرْ هُ لِي ث َّم ب، () َخ ْي ٌر لِي فِي دِينِي َومَعَ اشِ ي َوعَ ا ِق َب ِة مْ ِري َوعَ ا ِجلِ ِه َوآ ِجلِ ِه
ضنِي ِب ِه ِّ َ ُث َّم ر، َْث َكان ُ َوا ْقدُرْ لِيَ ْال َخ ْيرَ حَ ي، َواصْ ِر ْفنِي عَ ْن ُه، َوعَ ا ِجلِ ِه َوآ ِجلِ ِه َفاصْ ِر ْف ُه عَ ِّني
অর্থঃ হে আল্লাহ! নিশ্চয় আমি তোমার নিকট তোমার ইলমের সাথে মঙ্গল প্রার্থনা করছি। তোমার কুদরতের সাথে শক্তি প্রার্থনা করছি এবং তোমার
বিরাট অনুগ্রহ থেকে ভিক্ষা যাচনা করছি। কেননা, তু মি শক্তি রাখ, আমি শক্তি রাখি না। তু মি জান, আমি জানি না এবং তু মি অদৃশ্যের পরিজ্ঞাতা।
হে আল্লাহ! যদি তু মি এই ( ) কাজ আমার জন্য আমার দ্বীন, দুনিয়া, জীবন এবং কাজের বিলম্বিত ও অবিলম্বিত পরিণামে ভালো জান, তাহলে তা
আমার জন্য নির্ধারিত ও সহজ করে দাও। অতঃপর তাতে আমার জন্য বৰ্ক ত দান কর। আর যদি তু মি এই কাজ আমার জন্য আমার দ্বীন, দুনিয়া,
জীবন এবং কাজের বিলম্বিত ও অবিলম্বিত পরিণামে মন্দ জান, তাহলে তা আমার নিকট থেকে ফিরিয়ে নাও এবং আমাকে ওর নিকট থেকে সরিয়ে
দাও। আর যেখানেই হোক মঙ্গল আমার জন্য বাস্তবায়িত কর, অতঃপর তাতে আমার মনকে পরিতু ষ্ট করে দাও।
প্রথমে ( َ‘ )ه ََذا اَألمْ رহা-যাল আমরা এর স্থলে বা পরে কাজের নাম নিতে হবে অথবা মনে মনে সেই জ্ঞাতব্য বিষয়ের প্রতি ইঙ্গিত করতে হবে।
সে ব্যক্তি কর্মে কোনদিন লাঞ্ছিত হয় না, যে আল্লাহর নিকট তাতে মঙ্গল প্রার্থনা করে, অভিজ্ঞদের নিকট পরামর্শ গ্রহণ করে এবং ভালো-মন্দ বিচার
করার পর কর্ম করে। (বুখারী ৭/ ১৬২, আবু দাউদ ২/৮৯, তিরমিযী ২/৩৫৫, আহমাদ ৩/৩৪৪)।
ইস্তিখারার পর কী হবে?
বিশ্বাস রাখুন
বিশেষ করে আপনি যদি রিজিক, ঋণ, ব্যবসা, চাকরি, সংসারের স্বস্তি—এসব নিয়ে চিন্তায় থাকেন, তাহলে জুমার দিনটা
আপনার জন্য খুবই মূল্যবান।
নবী করিম ﷺবলেছেন, তোমাদের শ্রেষ্ঠ দিনগুলোর একটি হলো জুমার দিন। তাই এ দিনে আমার উপর বেশি বেশি দরূদ
পাঠ করো।
আরবি:
َ اللَّ ُه َّم
ِ ص ِّل َع َلى م َُح َّم ٍد َو َع َلى
آل م َُح َّم ٍد
বাংলা উচ্চারণ:
আল্লাহুম্মা সাল্লি আলা মুহাম্মাদিওঁ ওয়া আলা আলি মুহাম্মাদ।
বাংলা অর্থ:
হে আল্লাহ, নবী করিম ﷺও তাঁর পরিবারবর্গের উপর রহমত নাযিল করুন।
আরবি:
َربِّ ِإ ِّني لِ َما َأ ْن َز ْلتَ ِإ َليَّ مِنْ َخي ٍْر َفقِي ٌر
বাংলা উচ্চারণ:
রব্বি ইন্নী লিমা আনযালতা ইলাইয়্যা মিন খাইরিন ফাকীর।
বাংলা অর্থ:
হে আমার রব, আপনি আমার দিকে যে কল্যাণই পাঠাবেন, আমি তার মুখাপেক্ষী।
আরবি:
َ َوَأ ْغ ِننِي ِب َفضْ ل َِك َعمَّنْ سِ َو،ِك
اك ْ اللَّ ُه َّم
َ اك ِفنِي ِب َحاَل ل َِك َعنْ َح َرام
বাংলা উচ্চারণ:
আল্লাহুম্মাকফিনী বিহালালিকা আন হারামিকা, ওয়া আগনিনী বিফাদলিকা আম্মান সিওয়াক।
বাংলা অর্থ:
হে আল্লাহ, আপনার হালাল দিয়ে আমাকে হারাম থেকে বাঁচান, আর আপনার অনুগ্রহ দিয়ে আমাকে আপনি ছাড়া অন্য সবার
মুখাপেক্ষী হওয়া থেকে মুক্ত করুন।
ফজরের পর —
সূরা কাহফ শুরু করুন বা পড়ে ফেলুন।
সারাদিন —
বেশি বেশি দরূদ পড়ুন।
আসরের পর —
কিছু টা নিরিবিলি হয়ে বসুন।
দোয়া করুন।
রিজিক, ঋণ, চাকরি, ব্যবসা, সংসার, মানসিক স্বস্তি—সব নিয়ে আল্লাহর কাছে খুলে বলুন।
মনে রাখবেন
জুমার দিনের বরকত শুধু নামাজ পড়ে শেষ হয়ে যায় না।
অনেক মানুষ জুমা পড়ে বের হয়ে আবার দুনিয়ার ব্যস্ততায় হারিয়ে যায়।
কিন্তু যে মানুষ এই দিনের লুকানো আমলগুলো ধরতে পারে,
সে সারা সপ্তাহের জন্য এক ধরনের নূর, শক্তি আর বরকত পেতে শুরু করে।
মনে রাখবেন:
জুমার দিনের সবচেয়ে বড় সৌন্দর্য হলো,
এই দিনে অল্প আমলেও বড় বরকত লুকিয়ে থাকে।
তাই জুমাকে শুধু পালন করবেন না,
জুমাকে অনুভব করুন।
হয়তো এই একদিনের আমলই আপনার পুরো সপ্তাহ বদলে দিতে পারে।
[Link]
Tasbih Application.mp4
How to Build a Custom PDF Text Extractor with [Link] and TypeScript
Mastering C++ STL | Pair ,Tuple, Vector, String, Map | বাংলায় Complete Tutorial
ইংলিশ কোর্স সেলস কনটেন্ট আইডিয়া ও কনটেন্ট প্ল্যানিং গাইড - Content King
BD Big Tech Interview | এই LeetCode 300 Problem + CS 200 Questions যা Cover করলেই হবে
Let’s Talk About Object-Oriented Programming (OOP) — Part 1 | by Minhajul Islam (Minhaj)
Data Structures and Algorithms Mega Course – Master Technical Interviews in 49 Hours
[Link]
Making Software
[Link]
Unreal Engine Official Learning Resources
Stack-O-Bot
Crash Course: Making an Animation In-Engine with an In-Engine Rig | Epic Developer
Community
Blueprint Communication
[Link]
ation/8nv8/unreal-engine-level-blueprint
👋 👩💻
🔥 🥘 ❓,
GitHub - nidhiupman568/Codechef-Problem-Solved: Hi! I'm Nidhi Upman, a passionate
💪 📈 🧠 🌟 🗓️, I
competitive programmer active on CodeChef . Starting with just solving 1️⃣-2️⃣ questions
🏆 🔄 💻
I persisted , upsolving to master and achieve 3-star status. Every Wednesday
tackle contests and daily practice ensures continuous improvement .
[Link]
Job GK Bangla
প্রাচীন আমল lecture 2 basic view. নাঈম ভাই
Qaantar - YouTube
Sam - [Link]
Manga - [Link]
বর্ত মান বিশ্ব রাজনীতি বুঝতে এই ৮টি মৌলিক থিওরি জানা আবশ্যক | কনসেপচু য়াল ইস্যুজ
AI-এর যুগে সফটওয়্যার ইঞ্জিনিয়ারিং: টিকে থাকার এবং এগিয়ে যাওয়ার পূর্ণাঙ্গ গাইড
[Link]
[Link]
ation/8nv8/unreal-engine-level-blueprint
[Link]
[Link]
৬টি গুরুত্বপূর্ণ ভূ -রাজনৈতিক তত্ত্ব | BCS International Affairs | Geopolitics Theories in Bangla
ভূ রাজনৈতিক তত্ত্ব | ডমিনো, হার্ট ল্যান্ড, ট্রু ম্যান ডকট্রিন, মার্শাল প্ল্যান | আন্তর্জ াতিক বিষয়াবলী
AI Courses
[Link]
[Link]
[Link]
AI-Assisted Coding Tutorial – OpenClaw, GitHub Copilot, Claude Code, CodeRabbit, Gem…
Build & Monetize Your First MCP Server (Bangla) | MCPize Tutorial
how-to-build-a-secure-ai-pr-reviewer-with-claude
[Link]
কেন উর্বর জমি হয়েও বাংলাদেশ আজও গরিব? | The Delta Paradox | Boi Kotha Koy
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Short Reads
[Link]
[Link]
Comics
Power Fantasy
[Link]
Shows
About the Movement of the Earth - E11
Monster- E25
To Be Hero X-E18
100 Meters
Solo Leveling-3
Future Employment Research
Future Employment Research
Focus on:
👉
● Remotasks → Very popular in South Asia
[Link]
👉
● Toloka (by Yandex) → Beginner friendly
[Link]
👉
● Appen → More professional projects
[Link]
👉
● TELUS AI (formerly Lionbridge)
[Link]
👉
● Clickworker
[Link]
Common topics:
💡 Tip:
Read instructions VERY carefully — most people fail because they rush.
Think of it as:
✅ Student
✅ Job searching
✅ Want remote income
✅ Switching careers
✅ Entering tech without coding
But long-term — skill upgrade is mandatory.
Git Links
steipete (Peter Steinberger) · GitHub
JOB Forms
Monipuripara,gate-3,house-25
TEJGAON
1215
DHAKA
NID - 6005202566
BSc - 3.65
Mobile Service
[Link]