Skip to content

Instantly share code, notes, and snippets.

View prateek27's full-sized avatar

Prateek Narang prateek27

View GitHub Profile
#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;
#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;
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])
{
#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;
#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
#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;
}
}
#include<iostream>
#include<cstring>
using namespace std;
char* mystrtok( char str[], char delim){
static char*input = NULL;
if(str!=NULL)
{
input = str;
#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){
#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
#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