Skip to content

Commit

Permalink
Merge pull request Kvaibhav01#5 from CruiseDevice/master
Browse files Browse the repository at this point in the history
some of the solutions for algorithms problem from hackerearth
  • Loading branch information
Kvaibhav01 authored Oct 3, 2018
2 parents be0e36f + ed01e8b commit 1084d2c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Algorithms/C++/Graph/edge_existence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
You have been given an undirected graph consisting of N nodes and M
edges. This graph can consist of self-loops as well as multiple edges.
In addition , you have also been given Q queries. For each query , you
shall be given 2 integers A and B. You just need to find if there exists
an edge between node A and node B. If yes, print "YES" (without quotes)
else , print "NO"(without quotes).
*/
#include <iostream>
using namespace std;
int arr[1000][1000];
void initialize(){
for(int i = 0; i < 1000; i++){
for(int j = 0; j < 1000; j++){
arr[i][j] = false;
}
}
}
int main(){

int x,y,n,m,q;
initialize();
cin >> n >> m;
for(int i = 0 ; i < m; i++){
cin >> x >> y;
arr[x][y] = true;
}
cin >> q;
for(int i = 0; i < q; i ++){
cin >> x >> y;
if(arr[x][y]== true){
cout << "YES"<<"\n";
}else{
cout << "NO"<<"\n";
}
}
return 0;
}
35 changes: 35 additions & 0 deletions Algorithms/C++/Greedy Algorithms/Being_greedy_for_water.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
You are given container full of water. Container can have limited amount
of water. You also have N bottles to fill. You need to find the maximum
numbers of bottles you can fill.
*/
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 100000;
int A[MAX];
int main(){
int T;
cin >> T;
while(T--){

int N,Capacity;
cin >> N >> Capacity;
int numberBottles = 0, numberOfBottles = 0;
for(int i = 0; i < N; i++){
cin >> A[i];
}
sort(A,A+N);
for(int i = 0; i < N; i++){
numberBottles += A[i];
if(numberBottles > Capacity){
break;
}else{
numberOfBottles++;
}
}
cout << numberOfBottles << "\n";

}
return 0;
}

0 comments on commit 1084d2c

Please sign in to comment.