diff --git a/CompetitvePrograms/cavitymaphackerrank.cpp b/CompetitvePrograms/cavitymaphackerrank.cpp new file mode 100644 index 00000000..33d811ca --- /dev/null +++ b/CompetitvePrograms/cavitymaphackerrank.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +int main() +{ + int n,**arr; + cin>>n; + arr=new int*[n]; + for(int i=0;i>s; + for(int j=0;jarr[i-1][j]&&arr[i][j]>arr[i][j-1]&&arr[i][j]>arr[i+1][j]&&arr[i][j]>arr[i][j+1]) + cout<<"X"; + else cout< + +using namespace std; + +int main() +{ + int c,r; + int *coins,**arr; + cin>>c>>r; + coins=new int[r]; + + arr=new int*[r+1]; + for(int i=0;i>coins[i]; + arr[i+1][0]=coins[i]; + } + for(int i=1;i +using namespace std; +bool canConstruct(string ransomNote, string magazine) + { + int count=ransomNote.length(),j,i; + for( i=0;i>r>>m; + cout< +#include +using namespace std; +int findComplement(int num) + { + int count=0,sum=0; + while(num>0) + { + if(num%2==0) + sum+=pow(2,count); + num/=2; + count++; + } + return sum; + } +int main() +{ + int n; + cin>>n; + cout< +using namespace std; + + int firstUniqChar(string s) + { + int arr[26]={0}; + for(int i=0;i>s; + cout< +#include +using namespace std; + int majorityElement(vector nums) + { + + int arr[1000]={0},i; + for( i=0;i=0;j--) + if(nums[j]=nums[i]) + continue; + + for(int j=i+1;jnums.size()/2) + return nums[i]; + } + return nums[i]; + } +int main() +{ + vector arr(0); + arr.push_back(10); + arr.push_back(9); + arr.push_back(9); + + arr.push_back(9); + arr.push_back(10); + cout< +#include +using namespace std; +int main() +{ + int n,o,row,col,max; + int **board; + cin>>n>>o; + board=new int*[n]; + for(int i=0;i>row>>col; + board[row-1][col-1]=2; + // if((row-1==0&&col-1==0)||(row-1==0&&col-1==n-1)||(row-1==n-1&&col-1==0)||(row-1==n-1&&col-1==n-1)) + if(row-1==0||col-1==0||row-1==n-1||col-1==n-1) + max=(n-1)*3; + + while(o--) + { + cin>>row>>col; + board[row-1][col-1]=1; + } + +} diff --git a/CompetitvePrograms/testFunctions.cpp b/CompetitvePrograms/testFunctions.cpp new file mode 100644 index 00000000..a59734c4 --- /dev/null +++ b/CompetitvePrograms/testFunctions.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +using namespace std; +void show(int arr[],int n) +{ + for(int i=0;i +#include +#include +#include +using namespace std; +struct node +{ + struct node *leftChild; + int data; + struct node *rightChild; +}; +struct node *root=NULL; +//int const MAX=100; +int MAX=100; +struct node *sta[100]; +int top=-1,leftheight=0,rightheight=0; +void push(struct node *ptr); +struct node *pop(); +void preorder(struct node* ptr); +void display(struct node *ptr); +struct node *create(); +void inorder(struct node* ptr); +bool c=true; +int co=0; +struct node *check(struct node *ptr,int count,int element) + { + cout<<" count : "<data==element) + return ptr; + struct node* parent=ptr; + struct node* ch=check(ptr->leftChild,count+1,element); + if(ch!=NULL&&c==true) + { + c=false; + return parent; + } + if(c) + { + parent=ptr; + ch=check(ptr->rightChild,count+1,element); + if(ch!=NULL&&c==true) + { + c=false; + return parent; + } + } + + return ch; + } + bool isCousins(struct node *ptr, int x, int y) + { + int co1,co2; + co=0; + c=true; + struct node *n=check(ptr,0,x); + co1=co; + co=0; + c=true; + struct node *m=check(ptr,0,y); + co2=co; + if(co1==co2&&n->data!=m->data) + return true; + else return false; + } +/*int heightofleftsubtree(struct node* ptr) +{ + if(ptr==NULL) + return 0; + while(ptr->leftChild!=NULL) + { + ptr=ptr->leftChild; + leftheight++; + } + if(ptr->rightChild==NULL) + return leftheight; + else heightofleftsubtree(ptr->rightChild); +} +int heightofrightsubtree(struct node* ptr) +{ + if(ptr==NULL) + return 0; + while(ptr->rightChild!=NULL) + { + ptr=ptr->rightChild; + rightheight++; + } + if(ptr->leftChild==NULL) +}*/ +void push(struct node *ptr) +{ + if(top==(MAX-1)) + { + printf("Stack OverFlow\n"); + return; + } + else sta[++top]=ptr; +} + +struct node *pop() +{ + if(top==-1) + { + printf("Stack UnderFlow"); + exit(0); + } + else return sta[top--]; +} +int main() +{ + root=create(); + printf("Preorder traversal of tree : "); + inorder(root); + cout<<"Enter the element to check : "; + int a; + cin>>a; + c=true; + struct node *ptr=check(root,0,a); + cout<data<<" "<data); + display(ptr->leftChild); + display(ptr->rightChild); +} +void preorder(struct node* ptr) +{ + if(ptr==NULL) + { + printf("Tree is empty!"); + return; + } + push(ptr); + while(top!=-1); + { + ptr=pop(); + printf("%d ",ptr->data); + if(ptr->rightChild!=NULL) + push(ptr->rightChild); + if(ptr->leftChild!=NULL) + push(ptr->leftChild); + } +} +void inorder(struct node* ptr) +{ + if(ptr==NULL) + { + printf("Tree is empty!"); + return; + } + while(1) + { + while(ptr->leftChild!=NULL) + { + push(ptr); + ptr=ptr->leftChild; + } + while(ptr->rightChild==NULL) + { + printf("1 test ptr->left =%u ptr->right=%u ptr->info=%d \n",ptr->leftChild,ptr->rightChild,ptr->data); + printf("loop In %d \n",ptr->data); + if(top==-1) + return; + ptr=pop(); + } + printf("test ptr->left =%u ptr->right=%u ptr->info=%d \n",ptr->leftChild,ptr->rightChild,ptr->data); + printf("In %d \n",ptr->data); + ptr=ptr->rightChild; + printf("test ptr->left =%u ptr->right=%u ptr->info=%d \n",ptr->leftChild,ptr->rightChild,ptr->data); + } +} +struct node *create() +{ + struct node *temp=NULL; + int x; + printf("Enter the data(0 for no node) : "); + scanf("%d",&x); + if(x==0) + return NULL; + temp=(struct node*)malloc(sizeof(struct node)); + temp->data=x; + printf("Enter the Left Child Of %d : \n",x); + temp->leftChild=create(); + + printf("Enter the Right Child Of %d : \n",x); + temp->rightChild=create(); + + return temp; +}