This file contains 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++ linear time solution for stock span problem | |
#include <iostream> | |
#include <stack> | |
using namespace std; | |
// A stack based efficient method to calculate | |
// stock span values | |
void calculateSpan(int price[], int n, int S[]) | |
{ | |
// Create a stack and push index of first |
This file contains 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> | |
using namespace std; | |
void findMajority(int arr[], int n) | |
{ | |
// Number of bits in the integer | |
int len = sizeof(int) * 8; | |
// Variable to calculate majority element | |
int number = 0; |
This file contains 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
// Program to find minimum number of platforms | |
// required on a railway station | |
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
// Returns minimum number of platforms reqquired | |
int findPlatform(int arr[], int dep[], int n) | |
{ |
This file contains 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
/* Following program is a C++ implementation of Rabin Karp | |
Algorithm given in the CLRS book */ | |
#include <bits/stdc++.h> | |
using namespace std; | |
// d is the number of characters in the input alphabet | |
#define d 256 | |
/* pat -> pattern | |
txt -> text |