This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution{ | |
public: | |
// arr[]: Input Array | |
// N : Size of the Array arr[] | |
// Function to count inversions in the array. | |
void mergesort(long long arr[], long long temp[], long long int l, long long int r, long long int inv){ | |
if(l<r){ | |
long long int mid = (l+r)/2; | |
inv += mergesort(a,temp, l, mid,inv); | |
inv += mergesort(a,temp, mid+1, r,inv); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<vector<int>> merge(vector<vector<int>>& intervals) { | |
sort( intervals.begin(), intervals.end()); | |
vector<vector<int>>ans; | |
int l = intervals[0][0]; | |
int r = intervals[0][1]; | |
int n = intervals.size(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int findDuplicate(vector<int>& v) { | |
set<int> s; | |
int n= v.size(); int ans; | |
for(int i=0; i<n; i++){ | |
if(s.find(v[i]) == s.end()){ | |
s.insert(v[i]); | |
} | |
else{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#define int long long int | |
using namespace std; | |
void solve(){ | |
int n; | |
cin>>n; | |
while(true){ | |
int a[n]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution{ | |
public: | |
//Function to find starting point where the truck can start to get through | |
//the complete circle without exhausting its petrol in between. | |
int tour(petrolPump p[],int n) | |
{ | |
//Your code here | |
int fuel=0, st=0, shortage =0,i; | |
for(i=0; i<n; ++i){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queue<int> rev(queue<int> q) | |
{ | |
// add code here. | |
int n = q.size(); | |
stack<int> s; | |
while (!q.empty()) { | |
s.push(q.front()); | |
q.pop(); | |
} | |
while (!s.empty()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int curr=0; queue<int> q1, q2; | |
//Function to push an element into stack using two queues. | |
void QueueStack :: push(int x) | |
{ | |
// Your Code | |
q2.push(x); | |
curr++; | |
while(!q1.empty()){ | |
q2.push(q1.front()); | |
q1.pop(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int findMaxLen(string A) { | |
// code here | |
int left = 0, right = 0, ans = 0, n = A.size(); | |
for(int i = 0; i < n; ++i){ | |
if(A[i] == '(') | |
++left; | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<vector<int>> merge(vector<vector<int>>& intervals) { | |
sort(intervals.begin(),intervals.end()); | |
stack<vector<int>> st; | |
int n = intervals.size(); | |
st.push({ intervals[0].first, intervals[0].second }); | |
for(int i=1; i<n; i++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void insertatbottom(stack<int>&s, int ele){ | |
if(s.empty() || s.top() <= ele ){ | |
s.push(ele); | |
return; | |
} | |
int temp = s.top(); | |
s.pop(); | |
insertatbottom(s,ele); |
NewerOlder