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
// C++ program to merge two sorted arrays with O(1) extra space. | |
#include <bits/stdc++.h> | |
using namespace std; | |
// Merge ar1[] and ar2[] with O(1) extra space | |
void merge(int ar1[], int ar2[], int m, int n) | |
{ | |
// Iterate through all elements of ar2[] starting from | |
// the last element | |
for (int i=n-1; i>=0; 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
//#include <iostream> | |
#include<bits/stdc++.h> | |
using namespace std; | |
bool comparator(string first,string second) | |
{ | |
string one = first+second; | |
string two = second+first; | |
int i=0; |
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
// A Stack based C++ program to find next | |
// greater element for all array elements. | |
#include <bits/stdc++.h> | |
using namespace std; | |
/* prints element and NGE pair for all | |
elements of arr[] of size n */ | |
void printNGE(int arr[], int n) { | |
stack < int > s; |
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
// CPP program to check for balanced parenthesis. | |
#include<bits/stdc++.h> | |
using namespace std; | |
// function to check if paranthesis are balanced | |
bool areParanthesisBalanced(string expr) | |
{ | |
stack<char> s; | |
char x; |
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
// C++ program to find circular tour for a truck | |
#include <bits/stdc++.h> | |
using namespace std; | |
// A petrol pump has petrol and distance to next petrol pump | |
class petrolPump | |
{ | |
public: | |
int petrol; | |
int distance; |
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<iostream> | |
#include<stdlib.h> | |
using namespace std; | |
/* A simple stack class with basic stack funtionalities */ | |
class Stack | |
{ | |
private: | |
static const int max = 100; |
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
// C++ program to implement a stack that supports | |
// getMinimum() in O(1) time and O(1) extra space. | |
#include <bits/stdc++.h> | |
using namespace std; | |
// A user defined stack that supports getMin() in | |
// addition to push() and pop() | |
struct MyStack | |
{ | |
stack<int> s; |
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
// We can use stl container list as a double | |
// ended queue to store the cache keys, with | |
// the descending time of reference from front | |
// to back and a set container to check presence | |
// of a key. But to fetch the address of the key | |
// in the list using find(), it takes O(N) time. | |
// This can be optimized by storing a reference | |
// (iterator) to each key in a hash map. | |
#include <bits/stdc++.h> | |
using namespace std; |
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
// C++ program to find minimum time required to make all | |
// oranges rotten | |
#include<bits/stdc++.h> | |
#define R 3 | |
#define C 5 | |
using namespace std; | |
// function to check whether a cell is valid / invalid | |
bool isvalid(int i, int j) | |
{ |
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
// A C++ program to find first | |
// non-repeating character | |
// from a stream of characters | |
#include <iostream> | |
#define MAX_CHAR 256 | |
using namespace std; | |
// A linked list node | |
struct node { | |
char a; |