Skip to content

Commit

Permalink
updt.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanaSabuj committed Apr 4, 2020
1 parent 66fc687 commit 95f8c86
Show file tree
Hide file tree
Showing 64 changed files with 3,034 additions and 0 deletions.
59 changes: 59 additions & 0 deletions HackerEarth/Adjacencylist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<iostream >
#include < vector >

using namespace std;

vector <int> adj[10];


vector <int> v[10] ; //Vector for maintaining adjacency list explained above
int level[10]; //To determine the level of each node
bool vis[10]; //Mark the node if visited
void bfs(int s) {
queue <int> q;
q.push(s);
level[ s ] = 0 ; //Setting the level of the source node as 0
vis[ s ] = true;
while(!q.empty())
{
int p = q.front();
q.pop();
for(int i = 0;i < v[ p ].size() ; i++)
{
if(vis[ v[ p ][ i ] ] == false)
{
//Setting the level of each node with an increment in the level of parent node
level[ v[ p ][ i ] ] = level[ p ]+1;
q.push(v[ p ][ i ]);
vis[ v[ p ][ i ] ] = true;
}
}
}
}




int main()
{
int x, y, nodes, edges;
cin >> nodes; //Number of nodes
cin >> edges; //Number of edges
for(int i = 0;i < edges;++i)
{
cin >> x >> y;
adj[x].push_back(y); //Insert y in adjacency list of x
}
for(int i = 1;i <= nodes;++i)
{
cout << "Adjacency list of node " << i << ": ";
for(int j = 0;j < adj[i].size();++j)
{
if(j == adj[i].size() - 1)
cout << adj[i][j] << endl;
else
cout << adj[i][j] << " --> ";
}
}
return 0;
}
46 changes: 46 additions & 0 deletions HackerEarth/Graphs/Monk at the Graph Factory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<bits/stdc++.h>
using namespace std;

#define double long double

#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopb(i,a,b) for(int i=a;i>=b;i--)
#define loopm(i,a,b,step) for(int i=a;i<b;i+=step)
#define loopbm(i,a,b,step) for(int i=a;i>=b;i-=step)

#define pb push_back
#define init(arr,val) memset(arr,val,sizeof(arr))
#define endl "\n"

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

int main(){
_;

//Code goes here

int n;
cin>>n;
int sum=0;

loop(i,0,n)
{
int x;
cin>>x;

sum+=x;


}

int total= 2*(n-1);
if(sum==total)
std::cout << "Yes" << endl;
else
std::cout << "No" << endl;



return 0;
}
36 changes: 36 additions & 0 deletions HackerEarth/Graphs/Monk in the Real Estate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
using namespace std;


int main() {
// cout<<"GfG!";

int t;
cin>>t;



while(t--)
{

int n,x,y;
cin>>n;
std::set<int> s ;

for (int i = 0; i < n; i++) {
/* code */
cin>>x>>y;
s.insert(x);
s.insert(y);

}


std::cout << s.size() << std::endl;



}

return 0;
}
2 changes: 2 additions & 0 deletions HackerEarth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# HackerEarth-problems
Solutions to hackerearth practice problems , topic-wise
55 changes: 55 additions & 0 deletions Hackerrank/10 Days of Statistics/Day 0 - Mean Median Mode .cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin>>n;

vector<int> vec(n);
int total = 0;

for(int i = 0; i < n; i++){
cin>>vec[i];
total += vec[i];
}

sort(vec.begin(), vec.end());

float avg = (float)total / n;
cout << fixed << showpoint << setprecision(1) <<avg <<endl;

float median ;
if(n & 1)
median = vec[(n)/ 2];
else {
median = (float)(vec[(n-1)/2] + vec[(n-1)/2 + 1])/2;
}

cout << fixed << showpoint << setprecision(1) << median <<endl;

int ans = 0;
int val ;

map<int,int> mp;
for(auto x: vec)
mp[x]++;

for(auto x: mp){
if(x.second > ans){
ans = x.second;
val = x.first;
}
}

cout << fixed << showpoint << setprecision(1) << val <<endl;

return 0;
}
37 changes: 37 additions & 0 deletions Hackerrank/10 Days of Statistics/Day 0 - Weighted Mean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <iomanip>
using namespace std;

// To execute C++, please define "int main()"
int main() {

int n;
cin>>n;

int x[n];
for(int i = 0; i < n; i++){
cin>>x[i];
}

int w[n];
for(int i = 0; i < n; i++){
cin>>w[i];
}

int totW = 0;
int totWX = 0;
for(int i = 0; i < n; i++){
totWX += w[i] * x[i];
totW += w[i];
}

double ans = (double) totWX / totW ;

cout << fixed << showpoint << setprecision(1) << ans <<endl;



return 0;
}


71 changes: 71 additions & 0 deletions Hackerrank/Algorithms/AppendAndDelete.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define dbg(x) cerr << #x << " = " << x << endl
#define endl "\n"
#define int long long int
#define double long double
#define pb push_back
#define mp make_pair
#define PI acos(-1)

//const int INF=1e9+5;//billion
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89};
string alpha = "abcdefghijklmnopqrstuvwxyz";
/*----------JU IS LOVE----------*/
//int power(int a,int b,int m){int ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
//int power(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a;b/=2;a=a*a;}return ans;}


signed main() {

freopen("input.txt", "r", stdin);
crap;

string s1, s2;
int k;
cin >> s1 >> s2 >> k;

int c = 0; //common letters

for (int i = 0; i < min(s1.length(), s2.length()) ; i++) {

if (s1[i] == s2[i])
c++;
else
break;

}

int x = s1.length() - c; // uncommon letters to be deleted in s1
int y = s2.length() - c; // uncommon letters to be added to s1

bool isYes = false;
if ( k >= (x + y) and k <= (x + y + 2 * c)) {
if ( (k - (x + y)) % 2 == 0) {
isYes = true;

}
} else if ( k > (x + y + 2 * c)) {
isYes = true;
}

if (isYes)
cout << "Yes" << endl;
else
cout << "No" << endl;



return 0;
}




74 changes: 74 additions & 0 deletions Hackerrank/Algorithms/DP/Equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define dbg(x) cerr << #x << " = " << x << endl
#define endl "\n"
#define int long long int
#define double long double
#define pb push_back
#define mp make_pair
#define PI acos(-1)

//const int INF=1e9+5;//billion
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89};
string alpha = "abcdefghijklmnopqrstuvwxyz";
/*----------JU IS LOVE----------*/
//int power(int a,int b,int m){int ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
//int power(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a;b/=2;a=a*a;}return ans;}


signed main() {

freopen("input.txt", "r", stdin);
crap;

int t;
cin >> t;

while (t--) {
int n;
cin >> n;

int arr[n];
for (int i = 0; i < n; ++i)
{
/* code */
cin >> arr[i];
}

sort(arr, arr + n);

int mini = arr[0];
// +1, +2, +5
int ans = LLONG_MAX;
for (int x = mini - 4; x <= mini; x++) {

int k=0;
for (int i = 0; i < n; ++i)
{
/* code */
int t = arr[i] - x;
k += t/5 + (t%5)/2 + (t%5)%2 ;
}

ans = min(ans, k);

}

cout<<ans<<endl;
}



return 0;
}




Binary file added Hackerrank/Algorithms/DP/LCS
Binary file not shown.
Loading

0 comments on commit 95f8c86

Please sign in to comment.