diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cba2e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/Array/minJumpstorchEnd.cpp b/Array/minJumpstorchEnd.cpp new file mode 100644 index 0000000..382d437 --- /dev/null +++ b/Array/minJumpstorchEnd.cpp @@ -0,0 +1,16 @@ +// int minJumps(int A[], int n) +// { +// int jumps = 0, curEnd = 0, curFarthest = 0; +// for (int i = 0; i < n; i++) +// { +// if (i > curFarthest) +// return -1; +// curFarthest = max(curFarthest, i + A[i]); +// if (i < n - 1 && i == curEnd) +// { +// jumps++; +// curEnd = curFarthest; +// } +// } +// return jumps; +// } \ No newline at end of file diff --git a/graph/minEdgetomakepath.cpp b/graph/minEdgetomakepath.cpp index 5ddd8d8..141ddf1 100644 --- a/graph/minEdgetomakepath.cpp +++ b/graph/minEdgetomakepath.cpp @@ -1,43 +1,51 @@ -#include +#include using namespace std; -void solve(int src,int dest,vector adj[],int n){ - vector> newAdj[n]; - for(int i=0;i adj[], int n) +{ + vector> newAdj[n]; + for (int i = 0; i < n; i++) + { int u = i; - for(auto v:adj[i]){ - newAdj[u].push_back({v,0}); - newAdj[v].push_back({u,1}); + for (auto v : adj[i]) + { + newAdj[u].push_back({v, 0}); + newAdj[v].push_back({u, 1}); } } - priority_queue,vector>,greater>> pq; - pq.push({0,src}); - vector cost(n,INT_MAX); - cost[src]=0; - while(!pq.empty()){ - auto pnt = pq.top().second;pq.pop(); - for(auto x:newAdj[pnt]){ - if(x.second+cost[pnt] < cost[x.first]){ - cost[x.first] = x.second+cost[pnt]; - pq.push({cost[x.first],x.first}); + priority_queue, vector>, greater>> pq; + pq.push({0, src}); + vector cost(n, INT_MAX); + cost[src] = 0; + while (!pq.empty()) + { + auto pnt = pq.top().second; + pq.pop(); + for (auto x : newAdj[pnt]) + { + if (x.second + cost[pnt] < cost[x.first]) + { + cost[x.first] = x.second + cost[pnt]; + pq.push({cost[x.first], x.first}); } } } - cout<<"Minimum cost required "<>n>>e; + cin >> n >> e; vector adj[n]; - for(int i=0;i>u>>v; + for (int i = 0; i < e; i++) + { + int u, v; + cin >> u >> v; adj[u].push_back(v); } - int src,dest; - cin>>src>>dest; - solve(src,dest,adj,n); + int src, dest; + cin >> src >> dest; + solve(src, dest, adj, n); return 0; } \ No newline at end of file diff --git a/heap/a.out b/heap/a.out new file mode 100755 index 0000000..89468a5 Binary files /dev/null and b/heap/a.out differ diff --git a/stack/maxHist.cpp b/stack/maxHist.cpp new file mode 100644 index 0000000..f3b8a34 --- /dev/null +++ b/stack/maxHist.cpp @@ -0,0 +1,53 @@ +/*Easy logic just find nsl and nsr and then compute the area*/ +#include +using namespace std; +long long getMaxArea(long long arr[], int n) +{ + // Your code here + vector nsl(n), nsr(n); + stack> st, st1; + for (int i = n - 1; i >= 0; i--) + { + while (!st.empty() && st.top().first >= arr[i]) + { + st.pop(); + } + if (st.empty()) + { + nsr[i] = n; + } + else + { + nsr[i] = st.top().second; + } + st.push({arr[i], i}); + } + + for (int i = 0; i < n; i++) + { + while (!st1.empty() && st1.top().first >= arr[i]) + { + st1.pop(); + } + if (st1.empty()) + { + nsl[i] = -1; + } + else + { + nsl[i] = st1.top().second; + } + st1.push({arr[i], i}); + } + long long int ans = INT_MIN; + for (int i = 0; i < n; i++) + { + ans = max(ans, arr[i] * (nsr[i] - nsl[i] + 1 - 2)); + // cout< +using namespace std; +int main() +{ + string s1, s2; + cin >> s1 >> s2; + int n = s1.size(), m = s2.size(); + map mp1, mp2; + for (auto x : s2) + mp2[x]++; + int rmct = 0, mct = 0; + for (auto x : mp2) + { + rmct += x.second; + } + int left = 0, right = 0; + string ans = ""; + while (true) + { + bool f1 = false, f2 = false; + // cout << "Aquiring\n"; + while (right < n && mct < rmct) + { + mp1[s1[right]]++; + if (mp1[s1[right]] <= mp2[s1[right]]) + { + mct++; + } + string temp = s1.substr(left, right - left + 1); + cout << temp << endl; + right++; + f1 = true; + } + + // cout<<"Releasing\n"; + while (left < right && mct == rmct) + { + string temp = s1.substr(left, right - 1 - left + 1); + cout << temp << endl; + if (ans.size() == 0 || ans.size() > temp.size()) + { + ans = temp; + } + + if (mp1[s1[left]] == 1) + { + mp1.erase(s1[left]); + } + else + { + mp1[s1[left]]--; + } + if (mp1[s1[left]] < mp2[s1[left]]) + { + mct--; + } + left++; + f2 = true; + } + if (!f1 && !f2) + break; + } + cout << ans << endl; + return 0; +} \ No newline at end of file