1116 - Ekka Dokka
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int cs = 1; cs <= t; cs++){
long long w;
cin >> w;
if(w&1){
...
1113 - Discover the Web
1113 - Discover the Web
Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int cs = 1; cs <= t; cs++)
{
stack<string>f,b,st;
string s;
cout...
1109 - False Ordering
1109 - False Ordering
Solution 01:
#include<bits/stdc++.h>
using namespace std;
void Sieve(int n, bool prime[], bool primesqure[], int a[])
{
for(int i = 2; i <= n; i++)
prime[i] = true;
for(int i = 0; i <= (n*n + 1); i++)
primesqure[i] =...
Compare Function for sorting
Compare Function for sorting:
bool cmp (const pair<int, int> &aa, const pair<int, int> &bb)
{
if(aa.first != bb.first )
{
return aa.first < bb.first;
}
else {
...
Count Divisors
Count Divisors
Solution 1:
Complexity: sqrt(n)
#include<bits/stdc++.h>
using namespace std;
int countDivisors (int n)
{
int cnt = 0;
for(int i = 1; i <= sqrt(n); i++){
if(n % i == 0){
if(n/i == i)cnt++;
...
778. Swim in Rising Water
778. Swim in Rising Water
Complexity: O(n^2)
Topic: Flood Fill
Solution:
class Solution {public: using vi = vector<int>;struct pos{ pos(int a, int b, int c) : val(a), x (b), y(c) {} bool operator< (const pos &d) const {return val > d.val;} int val, x,y;};vi nx = {1,-1,0,0};vi ny = {0,...
786. K-th Smallest Prime Fraction
786. K-th Smallest Prime Fraction
Complexity: O(n*log(k))
Solution 1:
class Solution {public: struct fraction{ double val; int i,j; fraction(double d, int x, int y) : val(d), i(x), j(y){} bool operator< (const fraction& f)const{ return val > f.val;}};vector<int> kthSmallestPrimeFraction(vector<int>&...
790. Domino and Tromino Tiling
795. Number of Subarrays with Bounded Maximum
795. Number of Subarrays with Bounded Maximum
Complexity: O(n)
Solution 1:
int numSubarrayBoundedMax(const vector<int>& A, int l, int r){ int result = 0, start = -1, end = -1; for(int i = 0; i < A.size(); i++){ if(A[i] >r)start = i; if(A[i] >= l)end = i; ...
802. Find Eventual Safe States
802. Find Eventual Safe States
Solution: DFS
concept:
যেই নোডগুলোতে সাইকেল নাই ওই গুলা প্রিন্ট করতে হবে।
Code:
class Solution {public: unordered_set<int> cycle_nodes, safe_nodes; bool dfs(vector<vector<int>>& g, int i, unordered_set<int>visited_nodes) ...