├── _config.yml ├── .DS_Store ├── Problem-Solving-Algorithms ├── .DS_Store ├── Solve me first.txt ├── Plus Minus.txt ├── Arrays.txt ├── Kangaroo.txt ├── Simple Array Sum.txt ├── a very big sum.txt ├── Lonely Integers.txt ├── Staircase.txt ├── Maximizing XOR.txt ├── Compare The Triplets.txt ├── Arrays 2D.txt ├── Birthday Cake Candles.txt ├── Divisible Sum Pair.txt ├── Diagonal Difference.txt ├── Mini Max.txt └── Sherlock And Array.txt ├── README.md └── #define /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MukulCode/HackerRank-Solutions-/HEAD/.DS_Store -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MukulCode/HackerRank-Solutions-/HEAD/Problem-Solving-Algorithms/.DS_Store -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Solve me first.txt: -------------------------------------------------------------------------------- 1 | Problem Name: Solve Me First 2 | Difficilty: Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || \/ || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int solveMeFirst(int a, int b) { 20 | return a+b; 21 | 22 | } 23 | 24 | int main() { 25 | int num1,num2; 26 | scanf("%d %d",&num1,&num2); 27 | int sum; 28 | sum = solveMeFirst(num1,num2); 29 | printf("%d",sum); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HackerRank-Solutions 2 | Explanations of questions taken from HackerRank.com 3 | 4 | 5 | Competitive coding questions collection 🔥 6 | 7 | :octocat: Here is the collection of questions hackerrank implemented by me in C/C++💻 8 | 9 | 10 | Getting Started ✔️ 11 | :octocat: Fork the repository and get your own copy of these solved coding questions collection. 12 | :octocat: Try out the questions on different outputs. 13 | 14 | 15 | Contribute ??? ✔️ 16 | Fork the repository 17 | Make the commits 18 | Submit a pull request. 19 | :octocat: If you find any better approach then make a pull request.I will surely merge it after a review. 20 | 21 | :octocat: You can also make a pull request if you solved the question with same approach as above but in programming language other than C++/C. 22 | 23 | Prerequisites ✔️ 24 | :octocat: You can just run these codes on any IDEs like netbeans,eclipse or any online ide. 25 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Plus Minus.txt: -------------------------------------------------------------------------------- 1 | Problem Name: Plus Minus 2 | Difficulty: Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || \/ || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | 14 | 15 | 16 | #include 17 | using namespace std; 18 | 19 | 20 | int main() 21 | { 22 | float a,n,p=0,i,q=0,r=0; 23 | cin>>n; 24 | for (int i = 0; i < n; i++) { 25 | cin>>a; 26 | if(a>0)p++; 27 | else if (a<0)q++; 28 | else if(a==0)r++; 29 | } 30 | 31 | cout<

16 | #include 17 | using namespace std; 18 | vector split_string(string); 19 | 20 | // Complete the reverseArray function below. 21 | void reverseArray(vector a) { 22 | for(int i=a.size()-1;i>=0;i--) 23 | cout< m; 30 | int temp, n; 31 | cin>>n; 32 | for(int i=0;i>temp; 34 | m.push_back(temp);} 35 | reverseArray(m); 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Kangaroo.txt: -------------------------------------------------------------------------------- 1 | Problem Name: Kangaroo 2 | Problem Difficulty : Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || \/ || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | char* readline(); 24 | char** split_string(char*); 25 | 26 | 27 | int main() 28 | { 29 | int v1,v2,x1,x2,m,p,q; 30 | scanf("%d%d%d%d",&x1,&v1,&x2,&v2); 31 | 32 | if((v1>v2)&&((x1-x2)%(v1-v2)==0)) printf("YES"); 33 | else 34 | printf("NO"); 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Simple Array Sum.txt: -------------------------------------------------------------------------------- 1 | Problem name: Simple Array Sum. 2 | DIfficulty: Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || \/ || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | 25 | int main() 26 | { 27 | int n,i,sum=0,a[1000]; 28 | /* choosen an array of 1000 elements to fulfill all test cases*/ 29 | scanf("%d",&n); 30 | for(i=0;i 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | int main() 25 | { 26 | long long int n,i,k,ar[100],suma=0; 27 | scanf("%lli",&n); 28 | 29 | 30 | for(int i=0;i 17 | using namespace std; 18 | vector split_string(string); 19 | 20 | // Complete the lonelyinteger function below. 21 | void lonelyinteger(vector arr) { 22 | vector m; 23 | for(int i = 1; i < arr.size(); i++){ 24 | arr[0] = arr[0] ^ arr[i]; 25 | } 26 | cout< arr; 33 | cin>>n; 34 | for(int i=0;i>temp; 36 | arr.push_back(temp); 37 | } 38 | lonelyinteger(arr); 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Staircase.txt: -------------------------------------------------------------------------------- 1 | Problem Name : Staircase 2 | Problem Difficulty : Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || \/ || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | 27 | void staircase(int n) { 28 | 29 | 30 | } 31 | 32 | int main() 33 | { 34 | 35 | int i,j,n; 36 | scanf("%d",&n); 37 | 38 | for(i=0;i=n-1) 41 | printf("#"); 42 | else 43 | { 44 | printf(" "); 45 | } 46 | } 47 | printf("\n"); 48 | } 49 | 50 | 51 | return 0; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Maximizing XOR.txt: -------------------------------------------------------------------------------- 1 | Problem Name : Maximizing XOR 2 | Problem Difficulty : Easy 3 | 4 | /*|||||||||||||||||||||||||||||||||| 5 | || ||\ //|| || // || 6 | || ||\\ // || || // || 7 | || || \\ // || || // || 8 | || || \\// || ||// || 9 | || || || ||\\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | || || || || \\ || 13 | ||||||||||||||||||||||||||||||||||*/ 14 | 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | // Complete the maximizingXor function below. 22 | int maximizingXor(int l, int r) { 23 | vector arr; 24 | int k=0; 25 | for(int i=l;imax){max=arr[i];} 34 | 35 | return max; 36 | } 37 | 38 | int main() 39 | { 40 | int l,r,ans; 41 | cin>>l>>r; 42 | cout< 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | 30 | int main() 31 | { 32 | int a[50],b[50],i,alice=0,bob=0; 33 | for(i=0;i<3;i++) 34 | scanf("%d",&a[i]); 35 | for(i=0;i<3;i++) 36 | scanf("%d",&b[i]); 37 | for(i=0;i<3;i++) 38 | { 39 | if(a[i]b[i]) 42 | alice++; 43 | } 44 | printf("%d %d",alice,bob); 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Arrays 2D.txt: -------------------------------------------------------------------------------- 1 | PRoblem Name : 2D Array 2 | Problem Type : Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || \/ || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | 14 | 15 | #include 16 | using namespace std; 17 | 18 | int main() { 19 | int arr[6][6],sum=0,max=INT_MIN; 20 | for (int i=0;i<6;i++){ 21 | for(int j=0;j<6;j++){ 22 | cin>>arr[i][j]; 23 | } 24 | } 25 | 26 | for (int i=0;i<5;i++){ 27 | for(int j=0;j<5;j++){ 28 | if(i!=0 && j!=0){ 29 | sum=arr[i-1][j-1]+arr[i-1][j]+arr[i-1][j+1]+arr[i][j]+arr[i+1][j-1]+arr[i+1][j]+arr[i+1][j+1]; 30 | 31 | if(sum>max) max=sum; 32 | 33 | } 34 | } 35 | } 36 | 37 | 38 | cout< 17 | using namespace std; 18 | 19 | vector split_string(string); 20 | 21 | // Complete the birthdayCakeCandles function below. 22 | int birthdayCakeCandles(vector ar,int n) { 23 | int max=0,count=0; 24 | for(int i=0;i>n; 39 | vector arr; 40 | for(i=0;i>m; 42 | arr.push_back(m); 43 | } 44 | cout< 19 | using namespace std; 20 | 21 | vector split_string(string); 22 | 23 | // Complete the divisibleSumPairs function below. 24 | int divisibleSumPairs(int n, int k, vector ar) { 25 | int count=0; 26 | for(int j=0;j>n>>k; 40 | vector arr; 41 | for(int i=0;i>temp; 43 | arr.push_back(temp);} 44 | cout< 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | int main() 27 | { int sum1=0,sum2=0; 28 | int j,i,n; 29 | int m[100][100]; 30 | scanf("%d",&n); 31 | for(i=0;isum2) 44 | printf("%d",sum1-sum2); 45 | else 46 | printf("%d",sum2-sum1); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Mini Max.txt: -------------------------------------------------------------------------------- 1 | Problem Name : Mini-Max 2 | Problem Difficulty : Easy 3 | 4 | /*|||||||||||||||||||||||||||||||||| 5 | || ||\ //|| || // || 6 | || ||\\ // || || // || 7 | || || \\ // || || // || 8 | || || \\// || ||// || 9 | || || \/ || ||\\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | || || || || \\ || 13 | ||||||||||||||||||||||||||||||||||*/ 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | 26 | 27 | void swap(int *xp, int *yp) 28 | { 29 | int temp = *xp; 30 | *xp = *yp; 31 | *yp = temp; 32 | } 33 | int main() 34 | { int i, j; 35 | long sum_max=0, sum_min=0,arr[5]; 36 | for(j=0;j<5;j++) 37 | scanf("%ld",&arr[j]); 38 | 39 | for (i = 0; i < 5; i++){ 40 | for (j = 0; j < 5-i-1; j++){ 41 | if (arr[j] > arr[j+1]) 42 | swap(&arr[j], &arr[j+1]); 43 | } 44 | } 45 | for(i=0;i<4;i++) 46 | sum_min+=arr[i]; 47 | for(i=1;i<5;i++) 48 | sum_max+=arr[i]; 49 | 50 | printf("%ld",sum_min); 51 | printf(" "); 52 | printf("%ld",sum_max); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /#define: -------------------------------------------------------------------------------- 1 | /*|||||||||||||||||||||||||||||||||| 2 | || ||\ //|| || // || 3 | || ||\\ // || || // || 4 | || || \\ // || || // || 5 | || || \\// || ||// || 6 | || || \/ || ||\\ || 7 | || || || || \\ || 8 | || || || || \\ || 9 | || || || || \\ || 10 | ||||||||||||||||||||||||||||||||||*/ 11 | 12 | #include 13 | #define MOD 1000000007 14 | #define test int t; cin>>t; while(t--) 15 | #define init(arr,val) memset(arr,val,sizeof(arr)) 16 | #define loop(i,a,b) for(int i=a;i=b;i--) 18 | #define loops(i,a,b,step) for(int i=a;i=b;i-=step) 20 | #define ull unsigned long long int 21 | #define ll long long int 22 | #define P pair 23 | #define PLL pair 24 | #define PII pair 25 | #define PUU pair 26 | #define L list 27 | #define V vector 28 | #define D deque 29 | #define ST set 30 | #define MS multiset 31 | #define M map 32 | #define UM unordered_map 33 | #define mp make_pair 34 | #define pb push_back 35 | #define pf push_front 36 | #define MM multimap 37 | #define F first 38 | #define S second 39 | #define IT iterator 40 | #define RIT reverse_iterator 41 | #define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie(); 42 | #define FILE_READ_IN freopen("input.txt","r",stdin); 43 | #define FILE_READ_OUT freopen("output.txt","w",stdout); 44 | #define MAXN 25 45 | 46 | 47 | //Now I don't think they are important 48 | -------------------------------------------------------------------------------- /Problem-Solving-Algorithms/Sherlock And Array.txt: -------------------------------------------------------------------------------- 1 | Problem Name: Sherlock And Array 2 | Difficulty : Easy 3 | /*|||||||||||||||||||||||||||||||||| 4 | || ||\ //|| || // || 5 | || ||\\ // || || // || 6 | || || \\ // || || // || 7 | || || \\// || ||// || 8 | || || || ||\\ || 9 | || || || || \\ || 10 | || || || || \\ || 11 | || || || || \\ || 12 | ||||||||||||||||||||||||||||||||||*/ 13 | #include 14 | using namespace std; 15 | 16 | string ltrim(const string &); 17 | string rtrim(const string &); 18 | vector split(const string &); 19 | 20 | // Complete the balancedSums function below. 21 | string balancedSums(vector arr) { 22 | int sum=0; 23 | int lsum=0; 24 | int n=arr.size(); 25 | for(int i=0;i arr_temp = split(rtrim(arr_temp_temp)); 60 | 61 | vector arr(n); 62 | 63 | for (int i = 0; i < n; i++) { 64 | int arr_item = stoi(arr_temp[i]); 65 | 66 | arr[i] = arr_item; 67 | } 68 | 69 | string result = balancedSums(arr); 70 | 71 | fout << result << "\n"; 72 | } 73 | 74 | fout.close(); 75 | 76 | return 0; 77 | } 78 | 79 | string ltrim(const string &str) { 80 | string s(str); 81 | 82 | s.erase( 83 | s.begin(), 84 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) 85 | ); 86 | 87 | return s; 88 | } 89 | 90 | string rtrim(const string &str) { 91 | string s(str); 92 | 93 | s.erase( 94 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 95 | s.end() 96 | ); 97 | 98 | return s; 99 | } 100 | 101 | vector split(const string &str) { 102 | vector tokens; 103 | 104 | string::size_type start = 0; 105 | string::size_type end = 0; 106 | 107 | while ((end = str.find(" ", start)) != string::npos) { 108 | tokens.push_back(str.substr(start, end - start)); 109 | 110 | start = end + 1; 111 | } 112 | 113 | tokens.push_back(str.substr(start)); 114 | 115 | return tokens; 116 | } 117 | --------------------------------------------------------------------------------