Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kabirrajsingh committed Jun 5, 2022
1 parent 44c1d82 commit 3d7acb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions duplicateinarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <bits/stdc++.h>
int findDuplicate(vector<int> &arr, int n){
// Write your code here.
sort(arr.begin(),arr.end());
for(int i=0;i<n;i++){
if(i!=n-1 && arr[i]==arr[i+1]){
return arr[i];
break;
}
}
return -1;
}
15 changes: 15 additions & 0 deletions searchin2dmatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <bits/stdc++.h>
#include <vector>
#include<iostream>
using namespace std;
bool findTargetInMatrix(vector < vector < int >> & mat, int m, int n, int target) {
// Write your code here.
int i=0,j=n-1;
while(i<m && j>=0){
// cout<<mat[i]<<mat[j]<<i<<j<<endl;
if(mat[i][j]==target){return true;break;}
else if(mat[i][j]>target){j--;}
else{i++;}
}
return false;
}

0 comments on commit 3d7acb3

Please sign in to comment.