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> | |
using namespace std; | |
int findPivot(int a[],int s,int e){ | |
if(s>e){ | |
return -1; | |
} | |
while(s<=e){ | |
int mid = (s+e)/2; |
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> | |
using namespace std; | |
int search(int a[],int s,int e,int key){ | |
if(s>e){ | |
return -1; | |
} | |
int mid = (s+e)/2; |
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 search(int arr[], int l, int h, int key) | |
{ | |
if (l > h) return -1; | |
int mid = (l+h)/2; | |
if (arr[mid] == key) return mid; | |
/* If arr[l...mid] is sorted */ | |
if (arr[l] <= arr[mid]) | |
{ |
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> | |
using namespace std; | |
int median(int *arr1,int *arr2,int n){ | |
int lo1 = 0,hi1 = n-1; | |
int lo2 = 0,hi2 = n-1; | |
if(n == 1){ | |
return (arr1[0] + arr2[0]) >> 1; |
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> | |
using namespace std; | |
bool solveMaze(char maze[][10],int sol[][10],int i,int j,int m,int n){ | |
///Base Case | |
if(i==m && j==n){ | |
sol[i][j] = 1; | |
///Print the soln |
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> | |
using namespace std; | |
bool canPlace(int mat[][9],int x,int y,int val){ | |
///Check along row | |
for(int i=0;i<9;i++){ | |
if(mat[x][i]==val){ | |
return false; | |
} | |
} |
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<cstring> | |
using namespace std; | |
char* mystrtok( char str[], char delim){ | |
static char*input = NULL; | |
if(str!=NULL) | |
{ | |
input = str; |
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> | |
using namespace std; | |
float binarySqRoot(int no,int p=2){ | |
int s=0,e=no; | |
float ans; | |
///Binary Search for Integer Part | |
while(s<=e){ |
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<climits> | |
using namespace std; | |
int query(int *tree,int index,int s,int e,int qs,int qe){ | |
///No Overlap | |
if(qs>e || qe<s){ | |
return INT_MAX; | |
} | |
///Complete Overlap |
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> | |
using namespace std; | |
int knapsack(int wts[],int prices[],int N,int W){ | |
///Base Case | |
if(N==0||W==0){ | |
return 0; | |
} | |
///Rec Case |