├── .github ├── issue_template.md └── pull_request_template.md ├── C++ ├── 01. Introduction │ ├── Arrays Introduction.cpp │ ├── Basic Data Types.cpp │ ├── Conditional Statements.cpp │ ├── For Loop.cpp │ ├── Functions.cpp │ ├── Input and Output.cpp │ ├── Pointer.cpp │ ├── Say_Hello_World_With_C++.cpp │ └── Variable Sized Arrays.cpp ├── 02. Strings │ ├── Attribute Parser.cpp │ ├── StringStream.cpp │ └── Strings.cpp ├── 03. Classes │ ├── BoxIt.cpp │ ├── Class.cpp │ └── Structs.cpp ├── 04. STL │ ├── Deque-STL.cpp │ ├── Lower Bound-STL.cpp │ ├── Maps-STL.cpp │ ├── Sets-STL.cpp │ ├── Vector Erase STL.cpp │ └── Vector-Sort.cpp ├── 05. Inheritance │ ├── Accessing Inherited Functions.cpp │ ├── Multi_Level_Inheritance.cpp │ └── Rectangle Area.cpp ├── 06. Debugging │ ├── CPP Exception Handling.cpp │ └── Overloading Ostream Operator.cpp ├── 07. Other Concepts │ └── Operator Overloading.cpp └── STL │ └── vector-sort.cpp ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Java ├── 01. Introduction │ ├── Currency Formatter.java │ ├── Java Datatypes.java │ ├── Java Date and Time.java │ ├── Java If-Else.java │ ├── Java Int to String.java │ ├── Java Loops II.java │ ├── Java Static initializer block.java │ ├── Java Stdin and Stdout I.java │ ├── Java Stdin and Stdout II.java │ └── Welcome To Java.java ├── 02. Strings │ ├── Java Anagrams.java │ ├── Java Substring.java │ └── Java_Int_to_String.java ├── 03. BigNumber │ └── dummy.java ├── 04. Data Structures │ ├── Java 1D Array.java │ └── Java Stack.java ├── 05.Java_Sort │ └── Java_sort.java ├── Object Oriented Programming │ ├── Java Abstract Class.java │ ├── Java Inheritance I.java │ ├── Java Inheritance II.java │ ├── Java Interface.java │ └── Java Method Overriding.java └── sorting │ ├── bubblesort.java │ ├── countingsort.java │ ├── insertionsort.java │ └── selectionsort.java ├── LICENSE ├── Problem Solving ├── Algorithms │ ├── Bit Manipulation │ │ └── Maximizing_XOR.cpp │ ├── Dynamic Programming │ │ ├── Equal │ │ │ └── Equal.cpp │ │ ├── Stock Maximize │ │ │ └── Stock Maximize.cpp │ │ └── The Coin Change Problem │ │ │ └── The Coin Change Problem.cpp │ ├── Recursion │ │ ├── Crossword Puzzle │ │ │ └── dummy.py │ │ ├── Recursive Digit Sum │ │ │ ├── Recursive Digit Sum.cpp │ │ │ ├── Recursive Digit Sum.java │ │ │ └── Recursive Digit Sum.py │ │ └── The Power Sum │ │ │ ├── dummy.cpp │ │ │ └── power.py │ └── Searching │ │ └── Array Solution │ │ └── Array Solution.cpp └── Data Structures │ ├── Array │ └── Left Rotation │ │ └── Left Rotation.java │ └── Stacks │ └── Balanced Brackets │ └── Balanced Brackets.cpp ├── Python ├── 01. Introduction │ ├── Loops.py │ ├── Python Division.py │ ├── Python If-Else.py │ └── Write a function.py ├── 02. Basic Data Types │ ├── Find the Runner-Up Score.py │ ├── Finding The Percentage.py │ └── List Comprehensions.py ├── 03. Strings │ ├── StringValidators.py │ ├── dummy.py │ └── sWAP_cASE.py ├── 04. Sets │ └── No Idea!.py └── Debugging │ └── Words Score.py ├── README.md └── SQL ├── 1. BASIC SELECT ├── 01. Revising the Select Query I.sql ├── 02. Revising the Select Query II.sql ├── 03. Select All.sql ├── 04. Select By ID.sql ├── 05. Japanese Cities' Attributes.sql ├── 06. Japanese Cities' Names.sql ├── 07. Weather Observation Station 1.sql ├── 08. Weather Observation Station 3.sql ├── 09. Weather Observation Station 4.sql ├── 10. Weather Observation Station 5.sql ├── 11. Weather Observation Station 6.sql ├── 12. Weather Observation Station 7.sql ├── 13. Weather Observation Station 8.sql ├── 14. Weather Observation Station 9.sql ├── 15. Weather Observation Station 10.sql ├── 16. Weather Observation Station 11.sql ├── 17. Weather Observation Station 12.sql ├── 18. Higher Than 75 Marks.sql ├── 19. Employee Names.sql └── 20. Employee Salaries.sql ├── 2. ADVANCED SELECT ├── 01.Type of Triangle.sql ├── 02. The PADS.sql ├── 03. Occupations.sql ├── 04. Binary Tree Nodes.sql └── 05. New Companies.sql ├── 3. AGGREGATION ├── 01.Revising Aggregations - The Count Function.sql ├── 02. Revising Aggregations - The Sum Function.sql ├── 03. Revising Aggregations - Averages.sql ├── 04. Average Population.sql ├── 05. Japan Population.sql ├── 06. Population Density Difference.sql ├── 07. The Blunder.sql ├── 08. Top Earners.sql ├── 09. Weather Observation Station 2.sql ├── 10. Weather Observation Station 13.sql ├── 11. Weather Observation Station 14.sql ├── 12. Weather Observation Station 15.sql ├── 13. Weather Observation Station 16.sql ├── 14. Weather Observation Station 17.sql ├── 15. Weather Observation Station 18.sql ├── 16. Weather Observation Station 19.sql └── 17. Weather Observation Station 20.sql ├── 4. BASIC JOIN ├── 01. Population Census.sql ├── 02. African Cities.sql ├── 03. Average Population of Each Continent.sql ├── 04. The Report.sql ├── 05. Top Competitors.sql ├── 06. Ollivander's Inventory.sql ├── 07. Challenges.sql └── 08. Contest Leaderboard.sql ├── 5. ADVANCED JOIN ├── 01. SQL Project Planning.sql ├── 02. SQL Symmetric Pairs.sql ├── 03. 15 Days of Learning SQL.sql └── Interviews.sql └── 6. ALTERNATIVE QUERIES ├── 01. Draw The Triangle 1.sql └── 02. Draw The Triangle 2.sql /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ### Hackerrank problem link 2 | 3 | Provide your hackerrank problem link here. 4 | 5 | ### Language 6 | 7 | If you are contributing to data structures or algorithms problem, which programming language will you use? 8 | 9 | ### Issue Checklist 10 | 11 | * [ ] Have you checked that the hackerrank problem you are raising is not already present in the repo? 12 | * [ ] Have you checked that the hackerrank problem you are raising is not raised by or assigned to another contributor? 13 | * [ ] Have you read the [CONTRIBUTING.md](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/CONTRIBUTING.md) file? 14 | 15 | ### Any other Changes? 16 | 17 | If you are raising an issue with some more changes, please provide the details here. 18 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Issue Number: 2 | 3 | This submission closes # issue 4 | 5 | ### Submissions Checklist: 6 | 7 | 9 | 10 | * [ ] This issue was assigned to you. 11 | * [ ] Have you followed the guidelines in [CONTRIBUTING.md](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/CONTRIBUTING.md)? 12 | * [ ] Have you checked there aren't other open [Pull Requests](https://github.com/Riddhi9570/HackerrankPracticeProblems/pulls) for the same hackerrank problem? 13 | * [ ] Have you successfully submitted your code in hackerrank? 14 | * [ ] Is your file name exactly same as the problem name of hackerrank, followed by the proper extension? 15 | * [ ] Have you ensured that you have put the files in appropriate folders? (Folders are made according to the subdomain of hackerrank practice problems). 16 | 17 | ### Hackerrank Problem Link: 18 | 19 | 20 | 21 | ### Submitted Hackerrank Solution Link: 22 | 23 | 24 | 25 | ### Any other changes you made or something you would like to mention? 26 | 27 | 28 | -------------------------------------------------------------------------------- /C++/01. Introduction/Arrays Introduction.cpp: -------------------------------------------------------------------------------- 1 | // below is the solution to arrays introduction problem: https://www.hackerrank.com/challenges/arrays-introduction/problem?isFullScreen=true 2 | // Score:10 3 | // Difficulty: Easy 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char const *argv[]) 9 | { 10 | int N; 11 | cin>>N; //taking N as input 12 | int arr[N]; //declaring an array of size N 13 | for(int i=0;i>arr[i]; //taking input the elements of the array 15 | } 16 | for(int i=N-1;i>=0;i--){ 17 | cout< 19 | #include 20 | using namespace std; 21 | 22 | int main() { 23 | int a; 24 | long long int b; 25 | char c; 26 | float d; 27 | double e; 28 | 29 | scanf("%d %lld %c %f %lf",&a,&b,&c,&d,&e); 30 | printf("%d\n%lld\n%c\n%f\n%lf",a,b,c,d,e); 31 | 32 | // you can also use the below code to take input and give output 33 | 34 | // cin>>a>>b>>c>>d>>e; 35 | // cout< 6 | 7 | using namespace std; 8 | 9 | //defines functions 10 | string ltrim(const string &); 11 | string rtrim(const string &); 12 | 13 | 14 | 15 | int main() 16 | { 17 | string n_temp; 18 | //gets input as a string 19 | getline(cin, n_temp); 20 | 21 | //trims all trailing whitespaces and gives integer form of input 22 | int n = stoi(ltrim(rtrim(n_temp))); 23 | 24 | // Write your code here 25 | // if-else if statements to check which number it is, else statement if it is greater than 9 26 | 27 | if(n==1){ 28 | cout << "one"; 29 | } 30 | else if(n==2){ 31 | cout << "two"; 32 | } 33 | else if(n==3){ 34 | cout << "three"; 35 | } 36 | else if(n==4){ 37 | cout << "four"; 38 | } 39 | else if(n==5){ 40 | cout << "five"; 41 | } 42 | else if(n==6){ 43 | cout << "six"; 44 | } 45 | else if(n==7){ 46 | cout << "seven"; 47 | } 48 | else if(n==8){ 49 | cout << "eight"; 50 | } 51 | else if(n==9){ 52 | cout << "nine"; 53 | } 54 | else{ 55 | cout << "Greater than 9"; 56 | } 57 | 58 | return 0; 59 | } 60 | 61 | string ltrim(const string &str) { 62 | string s(str); 63 | 64 | s.erase( 65 | s.begin(), 66 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) 67 | ); 68 | 69 | return s; 70 | } 71 | 72 | string rtrim(const string &str) { 73 | string s(str); 74 | 75 | s.erase( 76 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 77 | s.end() 78 | ); 79 | 80 | return s; 81 | } 82 | -------------------------------------------------------------------------------- /C++/01. Introduction/For Loop.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link :https://www.hackerrank.com/challenges/c-tutorial-for-loop/problem 2 | //Difficulty : Easy 3 | //Max Score:10 4 | #include 5 | using namespace std; 6 | int main() { 7 | // taking input of a ,b 8 | int a,b; 9 | cin>>a>>b; 10 | // initializing vector of strings named hashmap to store word value of 1 to 9 int values 11 | vectorhashmap{"one","two","three","four","five","six","seven","eight","nine"}; 12 | // making a for loop from a to b and checking if i is between i to 9 then preint corresponding word value of i 13 | // if i is greater than i then check if i is even or odd. 14 | for(int i=a;i<=b;i++) 15 | { 16 | if(1<=i and i<=9) 17 | { 18 | cout< 6 | using namespace std; 7 | 8 | int max_of_four(int a, int b, int c, int d) { 9 | return max(a, max(b, max(c, d))); 10 | } 11 | 12 | int main() { 13 | int a, b, c, d; 14 | cin>>a>>b>>c>>d; 15 | int ans = max_of_four(a, b, c, d); 16 | cout< 6 | using namespace std; 7 | 8 | int main() { 9 | int a,b,c; 10 | cin>>a>>b>>c; 11 | cout<<(a+b+c); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /C++/01. Introduction/Pointer.cpp: -------------------------------------------------------------------------------- 1 | // # Problem : https://www.hackerrank.com/challenges/c-tutorial-pointer/problem 2 | // # Score : 10.0 3 | // # Difficulty : Easy 4 | 5 | #include 6 | #include 7 | 8 | void update(int *a, int *b) 9 | { 10 | int temp_a = *a; 11 | int temp_b = *b; 12 | *a = temp_a + temp_b; 13 | *b = abs(temp_a - temp_b); 14 | } 15 | 16 | int main() 17 | { 18 | int a, b; 19 | int *pa = &a, *pb = &b; 20 | 21 | scanf("%d %d", &a, &b); 22 | update(pa, pb); 23 | printf("%d\n%d", a, b); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C++/01. Introduction/Say_Hello_World_With_C++.cpp: -------------------------------------------------------------------------------- 1 | // Problem : https://www.hackerrank.com/challenges/cpp-hello-world/problem 2 | // Score: 5.0 3 | // Difficulty : Easy 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | cout << "Hello, World!"; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C++/01. Introduction/Variable Sized Arrays.cpp: -------------------------------------------------------------------------------- 1 | //Hackerrank Problem link: https://www.hackerrank.com/challenges/variable-sized-arrays/problem 2 | //Score: 30.0 3 | //Difficulty level: Easy 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | 13 | int main() { 14 | int n,q; 15 | cin>>n>>q; 16 | vector> varlength; 17 | for(int i=0;i>len; 20 | vector curind(len); 21 | for(int j=0;j>curind[j]; 23 | } 24 | varlength.push_back(curind); 25 | } 26 | while(q--){ 27 | int outerind,innerind; 28 | cin>>outerind>>innerind; 29 | cout< 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | #include 15 | 16 | 17 | 18 | int main() { 19 | 20 | int n, q,i; 21 | cin>>n>>q; 22 | string temp; 23 | vector hrml; 24 | vector quer; 25 | cin.ignore(); 26 | for(i=0;i m; 37 | vector tag; 38 | for(i=0;i' ),temp.end()); 43 | if(temp.substr(0,2)==">ch>>t1>>p1>>ch>>v1; 55 | string temp1=""; 56 | if(tag.size()>0) 57 | { 58 | temp1=*tag.rbegin(); 59 | temp1=temp1+"."+t1; 60 | } 61 | else 62 | temp1=t1; 63 | tag.push_back(temp1); 64 | m[*tag.rbegin()+"~"+p1]=v1; 65 | while(ss) 66 | { 67 | ss>>p1>>ch>>v1; 68 | m[*tag.rbegin()+"~"+p1]=v1; 69 | } 70 | } 71 | } 72 | for(i=0;i 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | vector parseInts(string str) { 11 | // Complete this function 12 | stringstream ss(str); 13 | vectorans; 14 | string t; 15 | while(getline(ss,t,',')) 16 | { 17 | ans.push_back(stoi(t)); 18 | } 19 | return ans; 20 | } 21 | 22 | int main() { 23 | string str; 24 | cin >> str; 25 | vector integers = parseInts(str); 26 | for(int i = 0; i < integers.size(); i++) { 27 | cout << integers[i] << "\n"; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C++/02. Strings/Strings.cpp: -------------------------------------------------------------------------------- 1 | // problem: https://www.hackerrank.com/challenges/c-tutorial-strings/submissions/code/293651711 2 | // Score: 10.0 3 | // Difficulty: Easy 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | 12 | string a; 13 | string b; 14 | 15 | cin >> a; 16 | cin >> b; 17 | 18 | cout << a.length() << " " << b.length() << endl; 19 | string c = a + b; 20 | cout << c << endl; 21 | string temp; 22 | temp = a[0]; 23 | a[0] = b[0]; 24 | b[0] = temp[0]; 25 | cout << a << " " << b; 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++/03. Classes/BoxIt.cpp: -------------------------------------------------------------------------------- 1 | // Program Link: https://www.hackerrank.com/challenges/box-it/problem?isFullScreen=true 2 | // Problem: Box It! 3 | // Language: C++ 4 | // Subdomain: Class 5 | // Max Score: 30 6 | // Difficulty: Easy 7 | 8 | #include 9 | 10 | using namespace std; 11 | class Box 12 | { 13 | int l, b, h; 14 | 15 | public: 16 | Box() 17 | { 18 | l = 0; 19 | b = 0; 20 | h = 0; 21 | } 22 | Box(int length, int breadth, int height) 23 | { 24 | l = length; 25 | b = breadth; 26 | h = height; 27 | } 28 | Box(Box &B) 29 | { 30 | l = B.l; 31 | b = B.b; 32 | h = B.h; 33 | } 34 | 35 | int getLength() 36 | { 37 | return l; 38 | } 39 | int getBreadth() 40 | { 41 | return b; 42 | } 43 | int getHeight() 44 | { 45 | return h; 46 | } 47 | long long CalculateVolume() 48 | { 49 | return (long long)l * b * h; 50 | } 51 | bool operator<(const Box &b2) 52 | { 53 | Box b1; 54 | if (l < b2.l || (b < b2.b && l == b2.l) || (h < b2.h && b == b2.b && l == b2.l)) 55 | { 56 | return true; 57 | } 58 | 59 | return false; 60 | } 61 | friend ostream &operator<<(ostream &os, Box &B); 62 | }; 63 | ostream &operator<<(ostream &os, Box &B) 64 | { 65 | os << B.l << " " << B.b << " " << B.h; 66 | return os; 67 | } 68 | 69 | void check2() 70 | { 71 | int n; 72 | cin >> n; 73 | Box temp; 74 | for (int i = 0; i < n; i++) 75 | { 76 | int type; 77 | cin >> type; 78 | if (type == 1) 79 | { 80 | cout << temp << endl; 81 | } 82 | if (type == 2) 83 | { 84 | int l, b, h; 85 | cin >> l >> b >> h; 86 | Box NewBox(l, b, h); 87 | temp = NewBox; 88 | cout << temp << endl; 89 | } 90 | if (type == 3) 91 | { 92 | int l, b, h; 93 | cin >> l >> b >> h; 94 | Box NewBox(l, b, h); 95 | if (NewBox < temp) 96 | { 97 | cout << "Lesser\n"; 98 | } 99 | else 100 | { 101 | cout << "Greater\n"; 102 | } 103 | } 104 | if (type == 4) 105 | { 106 | cout << temp.CalculateVolume() << endl; 107 | } 108 | if (type == 5) 109 | { 110 | Box NewBox(temp); 111 | cout << NewBox << endl; 112 | } 113 | } 114 | } 115 | 116 | int main() 117 | { 118 | check2(); 119 | } -------------------------------------------------------------------------------- /C++/03. Classes/Class.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/challenges/c-tutorial-class/problem 2 | // Difficulty: Easy 3 | // Max Score: 10 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | class Student { 10 | int age; 11 | int standard; 12 | string first_name; 13 | string last_name; 14 | 15 | public: 16 | void set_age(int age_) { age = age_; } 17 | 18 | void set_standard(int standard_) { standard = standard_; } 19 | 20 | void set_first_name(string first_name_) { first_name = first_name_; } 21 | 22 | void set_last_name(string last_name_) { last_name = last_name_; } 23 | 24 | int get_age() { return age; } 25 | 26 | int get_standard() { return standard; } 27 | 28 | string get_first_name() { return first_name; } 29 | 30 | string get_last_name() { return last_name; } 31 | 32 | string to_string() { 33 | string age_ = std::to_string(age); 34 | string standard_ = std::to_string(standard); 35 | string result = 36 | age_ + "," + first_name + "," + last_name + "," + standard_; 37 | return result; 38 | } 39 | }; 40 | 41 | int main() { 42 | int age, standard; 43 | string first_name, last_name; 44 | 45 | cin >> age >> first_name >> last_name >> standard; 46 | 47 | Student st; 48 | st.set_age(age); 49 | st.set_standard(standard); 50 | st.set_first_name(first_name); 51 | st.set_last_name(last_name); 52 | 53 | cout << st.get_age() << "\n"; 54 | cout << st.get_last_name() << ", " << st.get_first_name() << "\n"; 55 | cout << st.get_standard() << "\n"; 56 | cout << "\n"; 57 | cout << st.to_string(); 58 | 59 | return 0; 60 | } -------------------------------------------------------------------------------- /C++/03. Classes/Structs.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/challenges/c-tutorial-struct/problem 2 | // Difficulty: Easy 3 | // Max Score: 10 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | struct Student { 13 | int age; 14 | string first_name; 15 | string last_name; 16 | int standard; 17 | }; 18 | 19 | int main() { 20 | Student st; 21 | 22 | cin >> st.age >> st.first_name >> st.last_name >> st.standard; 23 | cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C++/04. STL/Deque-STL.cpp: -------------------------------------------------------------------------------- 1 | // # Problem : https://www.hackerrank.com/challenges/deque-stl/problem?isFullScreen=false 2 | // # Score : 50 3 | // # Difficulty : Medium 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | void printKMax(int arr[], int n, int k){ 10 | //Write your code here. 11 | 12 | //variable for the max element in the current k elements 13 | int maxim = 0; 14 | 15 | //create a deque to see current k elements 16 | deque curr; 17 | 18 | //get first k elements and put them in the deque 19 | for(int i=0;imaxim){ 22 | maxim = arr[i]; 23 | } 24 | } 25 | 26 | cout << maxim << " "; 27 | 28 | int i = k; 29 | while(ii-k;j--){ 37 | if(arr[j]>maxim){ 38 | maxim = arr[j]; 39 | } 40 | } 41 | } 42 | 43 | //remove last element and add current element 44 | curr.pop_front(); 45 | curr.push_back(arr[i]); 46 | 47 | //checks if current added element is greater than the current max 48 | if(arr[i]>maxim){ 49 | maxim = arr[i]; 50 | } 51 | 52 | //prints the current max element 53 | cout << maxim << " "; 54 | 55 | //increments the current index we are on 56 | i++; 57 | } 58 | 59 | cout << endl; 60 | 61 | } 62 | 63 | int main(){ 64 | 65 | int t; 66 | cin >> t; 67 | while(t>0) { 68 | int n,k; 69 | cin >> n >> k; 70 | int i; 71 | int arr[n]; 72 | for(i=0;i> arr[i]; 74 | printKMax(arr, n, k); 75 | t--; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /C++/04. STL/Lower Bound-STL.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | -- # Problem Link : https://www.hackerrank.com/challenges/cpp-lower-bound/problem?isFullScreen=true 4 | -- # Problem : Lower Bound-STL 5 | -- # Language : C++ 6 | -- # Subdomain : STL 7 | -- # Max Score : 15 8 | -- # Difficulty : Easy 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | 19 | int main() { 20 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; 21 | vector vec; 22 | cin >> n; 23 | for (int i = 0; i < n; i++) { 24 | int temp; 25 | cin >> temp; 26 | vec.push_back(temp); 27 | } 28 | int q; 29 | cin >> q; 30 | for (int i = 0; i < q; i++) { 31 | int temp; 32 | cin >> temp; 33 | vector::iterator iter; 34 | iter = lower_bound(vec.begin(), vec.end(), temp); 35 | if (*(iter + 1) == temp || *iter == temp) 36 | cout << "Yes " << iter - vec.begin() + 1 << endl; 37 | else 38 | cout << "No " << iter - vec.begin() + 1 << endl; 39 | } 40 | return 0; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /C++/04. STL/Maps-STL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | -- # Problem Link : https://www.hackerrank.com/challenges/cpp-maps/problem?isFullScreen=true 3 | -- # Problem : Maps-STL 4 | -- # Language : C++ 5 | -- # Subdomain : STL 6 | -- # Max Score : 15 7 | -- # Difficulty : Easy 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | int main() 20 | { 21 | ios::sync_with_stdio(0); 22 | cin.tie(0); 23 | 24 | int a, b, c; 25 | map student; 26 | cin >> a; 27 | for (int i = 0; i < a; i++) 28 | { 29 | string s; 30 | cin >> b; 31 | if (b == 1) 32 | { 33 | cin >> s >> c; 34 | map::iterator iter; 35 | iter = student.find(s); // if it donot find then it will store end location. 36 | if (iter != student.end()) 37 | { 38 | iter->second += c; 39 | } 40 | else 41 | { 42 | student[s] = c; 43 | } 44 | } 45 | else if (b == 2) 46 | { 47 | cin >> s; 48 | student.erase(s); 49 | } 50 | else 51 | { 52 | cin >> s; 53 | map::iterator it; 54 | it = student.find(s); 55 | if (it != student.end()) 56 | { 57 | cout << it->second << endl; 58 | } 59 | else 60 | { 61 | cout << 0 << endl; 62 | } 63 | } 64 | } 65 | return 0; 66 | } -------------------------------------------------------------------------------- /C++/04. STL/Sets-STL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem Link : https://www.hackerrank.com/challenges/cpp-sets/problem?isFullScreen=true 3 | Problem :Sets-STL 4 | Category: C++ STL 5 | Difficulty: Easy 6 | Max Score: 15 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | 17 | int main() { 18 | int q; 19 | cin>>q; 20 | sets; 21 | for(int i=0;i>y>>x; 24 | if(y==1){ 25 | s.insert(x); 26 | }else if(y==2){ 27 | s.erase(x); 28 | }else{ 29 | set::iterator itr=s.find(x); 30 | if(itr==s.end()){ 31 | cout<<"No"<<"\n"; 32 | }else{ 33 | cout<<"Yes"<<"\n"; 34 | } 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /C++/04. STL/Vector Erase STL.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Problem: https://www.hackerrank.com/challenges/vector-erase/problem 3 | // Score: 10 4 | // Difficulty : Easy 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | 14 | int main() { 15 | int size,pos,start,end,n,i,a,j; 16 | cin>>n; 17 | vectorv; 18 | for(i=0;i>a; 21 | v.push_back(a); 22 | } 23 | cin>>pos>>start>>end; 24 | v.erase(v.begin()+(pos-1)); 25 | v.erase(v.begin()+start-1,v.begin()+end-1); 26 | size=v.size(); 27 | cout<v; (creates an empty vector of integers) 11 | 12 | // Size of a vector: int size=v.size(); 13 | 14 | // Pushing an integer into a vector: v.push_back(x);(where x is an integer.The size increases by 1 after this.) 15 | 16 | // Popping the last element from the vector: v.pop_back(); (After this the size decreases by 1) 17 | 18 | // Sorting a vector: sort(v.begin(),v.end()); (Will sort all the elements in the vector) 19 | 20 | // ....................................................................................................................................... 21 | 22 | // Input Format : 23 | // The first line of the input contains N ,where N is the number of integers. The next line contains integers. 24 | 25 | // Output Format : 26 | // Print the integers in the sorted order one by one in a single line followed by a space. 27 | 28 | 29 | 30 | // Solution of the Problem : 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | using namespace std; 38 | 39 | int main() { 40 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 41 | 42 | // Taking Input of the length of the Vector Array 43 | int length; 44 | cin >> length; 45 | 46 | // Taking the Integer array vector 47 | vectorarr; 48 | 49 | // Taking input of the Array 50 | for(int i=0;i> x; 55 | arr.push_back(x); 56 | } 57 | 58 | // Now sort the vector using sort() function 59 | sort(arr.begin(),arr.end()); 60 | 61 | // Now give the output of the sorted array 62 | for(int i=0;i 9 | using namespace std; 10 | class A 11 | { 12 | public: 13 | A() 14 | { 15 | callA = 0; 16 | } 17 | 18 | private: 19 | int callA; 20 | void inc() 21 | { 22 | callA++; 23 | } 24 | 25 | protected: 26 | void func(int &a) 27 | { 28 | a = a * 2; 29 | inc(); 30 | } 31 | 32 | public: 33 | int getA() 34 | { 35 | return callA; 36 | } 37 | }; 38 | class B 39 | { 40 | public: 41 | B() 42 | { 43 | callB = 0; 44 | } 45 | 46 | private: 47 | int callB; 48 | void inc() 49 | { 50 | callB++; 51 | } 52 | 53 | protected: 54 | void func(int &a) 55 | { 56 | a = a * 3; 57 | inc(); 58 | } 59 | 60 | public: 61 | int getB() 62 | { 63 | return callB; 64 | } 65 | }; 66 | class C 67 | { 68 | public: 69 | C() 70 | { 71 | callC = 0; 72 | } 73 | 74 | private: 75 | int callC; 76 | void inc() 77 | { 78 | callC++; 79 | } 80 | 81 | protected: 82 | void func(int &a) 83 | { 84 | a = a * 5; 85 | inc(); 86 | } 87 | 88 | public: 89 | int getC() 90 | { 91 | return callC; 92 | } 93 | }; 94 | /* Accessing Inherited Functions in C++ - Hacker Rank Solution START */ 95 | class D : public A, B, C 96 | { 97 | int val; 98 | 99 | public: 100 | // Initially val is 1 101 | D() 102 | { 103 | val = 1; 104 | } 105 | // Implement this function 106 | void update_val(int new_val) 107 | { 108 | int a = new_val; 109 | while (new_val != 0) 110 | { 111 | if (val == a) 112 | break; 113 | if (new_val % 2 == 0) 114 | { 115 | A::func(val); 116 | new_val /= 2; 117 | } 118 | else if (new_val % 3 == 0) 119 | { 120 | B::func(val); 121 | new_val /= 3; 122 | } 123 | else if (new_val % 5 == 0) 124 | { 125 | C::func(val); 126 | new_val /= 5; 127 | } 128 | } 129 | } 130 | // For Checking Purpose 131 | void check(int); // Do not delete this line. 132 | }; 133 | /* Accessing Inherited Functions in C++ - Hacker Rank Solution END */ 134 | void D::check(int new_val) 135 | { 136 | update_val(new_val); 137 | cout << "Value = " << val << endl 138 | << "A's func called " << getA() << " times " << endl 139 | << "B's func called " << getB() << " times" << endl 140 | << "C's func called " << getC() << " times" << endl; 141 | } 142 | int main() 143 | { 144 | D d; 145 | int new_val; 146 | cin >> new_val; 147 | d.check(new_val); 148 | } -------------------------------------------------------------------------------- /C++/05. Inheritance/Multi_Level_Inheritance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem Link : https://www.hackerrank.com/challenges/multi-level-inheritance-cpp/problem?isFullScreen=true 3 | Problem : Multi_Level_Inheritance 4 | Category: Inheritance 5 | Difficulty: Easy 6 | Max Score: 25 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | class Triangle{ 17 | public: 18 | void triangle(){ 19 | cout<<"I am a triangle\n"; 20 | } 21 | }; 22 | 23 | class Isosceles : public Triangle{ 24 | public: 25 | void isosceles(){ 26 | cout<<"I am an isosceles triangle\n"; 27 | } 28 | }; 29 | 30 | //Write your code here. 31 | class Equilateral:public Isosceles{ 32 | public: 33 | void equilateral(){ 34 | cout<<"I am an equilateral triangle"<<"\n"; 35 | } 36 | }; 37 | int main(){ 38 | 39 | Equilateral eqr; 40 | eqr.equilateral(); 41 | eqr.isosceles(); 42 | eqr.triangle(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++/05. Inheritance/Rectangle Area.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link :https://www.hackerrank.com/challenges/rectangle-area/problem 2 | //Difficulty : Easy 3 | //Max Score:25 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | 14 | int main() { 15 | int h,w; 16 | //taking input 17 | cin>>h>>w; 18 | //print height and width 19 | cout< 9 | #include 10 | 11 | using namespace std; 12 | 13 | int largest_proper_divisor(int n) 14 | { 15 | if (n == 0) 16 | { 17 | throw invalid_argument("largest proper divisor is not defined for n=0"); 18 | } 19 | if (n == 1) 20 | { 21 | throw invalid_argument("largest proper divisor is not defined for n=1"); 22 | } 23 | for (int i = n / 2; i >= 1; --i) 24 | { 25 | if (n % i == 0) 26 | { 27 | return i; 28 | } 29 | } 30 | return -1; // will never happen 31 | } 32 | 33 | void process_input(int n) 34 | { 35 | try 36 | { 37 | int d = largest_proper_divisor(n); 38 | cout << "result=" << d << endl; 39 | } 40 | catch (exception &e) 41 | { 42 | cout << e.what() << endl; 43 | } 44 | cout << "returning control flow to caller" << endl; 45 | } 46 | 47 | int main() 48 | { 49 | int n; 50 | cin >> n; 51 | process_input(n); 52 | return 0; 53 | } -------------------------------------------------------------------------------- /C++/06. Debugging/Overloading Ostream Operator.cpp: -------------------------------------------------------------------------------- 1 | // Problem link: https://www.hackerrank.com/challenges/overloading-ostream-operator/problem?isFullScreen=true 2 | // Problem: Overloading Ostream Operator 3 | // Language: C++ 4 | // Subdomain: Debugging 5 | // Score: 20 6 | // Difficulty: Medium 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Person 13 | { 14 | public: 15 | Person(const string &first_name, const string &last_name) : first_name_(first_name), last_name_(last_name) {} 16 | const string &get_first_name() const 17 | { 18 | return first_name_; 19 | } 20 | const string &get_last_name() const 21 | { 22 | return last_name_; 23 | } 24 | 25 | private: 26 | string first_name_; 27 | string last_name_; 28 | }; 29 | ostream &operator<<(ostream &os, const Person &rhs) 30 | { 31 | os << "first_name=" << rhs.get_first_name() << ",last_name=" << rhs.get_last_name(); 32 | return os; 33 | } 34 | -------------------------------------------------------------------------------- /C++/07. Other Concepts/Operator Overloading.cpp: -------------------------------------------------------------------------------- 1 | // Problem: Operator Overloading 2 | // Problem Link: https://www.hackerrank.com/challenges/operator-overloading/problem?isFullScreen=true 3 | // Language: C++ 4 | // Difficulty: Medium 5 | // Max Score: 25 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | class Matrix 15 | { 16 | public: 17 | vector> a; 18 | 19 | Matrix(){}; 20 | 21 | Matrix operator+(const Matrix &y) 22 | { 23 | for (int i = 0; i < y.a.size(); i++) 24 | { 25 | for (int j = 0; j < y.a[0].size(); j++) 26 | { 27 | this->a[i][j] = this->a[i][j] + y.a[i][j]; 28 | } 29 | } 30 | 31 | return *this; 32 | } 33 | }; 34 | 35 | int main() 36 | { 37 | int cases, k; 38 | cin >> cases; 39 | for (k = 0; k < cases; k++) 40 | { 41 | Matrix x; 42 | Matrix y; 43 | Matrix result; 44 | int n, m, i, j; 45 | cin >> n >> m; 46 | for (i = 0; i < n; i++) 47 | { 48 | vector b; 49 | int num; 50 | for (j = 0; j < m; j++) 51 | { 52 | cin >> num; 53 | b.push_back(num); 54 | } 55 | x.a.push_back(b); 56 | } 57 | for (i = 0; i < n; i++) 58 | { 59 | vector b; 60 | int num; 61 | for (j = 0; j < m; j++) 62 | { 63 | cin >> num; 64 | b.push_back(num); 65 | } 66 | y.a.push_back(b); 67 | } 68 | result = x + y; 69 | for (i = 0; i < n; i++) 70 | { 71 | for (j = 0; j < m; j++) 72 | { 73 | cout << result.a[i][j] << " "; 74 | } 75 | cout << endl; 76 | } 77 | } 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /C++/STL/vector-sort.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | 12 | // Taking Input of the length of the Vector Array 13 | int length; 14 | cin >> length; 15 | 16 | // Taking the Integer array vector 17 | vectorarr; 18 | 19 | // Taking input of the Array 20 | for(int i=0;i> x; 25 | arr.push_back(x); 26 | } 27 | 28 | // Now sort the vector using sort() function 29 | sort(arr.begin(),arr.end()); 30 | 31 | // Now give the output of the sorted array 32 | for(int i=0;i 34 | ``` 35 | * Step 5: Commit all the changes (Write commit message as "Small Message") 36 | ``` 37 | git commit -m "Write a meaningful but small commit message" 38 | ``` 39 | * Step 6: Push the changes for review 40 | ``` 41 | git push origin 42 | ``` 43 | * Step 7: Create a PR on Github. (Don't just hit the create a pull request button, you must write a PR message to clarify why and what are you contributing) 44 | 45 | ### 🔑Guidelines 46 | 47 | Here are some set of guidelines to follow while contributing to `HackerrankPracticeProblems` : 48 | 49 | 1. Welcome to this repository, if you are here as an open-source program participant/contributor. 50 | 2. Participants/contributors have to **comment** on issues they would like to work on, and mentors or the PA will assign you. 51 | 3. Issues will be assigned on a **first-come, first-serve basis.** 52 | 4. Participants/contributors can also **open their issues**, but it needs to be verified and labelled by a mentor or PA. We respect all your contributions, whether 53 | it is an Issue or a Pull Request. 54 | 5. When you raise an issue, make sure you get it assigned to you before you start working on that project. 55 | 6. Each participant/contributor will be **assigned 1 issue (max)** at a time to work. 56 | 7. Don't create issues that are **already listed**. 57 | 8. Please don't pick up an issue already assigned to someone else. Work on the issues after it gets **assigned to you**. 58 | 9. Create your file in an appropriate folder with appropriate name and extension. 59 | 10. When you are adding solution for a hackerrank problem, add these comments at the top your solution: 60 | - `-- # Problem Link :` < problem link > 61 |
For example,
-- # Problem Link: https://www.hackerrank.com/challenges/multi-level-inheritance-cpp/problem 62 | - `-- # Problem :` < problem name > 63 |
For example,
-- # Problem : Multi Level Inheritance 64 | - `-- # Language :` < programming language > 65 |
For example,
-- # Language : C++ 66 | - `-- # Subdomain :` < subdomain of problem in hackerrank > 67 |
For example,
-- # Subdomain : Inheritance 68 | - `-- # Max Score :` < Maximum score for that problem > 69 |
For example,
-- # Max Score : 25 70 | - `-- # Difficulty :` < Easy/Medium/Hard > 71 |
For example,
-- # Difficulty : Easy 72 | 11. It would be appreciated if you add approach and notes to your solution (especially for difficult problems)- [Example 1](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/10.%20Weather%20Observation%20Station%205.sql), [Example 2](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/17.%20Weather%20Observation%20Station%2020.sql). 73 | 12. Create a pull request and also give your hackerrank submission link in the description so that it can be easily reviewed and merged. 74 | 13. Pull requests will be merged after being **reviewed** by a mentor or PA. 75 | 81 | 14. We all are here to learn. You are allowed to make mistakes. That's how you learn, right!. 82 | 83 | ### 🧲Pull Requests Review Criteria 84 | 85 | 86 | - You must add your file into the respective **folder**. 87 | - Your work must be original, written by you not copied from other resources. 88 | - You must comment on your code wherever necessary. 89 | - Follow the proper [style guides](https://google.github.io/styleguide/) for your work. 90 | - For any queries or discussions, please feel free to drop a message. 91 | 92 | ## 📖Resources 93 | 94 | 1. Markdown: Markdown is a lightweight markup language like HTML, with plain text formatting syntax. 95 | * [Markdown Cheat-Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) 96 | 97 | 2. Git: Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. 98 | * [Videos to get started](https://www.youtube.com/watch?v=xAAmje1H9YM&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW) 99 | * [Cheat Sheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet) 100 | 101 | ## 🤔Need more help? 102 | 103 | You can refer to the following articles on the basics of Git and Github and also contact me, in case you are stuck: 104 | - [Forking a Repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) 105 | - [Cloning a Repo](https://help.github.com/en/desktop/contributing-to-projects/creating-an-issue-or-pull-request) 106 | - [How to create a Pull Request](https://opensource.com/article/19/7/create-pull-request-github) 107 | - [Getting started with Git and GitHub](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6) 108 | - [Learn GitHub from Scratch](https://lab.github.com/githubtraining/introduction-to-github) 109 | 110 | ## 😇Tip from me 111 | 112 | It always takes time to understand and learn. So, do not worry at all. I know you can do this**!💪 113 | 114 | ### [![Typing SVG](https://readme-typing-svg.herokuapp.com/?lines=Thanks+for+contributing!;&size=30)](https://git.io/typing-svg) 115 | -------------------------------------------------------------------------------- /Java/01. Introduction/Currency Formatter.java: -------------------------------------------------------------------------------- 1 | // Problem - https://www.hackerrank.com/challenges/java-currency-formatter/problem?isFullScreen=true 2 | // Score - 15 3 | // Difficulty - Easy 4 | 5 | import java.util.*; 6 | import java.text.*; 7 | 8 | public class Currencyformatter { 9 | 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | //Input 13 | System.out.print("Enter amount: "); 14 | double payment = scanner.nextDouble(); 15 | scanner.close(); 16 | 17 | Locale indiaLocale = new Locale("en", "IN"); 18 | 19 | /* Create NumberFormats using Locales */ 20 | NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US); 21 | NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale); 22 | NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA); 23 | NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE); 24 | 25 | /* Print output */ 26 | System.out.println("US: " + us.format(payment)); 27 | System.out.println("India: " + india.format(payment)); 28 | System.out.println("China: " + china.format(payment)); 29 | System.out.println("France: " + france.format(payment)); 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /Java/01. Introduction/Java Datatypes.java: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/java-datatypes/problem?isFullScreen=true 2 | // Score: 10 3 | // Difficulty: Easy 4 | 5 | 6 | import java.util.*; 7 | import java.io.*; 8 | 9 | class Solution{ 10 | public static void main(String []argh) 11 | { 12 | Scanner sc = new Scanner(System.in); 13 | int t=sc.nextInt(); 14 | for(int i=0;i=-128 && x<=127)System.out.println("* byte"); 19 | if(x>=-32768 && x<32768)System.out.println("* short"); 20 | if(x>=-Math.pow(2,31) && x<=Math.pow(2,31)-1)System.out.println("* int"); 21 | if(x>=-Math.pow(2,63) && x<=Math.pow(2,63)-1)System.out.println("* long"); 22 | } 23 | catch(Exception e) { 24 | System.out.println(sc.next()+" can't be fitted anywhere."); 25 | } 26 | } 27 | } 28 | } 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Java/01. Introduction/Java Date and Time.java: -------------------------------------------------------------------------------- 1 | // Problem - https://www.hackerrank.com/challenges/java-date-and-time/problem?isFullScreen=true 2 | // Score - 15 3 | // Difficulty - Easy 4 | 5 | import java.io.*; 6 | import java.math.*; 7 | import java.security.*; 8 | import java.text.*; 9 | import java.util.*; 10 | import java.util.concurrent.*; 11 | import java.util.function.*; 12 | import java.util.regex.*; 13 | import java.util.stream.*; 14 | import static java.util.stream.Collectors.joining; 15 | import static java.util.stream.Collectors.toList; 16 | import java.util.Calendar; 17 | class Result { 18 | 19 | /* 20 | * Complete the 'findDay' function below. 21 | * 22 | * The function is expected to return a STRING. 23 | * The function accepts following parameters: 24 | * 1. INTEGER month 25 | * 2. INTEGER day 26 | * 3. INTEGER year import java.util.Calendar; import java.util.Calendar; 27 | */ 28 | 29 | public static String findDay(int month, int day, int year) { 30 | Calendar cal=Calendar.getInstance(); 31 | String dd[]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"}; 32 | cal.set(year,month-1,day); 33 | int n=cal.get(Calendar.DAY_OF_WEEK); 34 | return dd[n-1]; 35 | } 36 | 37 | } 38 | 39 | public class Solution { 40 | public static void main(String[] args) throws IOException { 41 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 42 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 43 | 44 | String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 45 | 46 | int month = Integer.parseInt(firstMultipleInput[0]); 47 | 48 | int day = Integer.parseInt(firstMultipleInput[1]); 49 | 50 | int year = Integer.parseInt(firstMultipleInput[2]); 51 | 52 | String res = Result.findDay(month, day, year); 53 | 54 | bufferedWriter.write(res); 55 | bufferedWriter.newLine(); 56 | 57 | bufferedReader.close(); 58 | bufferedWriter.close(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Java/01. Introduction/Java If-Else.java: -------------------------------------------------------------------------------- 1 | // problem link -> https://www.hackerrank.com/challenges/java-if-else/problem 2 | // Score: 10 3 | // Difficulty : Easy 4 | 5 | 6 | 7 | import java.util.Scanner; 8 | public class if_else { 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | System.out.println("Enter the number between 1-100"); 12 | 13 | int n = in.nextInt(); 14 | String ans = ""; 15 | 16 | if(n%2!=0){ // if the value of n is odd ans = weird 17 | ans = "Weird"; 18 | } else if (n>=2 && n <= 5){ // if the value of n is between 2&5 and is even ans = not weird 19 | ans = "Not Weird"; 20 | } else if (n>=6 && n <= 20) { // if the value of n i between 6&20 and is even ans = weird 21 | ans = "Weird"; 22 | } else { // if the valur of n>20 and is even ans = not weird 23 | ans = "Not Weird"; 24 | } 25 | System.out.println(ans); 26 | } 27 | } 28 | 29 | // Method 2 : by calling a function 30 | 31 | import java.util.Scanner; 32 | public class if_else { 33 | public static void main(String[] args) { 34 | Scanner in = new Scanner(System.in); 35 | System.out.println("Enter the value of between 1-100"); 36 | int n = in.nextInt(); // taking input from the user 37 | System.out.println(check(n)); 38 | } 39 | static String check(int n) { 40 | if(n%2!=0) { // if the value of n is odd return weird 41 | return "weird"; 42 | } else if ( n>=2 && n<=5) { // if the value of n is between 2&5 and is even return not weird 43 | return "not weird"; 44 | } else if ( n>=6 && n<=20) { // if the value of n i between 6&20 and is even return weird 45 | return "weird"; 46 | } else if (n>20) { 47 | return "not weird"; // if the valur of n>20 and is even return not weird 48 | } 49 | return null; 50 | } 51 | } -------------------------------------------------------------------------------- /Java/01. Introduction/Java Int to String.java: -------------------------------------------------------------------------------- 1 | 2 | //-- # Problem : https://www.hackerrank.com/challenges/java-int-to-string/problem?isFullScreen=true 3 | 4 | //-- # Score : 10 5 | 6 | //-- # Difficulty : Easy 7 | 8 | import java.util.*; 9 | import java.security.*; 10 | public class Solution { 11 | public static void main(String[] args) { 12 | 13 | DoNotTerminate.forbidExit(); 14 | 15 | try { 16 | Scanner in = new Scanner(System.in); 17 | int n = in .nextInt(); 18 | in.close(); 19 | //this line Converts Int to String 20 | String s=Integer.toString(n); 21 | //it checks whether it was converted or not 22 | if (n == Integer.parseInt(s)) { 23 | System.out.println("Good job"); 24 | } else { 25 | System.out.println("Wrong answer."); 26 | } 27 | } catch (DoNotTerminate.ExitTrappedException e) { 28 | System.out.println("Unsuccessful Termination!!"); 29 | } 30 | } 31 | } 32 | 33 | //The following class will prevent you from terminating the code using exit(0)! 34 | class DoNotTerminate { 35 | 36 | public static class ExitTrappedException extends SecurityException { 37 | 38 | private static final long serialVersionUID = 1; 39 | } 40 | 41 | public static void forbidExit() { 42 | final SecurityManager securityManager = new SecurityManager() { 43 | @Override 44 | public void checkPermission(Permission permission) { 45 | if (permission.getName().contains("exitVM")) { 46 | throw new ExitTrappedException(); 47 | } 48 | } 49 | }; 50 | System.setSecurityManager(securityManager); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Java/01. Introduction/Java Loops II.java: -------------------------------------------------------------------------------- 1 | package Java; 2 | 3 | import java.util.Scanner; 4 | 5 | //-- # Problem : https://www.hackerrank.com/challenges/java-loops/problem?isFullScreen=true 6 | 7 | //-- # Score : 10 8 | 9 | //-- # Difficulty : Easy 10 | 11 | class Solution{ 12 | public static void main(String []argh){ 13 | Scanner in = new Scanner(System.in); 14 | int t=in.nextInt(); 15 | for(int i=0;i 2 | // Language: Java 3 | // Difficulty: Medium 4 | // Max Score: 20 5 | 6 | 7 | import java.io.*; 8 | import java.util.*; 9 | 10 | public class Solution { 11 | 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | while (sc.hasNext()) { 15 | String input = sc.next(); 16 | if (check(input)){ 17 | System.out.println("true"); 18 | } 19 | else { 20 | System.out.println("false"); 21 | } 22 | } 23 | } 24 | public static boolean check(String s){ 25 | Stack stack = new Stack(); 26 | for (int i = 0; i < s.length();i++){ 27 | if (s.charAt(i) == '(') { 28 | stack.push('('); 29 | } 30 | else if (s.charAt(i) == '{') { 31 | stack.push('{'); 32 | } 33 | else if (s.charAt(i) == '[') { 34 | stack.push('['); 35 | } 36 | else if (s.charAt(i) == ')') { 37 | if (stack.isEmpty()) { 38 | return false; 39 | } 40 | if (stack.pop() != '(') { 41 | return false; 42 | } 43 | } 44 | else if (s.charAt(i) == '}') { 45 | if (stack.isEmpty()) { 46 | return false; 47 | } 48 | if (stack.pop() != '{') { 49 | return false; 50 | } 51 | } 52 | else if (s.charAt(i) == ']') { 53 | if (stack.isEmpty()) { 54 | return false; 55 | } 56 | if (stack.pop() != '[') { 57 | return false; 58 | } 59 | } 60 | } 61 | return stack.isEmpty(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Java/05.Java_Sort/Java_sort.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | 5 | class Student implements Comparable { 6 | 7 | private int id; 8 | private String fname; 9 | private double cgpa; 10 | 11 | public Student(int id, String fname, double cgpa) { 12 | this.id = id; 13 | this.fname = fname; 14 | this.cgpa = cgpa; 15 | } 16 | 17 | public int getId() { 18 | return id; 19 | } 20 | 21 | public String getFname() { 22 | return fname; 23 | } 24 | 25 | public double getCgpa() { 26 | return cgpa; 27 | } 28 | 29 | @Override 30 | public int compareTo(Student anotherStudent) { 31 | return Comparator.comparingDouble(Student::getCgpa) 32 | .reversed() 33 | .thenComparing(Student::getFname) 34 | .thenComparingInt(Student::getId) 35 | .compare(this, anotherStudent); 36 | } 37 | } 38 | 39 | public class Solution { 40 | 41 | public static void main(String[] args) { 42 | List studentList = new ArrayList(); 43 | try (Scanner in = new Scanner(System.in)) { 44 | int testCases = Integer.parseInt(in.nextLine()); 45 | while (testCases > 0) { 46 | int id = in.nextInt(); 47 | String fname = in.next(); 48 | double cgpa = in.nextDouble(); 49 | 50 | Student student = new Student(id, fname, cgpa); 51 | studentList.add(student); 52 | 53 | testCases--; 54 | } 55 | } 56 | Collections.sort(studentList); 57 | studentList.forEach(student -> System.out.println(student.getFname())); 58 | } 59 | } -------------------------------------------------------------------------------- /Java/Object Oriented Programming/Java Abstract Class.java: -------------------------------------------------------------------------------- 1 | // Problem : https://www.hackerrank.com/challenges/java-abstract-class/problem 2 | // Max Score: 10 3 | // Difficulty: Easy 4 | // Language: Java 5 | 6 | import java.util.*; 7 | abstract class Book{ 8 | String title; 9 | abstract void setTitle(String s); 10 | String getTitle(){ 11 | return title; 12 | } 13 | } 14 | 15 | class MyBook extends Book { 16 | void setTitle(String s){ 17 | super.title = s; 18 | } 19 | } 20 | public class Main{ 21 | 22 | public static void main(String []args){ 23 | //Book new_novel=new Book(); This line prHMain.java:25: error: Book is abstract; cannot be instantiated 24 | Scanner sc=new Scanner(System.in); 25 | String title=sc.nextLine(); 26 | MyBook new_novel=new MyBook(); 27 | new_novel.setTitle(title); 28 | System.out.println("The title is: "+new_novel.getTitle()); 29 | sc.close(); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Java/Object Oriented Programming/Java Inheritance I.java: -------------------------------------------------------------------------------- 1 | // Problem : https://www.hackerrank.com/challenges/java-inheritance-1/problem 2 | // Max Score: 5 3 | // Difficulty: Easy 4 | // Language: Java 5 | 6 | import java.io.*; 7 | import java.util.*; 8 | import java.text.*; 9 | import java.math.*; 10 | import java.util.regex.*; 11 | 12 | class Animal{ 13 | void walk(){ 14 | System.out.println("I am walking"); 15 | } 16 | } 17 | 18 | class Bird extends Animal{ 19 | void fly(){ 20 | System.out.println("I am flying"); 21 | } 22 | void sing(){ 23 | System.out.println("I am singing"); 24 | } 25 | } 26 | 27 | public class Solution{ 28 | 29 | public static void main(String args[]){ 30 | 31 | Bird bird = new Bird(); 32 | bird.walk(); 33 | bird.fly(); 34 | bird.sing(); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Java/Object Oriented Programming/Java Inheritance II.java: -------------------------------------------------------------------------------- 1 | // Problem : https://www.hackerrank.com/challenges/java-inheritance-2/problem 2 | // Max Score: 10 3 | // Difficulty: Easy 4 | // Language: Java 5 | 6 | import java.io.*; 7 | import java.util.*; 8 | import java.text.*; 9 | import java.math.*; 10 | import java.util.regex.*; 11 | 12 | 13 | class Arithmetic { 14 | int add(int a , int b){ 15 | return a+b; 16 | } 17 | } 18 | class Adder extends Arithmetic{ 19 | 20 | } 21 | public class Solution{ 22 | public static void main(String []args){ 23 | // Create a new Adder object 24 | Adder a = new Adder(); 25 | 26 | // Print the name of the superclass on a new line 27 | System.out.println("My superclass is: " + a.getClass().getSuperclass().getName()); 28 | 29 | // Print the result of 3 calls to Adder's `add(int,int)` method as 3 space-separated integers: 30 | System.out.print(a.add(10,32) + " " + a.add(10,3) + " " + a.add(10,10) + "\n"); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Java/Object Oriented Programming/Java Interface.java: -------------------------------------------------------------------------------- 1 | /* Problem link -> https://www.hackerrank.com/challenges/java-interface/problem 2 | difficulty level -> easy 3 | points -> 10 4 | */ 5 | 6 | 7 | 8 | import java.util.*; 9 | interface AdvancedArithmetic{ 10 | int divisor_sum(int n); 11 | } 12 | 13 | // Main code 14 | class MyCalculator implements AdvancedArithmetic { 15 | public int divisor_sum(int n) { 16 | if (n <= 1) { return n; } 17 | 18 | int res = n + 1; 19 | for (int i = 2; i < n; i++) { 20 | if (n % i == 0) { 21 | res += i; 22 | } 23 | } 24 | 25 | return res; 26 | } 27 | } 28 | 29 | 30 | 31 | class java_interface{ // already present in hackerrank website 32 | public static void main(String []args){ 33 | MyCalculator my_calculator = new MyCalculator(); 34 | System.out.print("I implemented: "); 35 | ImplementedInterfaceNames(my_calculator); 36 | Scanner sc = new Scanner(System.in); 37 | int n = sc.nextInt(); 38 | System.out.print(my_calculator.divisor_sum(n) + "\n"); 39 | sc.close(); 40 | } 41 | /* 42 | * ImplementedInterfaceNames method takes an object and prints the name of the interfaces it implemented 43 | */ 44 | static void ImplementedInterfaceNames(Object o){ 45 | Class[] theInterfaces = o.getClass().getInterfaces(); 46 | for (int i = 0; i < theInterfaces.length; i++){ 47 | String interfaceName = theInterfaces[i].getName(); 48 | System.out.println(interfaceName); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Java/Object Oriented Programming/Java Method Overriding.java: -------------------------------------------------------------------------------- 1 | // Problem : https://www.hackerrank.com/challenges/java-method-overriding 2 | // Max Score: 10 3 | // Difficulty: Easy 4 | // Language: Java 5 | 6 | import java.util.*; 7 | class Sports{ 8 | 9 | String getName(){ 10 | return "Generic Sports"; 11 | } 12 | 13 | void getNumberOfTeamMembers(){ 14 | System.out.println( "Each team has n players in " + getName() ); 15 | } 16 | } 17 | 18 | class Soccer extends Sports{ 19 | @Override 20 | String getName(){ 21 | return "Soccer Class"; 22 | } 23 | @Override 24 | void getNumberOfTeamMembers(){ 25 | System.out.println( "Each team has 11 players in " + getName()); 26 | } 27 | 28 | } 29 | 30 | public class Solution{ 31 | 32 | public static void main(String []args){ 33 | Sports c1 = new Sports(); 34 | Soccer c2 = new Soccer(); 35 | System.out.println(c1.getName()); 36 | c1.getNumberOfTeamMembers(); 37 | System.out.println(c2.getName()); 38 | c2.getNumberOfTeamMembers(); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Java/sorting/bubblesort.java: -------------------------------------------------------------------------------- 1 | public class bubblesort { 2 | public static void bub(int arr[]) 3 | { 4 | for(int turn=0;turnarr[j+1]){ 7 | int temp=arr[j]; 8 | arr[j]=arr[j+1]; 9 | arr[j+1]=temp; 10 | } 11 | } 12 | } 13 | } 14 | public static void printarr(int arr[]){ 15 | for(int i=0;i0){ 22 | arr[j]=i; 23 | j++; 24 | count[i]--; 25 | } 26 | 27 | } 28 | } 29 | 30 | public static void main(String args[]){ 31 | int arr[] = {1,4,1,3,2,4,3,7}; 32 | 33 | count(arr); 34 | printarr(arr); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Java/sorting/insertionsort.java: -------------------------------------------------------------------------------- 1 | public class insertionsort { 2 | public static void printarr(int arr[]){ 3 | for(int i=0;i=0 && arr[prev]>curr){ 14 | arr[prev+1]=arr[prev]; 15 | prev--; 16 | } 17 | //insertion 18 | arr[prev+1]=curr; 19 | } 20 | } 21 | public static void main(String args[]){ 22 | int arr[] = {1,4,1,3,2,4,3,7}; 23 | insertion(arr); 24 | printarr(arr); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/sorting/selectionsort.java: -------------------------------------------------------------------------------- 1 | public class selectionsort { 2 | public static void printarr(int arr[]){ 3 | for(int i=0;iarr[j]){ 13 | minpos=j; 14 | } 15 | } 16 | int temp=arr[minpos]; 17 | arr[minpos]=arr[i]; 18 | arr[i]=temp; 19 | } 20 | } 21 | public static void main(String args[]){ 22 | int arr[] = {1,4,1,3,2,4,3,7}; 23 | select(arr); 24 | 25 | printarr(arr); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Riddhi Bhagat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Problem Solving/Algorithms/Bit Manipulation/Maximizing_XOR.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Maximizing_XOR 3 | Category: Bit Manipulation 4 | Difficulty: Easy 5 | Max Score: 30 6 | */ 7 | #include 8 | 9 | using namespace std; 10 | 11 | string ltrim(const string &); 12 | string rtrim(const string &); 13 | 14 | /* 15 | * Complete the 'maximizingXor' function below. 16 | * 17 | * The function is expected to return an INTEGER. 18 | * The function accepts following parameters: 19 | * 1. INTEGER l 20 | * 2. INTEGER r 21 | */ 22 | 23 | int maximizingXor(int l, int r) { 24 | vectorv; 25 | for(int i=l;i(isspace))) 64 | ); 65 | 66 | return s; 67 | } 68 | 69 | string rtrim(const string &str) { 70 | string s(str); 71 | 72 | s.erase( 73 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 74 | s.end() 75 | ); 76 | 77 | return s; 78 | } 79 | -------------------------------------------------------------------------------- /Problem Solving/Algorithms/Dynamic Programming/Equal/Equal.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link :https://www.hackerrank.com/challenges/equal/problem?isFullScreen=true 2 | // Score: 30 3 | // Difficulty: Medium 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int T, N; 11 | int d[100010]; 12 | 13 | int main() { 14 | cin >> T; 15 | assert(T <= 100); 16 | while(T--) { 17 | cin >> N; 18 | assert(N <= 10000); 19 | for(int i = 0; i < N; i++) 20 | {cin >> d[i]; assert(d[i] < 1000);} 21 | int M = *min_element(d, d + N);//finding the minimum element 22 | int r = 1e9; //just an upper limit 23 | for(int t = M - 4; t <= M; t++) { 24 | int s = 0; 25 | for(int i = 0; i < N; i++) { 26 | int D = d[i] - t; 27 | s += D / 5, D %= 5;//we are trying to find the number of times the given number be divivisible by 5->gives no of opertations 28 | s += D / 2, D %= 2;//same with 2 and 1 from the remainder 29 | s += D; 30 | } 31 | r = min(r, s); //just an upperlimit for testing 32 | } 33 | cout << r << endl; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Problem Solving/Algorithms/Dynamic Programming/Stock Maximize/Stock Maximize.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link :https://www.hackerrank.com/challenges/stockmax/problem?isFullScreen=true 2 | // Score: 50 3 | // Difficulty: Medium 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | string ltrim(const string &); 10 | string rtrim(const string &); 11 | vector split(const string &); 12 | 13 | /* 14 | * Complete the 'stockmax' function below. 15 | * 16 | * The function is expected to return a LONG_INTEGER. 17 | * The function accepts INTEGER_ARRAY prices as parameter. 18 | */ 19 | 20 | long stockmax(vector prices) { 21 | int n= prices.size(); 22 | int i; 23 | long k=0,temp=0; 24 | 25 | temp = prices[n-1]; 26 | 27 | // explanation-you are trying to move from right end to left end of the array so as to find the local maximum for that part 28 | for(i=n-1;i>=0;i--){ 29 | if(prices[i]>temp) 30 | { 31 | temp=prices[i]; 32 | } 33 | k+= temp-prices[i]; 34 | } 35 | return k; 36 | } 37 | 38 | int main() 39 | { 40 | ofstream fout(getenv("OUTPUT_PATH")); 41 | 42 | string t_temp; 43 | getline(cin, t_temp); 44 | 45 | int t = stoi(ltrim(rtrim(t_temp))); 46 | 47 | for (int t_itr = 0; t_itr < t; t_itr++) { 48 | string n_temp; 49 | getline(cin, n_temp); 50 | 51 | int n = stoi(ltrim(rtrim(n_temp))); 52 | 53 | string prices_temp_temp; 54 | getline(cin, prices_temp_temp); 55 | 56 | vector prices_temp = split(rtrim(prices_temp_temp)); 57 | 58 | vector prices(n); 59 | 60 | for (int i = 0; i < n; i++) { 61 | int prices_item = stoi(prices_temp[i]); 62 | 63 | prices[i] = prices_item; 64 | } 65 | 66 | long result = stockmax(prices); 67 | 68 | fout << result << "\n"; 69 | } 70 | 71 | fout.close(); 72 | 73 | return 0; 74 | } 75 | 76 | string ltrim(const string &str) { 77 | string s(str); 78 | 79 | s.erase( 80 | s.begin(), 81 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) 82 | ); 83 | 84 | return s; 85 | } 86 | 87 | string rtrim(const string &str) { 88 | string s(str); 89 | 90 | s.erase( 91 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 92 | s.end() 93 | ); 94 | 95 | return s; 96 | } 97 | 98 | vector split(const string &str) { 99 | vector tokens; 100 | 101 | string::size_type start = 0; 102 | string::size_type end = 0; 103 | 104 | while ((end = str.find(" ", start)) != string::npos) { 105 | tokens.push_back(str.substr(start, end - start)); 106 | 107 | start = end + 1; 108 | } 109 | 110 | tokens.push_back(str.substr(start)); 111 | 112 | return tokens; 113 | } 114 | -------------------------------------------------------------------------------- /Problem Solving/Algorithms/Dynamic Programming/The Coin Change Problem/The Coin Change Problem.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link :https://www.hackerrank.com/challenges/coin-change/problem?isFullScreen=true 2 | // Score: 60 3 | // Difficulty: Medium 4 | 5 | #include 6 | using namespace std; 7 | 8 | int c[52]; 9 | int numCoins; 10 | long long table[52][252];//memorization table 11 | bool calculated[52][252]; 12 | 13 | // this problem is solved using recurision tree method 14 | 15 | long long solve(int i, int make) 16 | { 17 | if(make<0) return 0; //exit tree-node#0 18 | if(make==0)return 1; //exit tree-node#1 19 | if(i > numCoins) return 0; 20 | if(calculated[i][make] == false){ //eliminating overlap 21 | table[i][make] = solve(i, make - c[i]) + solve(i+1, make); //recursion function //logic is you care counting minimum possible ways from scratch 22 | calculated[i][make] = true; 23 | } 24 | return table[i][make]; 25 | } 26 | int main(){ 27 | 28 | int make; 29 | cin>>make>>numCoins; 30 | for(int i=1;i<=numCoins;i++){ 31 | cin>>c[i]; 32 | } 33 | cout< 7 | 8 | using namespace std; 9 | 10 | string ltrim(const string &); 11 | string rtrim(const string &); 12 | vector split(const string &); 13 | 14 | /* 15 | * Complete the 'superDigit' function below. 16 | * 17 | * The function is expected to return an INTEGER. 18 | * The function accepts following parameters: 19 | * 1. STRING n 20 | * 2. INTEGER k 21 | */ 22 | int superDigit(string n, int k) { 23 | long super = 0; 24 | for (char& c : n) 25 | super += c - '0'; 26 | 27 | super *= k; 28 | if (super <= 9) return super; 29 | return superDigit(to_string(super), 1); 30 | } 31 | 32 | int main() 33 | { 34 | ofstream fout(getenv("OUTPUT_PATH")); 35 | 36 | string first_multiple_input_temp; 37 | getline(cin, first_multiple_input_temp); 38 | 39 | vector first_multiple_input = split(rtrim(first_multiple_input_temp)); 40 | 41 | string n = first_multiple_input[0]; 42 | 43 | int k = stoi(first_multiple_input[1]); 44 | 45 | int result = superDigit(n, k); 46 | 47 | fout << result << "\n"; 48 | 49 | fout.close(); 50 | 51 | return 0; 52 | } 53 | 54 | string ltrim(const string &str) { 55 | string s(str); 56 | 57 | s.erase( 58 | s.begin(), 59 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) 60 | ); 61 | 62 | return s; 63 | } 64 | 65 | string rtrim(const string &str) { 66 | string s(str); 67 | 68 | s.erase( 69 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 70 | s.end() 71 | ); 72 | 73 | return s; 74 | } 75 | 76 | vector split(const string &str) { 77 | vector tokens; 78 | 79 | string::size_type start = 0; 80 | string::size_type end = 0; 81 | 82 | while ((end = str.find(" ", start)) != string::npos) { 83 | tokens.push_back(str.substr(start, end - start)); 84 | 85 | start = end + 1; 86 | } 87 | 88 | tokens.push_back(str.substr(start)); 89 | 90 | return tokens; 91 | } -------------------------------------------------------------------------------- /Problem Solving/Algorithms/Recursion/Recursive Digit Sum/Recursive Digit Sum.java: -------------------------------------------------------------------------------- 1 | // Problem : https://www.hackerrank.com/challenges/recursive-digit-sum/problem 2 | // Score: 30 3 | // Difficulty : Medium 4 | 5 | import java.io.*; 6 | import java.math.*; 7 | import java.security.*; 8 | import java.text.*; 9 | import java.util.*; 10 | import java.util.concurrent.*; 11 | import java.util.function.*; 12 | import java.util.regex.*; 13 | import java.util.stream.*; 14 | import static java.util.stream.Collectors.joining; 15 | import static java.util.stream.Collectors.toList; 16 | 17 | class Result { 18 | 19 | /* 20 | * Complete the 'superDigit' function below. 21 | * 22 | * The function is expected to return an INTEGER. 23 | * The function accepts following parameters: 24 | * 1. STRING n 25 | * 2. INTEGER k 26 | */ 27 | 28 | public static int superDigit(String n, int k) { 29 | // Write your code here 30 | long s = 0L; 31 | for(int i=0;i https://www.hackerrank.com/challenges/the-power-sum/problem?h_r=profile 2 | ## Problem Name => The Power Sum 3 | ## Language => Python 4 | ## Max Score => 20 5 | ## Difficulty => Medium 6 | #!/bin/python3 7 | 8 | import math 9 | import os 10 | import random 11 | import re 12 | import sys 13 | 14 | # 15 | # Complete the 'powerSum' function below. 16 | # 17 | # The function is expected to return an INTEGER. 18 | # The function accepts following parameters: 19 | # 1. INTEGER X 20 | # 2. INTEGER N 21 | # 22 | 23 | def solution(arr,x,n): 24 | if x==0: 25 | return 1 26 | if len(arr)==0: 27 | return 0 28 | if x<0: 29 | return 0 30 | sol=solution(arr[1:],x-arr[0]**n,n)+solution(arr[1:],x,n) 31 | return sol 32 | def powerSum(X, N): 33 | baseIndex=[] 34 | for i in range(int(pow(X,(1/N)))): 35 | baseIndex.append(i+1) 36 | answer=solution(baseIndex,X,N) 37 | return answer 38 | 39 | 40 | 41 | if __name__ == '__main__': 42 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 43 | 44 | X = int(input().strip()) 45 | 46 | N = int(input().strip()) 47 | 48 | result = powerSum(X, N) 49 | 50 | fptr.write(str(result) + '\n') 51 | 52 | fptr.close() 53 | -------------------------------------------------------------------------------- /Problem Solving/Algorithms/Searching/Array Solution/Array Solution.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/sherlock-and-array/problem 2 | // Score: 40 3 | // Difficulty: Easy 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | string ltrim(const string &); 10 | string rtrim(const string &); 11 | vector split(const string &); 12 | 13 | /* 14 | * Complete the 'balancedSums' function below. 15 | * 16 | * The function is expected to return a STRING. 17 | * The function accepts INTEGER_ARRAY arr as parameter. 18 | */ 19 | 20 | string balancedSums(vector arr) { 21 | int n=arr.size(); 22 | int sum=0; 23 | for(int i=0;i arr_temp = split(rtrim(arr_temp_temp)); 58 | 59 | vector arr(n); 60 | 61 | for (int i = 0; i < n; i++) { 62 | int arr_item = stoi(arr_temp[i]); 63 | 64 | arr[i] = arr_item; 65 | } 66 | 67 | string result = balancedSums(arr); 68 | 69 | fout << result << "\n"; 70 | } 71 | 72 | fout.close(); 73 | 74 | return 0; 75 | } 76 | 77 | string ltrim(const string &str) { 78 | string s(str); 79 | 80 | s.erase( 81 | s.begin(), 82 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) 83 | ); 84 | 85 | return s; 86 | } 87 | 88 | string rtrim(const string &str) { 89 | string s(str); 90 | 91 | s.erase( 92 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 93 | s.end() 94 | ); 95 | 96 | return s; 97 | } 98 | 99 | vector split(const string &str) { 100 | vector tokens; 101 | 102 | string::size_type start = 0; 103 | string::size_type end = 0; 104 | 105 | while ((end = str.find(" ", start)) != string::npos) { 106 | tokens.push_back(str.substr(start, end - start)); 107 | 108 | start = end + 1; 109 | } 110 | 111 | tokens.push_back(str.substr(start)); 112 | 113 | return tokens; 114 | } 115 | -------------------------------------------------------------------------------- /Problem Solving/Data Structures/Array/Left Rotation/Left Rotation.java: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/challenges/array-left-rotation/problem 2 | // Problem: Left Rotation 3 | // Language: Java 4 | // Subdomain: Arrays 5 | // Difficulty: Easy 6 | // Max Score: 20 7 | 8 | import java.io.*; 9 | import java.math.*; 10 | import java.security.*; 11 | import java.text.*; 12 | import java.util.*; 13 | import java.util.concurrent.*; 14 | import java.util.function.*; 15 | import java.util.regex.*; 16 | import java.util.stream.*; 17 | import static java.util.stream.Collectors.joining; 18 | import static java.util.stream.Collectors.toList; 19 | 20 | class Result { 21 | 22 | /* 23 | * Complete the 'rotateLeft' function below. 24 | * 25 | * The function is expected to return an INTEGER_ARRAY. 26 | * The function accepts following parameters: 27 | * 1. INTEGER d 28 | * 2. INTEGER_ARRAY arr 29 | */ 30 | 31 | public static void helpRotate(int s, int e, List < Integer > arr) { 32 | while (s < e) { 33 | int temp = arr.get(s); 34 | arr.set(s, arr.get(e)); 35 | arr.set(e, temp); 36 | s++; 37 | e--; 38 | } 39 | } 40 | 41 | public static List < Integer > rotateLeft(int d, List < Integer > arr) { 42 | int n = arr.size(); 43 | d %= n; 44 | helpRotate(0, n - 1, arr); 45 | helpRotate(0, n - 1 - d, arr); 46 | helpRotate(n - d, n - 1, arr); 47 | return arr; 48 | } 49 | 50 | } 51 | 52 | public class Solution { 53 | public static void main(String[] args) throws IOException { 54 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 55 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 56 | 57 | String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 58 | 59 | int n = Integer.parseInt(firstMultipleInput[0]); 60 | 61 | int d = Integer.parseInt(firstMultipleInput[1]); 62 | 63 | List < Integer > arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 64 | .map(Integer::parseInt) 65 | .collect(toList()); 66 | 67 | List < Integer > result = Result.rotateLeft(d, arr); 68 | 69 | bufferedWriter.write( 70 | result.stream() 71 | .map(Object::toString) 72 | .collect(joining(" ")) + 73 | "\n" 74 | ); 75 | 76 | bufferedReader.close(); 77 | bufferedWriter.close(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Problem Solving/Data Structures/Stacks/Balanced Brackets/Balanced Brackets.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/challenges/balanced-brackets/problem 2 | // Problem: Balance Brackets 3 | // Language: C++ 4 | // Subdomain: Data Structures 5 | // Difficulty: Medium 6 | // Max Score: 25 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | string ltrim(const string &); 13 | string rtrim(const string &); 14 | 15 | /* 16 | * Complete the 'isBalanced' function below. 17 | * 18 | * The function is expected to return a STRING. 19 | * The function accepts STRING s as parameter. 20 | */ 21 | 22 | unordered_map mp={{'{', -3}, {'[', -2}, {'(', -1},{')', 1}, {']', 2},{'}', 3}}; 23 | 24 | string isBalanced(string s){ 25 | stack st; 26 | for(auto c: s){ 27 | if(mp[c]<0){ 28 | st.push(c); 29 | } 30 | else{ 31 | if(st.empty()) return "NO"; 32 | if(mp[st.top()]+mp[c]!=0) { 33 | return "NO"; 34 | } 35 | st.pop(); 36 | } 37 | } 38 | if(st.empty()) return "YES"; 39 | return "NO"; 40 | } 41 | int main() 42 | { 43 | ofstream fout(getenv("OUTPUT_PATH")); 44 | 45 | string t_temp; 46 | getline(cin, t_temp); 47 | 48 | int t = stoi(ltrim(rtrim(t_temp))); 49 | 50 | for (int t_itr = 0; t_itr < t; t_itr++) { 51 | string s; 52 | getline(cin, s); 53 | 54 | string result = isBalanced(s); 55 | 56 | fout << result << "\n"; 57 | } 58 | 59 | fout.close(); 60 | 61 | return 0; 62 | } 63 | 64 | string ltrim(const string &str) { 65 | string s(str); 66 | 67 | s.erase( 68 | s.begin(), 69 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) 70 | ); 71 | 72 | return s; 73 | } 74 | 75 | string rtrim(const string &str) { 76 | string s(str); 77 | 78 | s.erase( 79 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 80 | s.end() 81 | ); 82 | 83 | return s; 84 | } 85 | -------------------------------------------------------------------------------- /Python/01. Introduction/Loops.py: -------------------------------------------------------------------------------- 1 | # Solves python loops problem: https://www.hackerrank.com/challenges/python-loops/problem?isFullScreen=true 2 | # Difficulty: Easy 3 | # Max Score: 10 4 | 5 | if __name__ == '__main__': 6 | n = int(input()) #Takes input 7 | for i in range(n): #Runs the loop from 0 to n-1 8 | print(i**2) #prints their squares -------------------------------------------------------------------------------- /Python/01. Introduction/Python Division.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-division/problem?isFullScreen=true 2 | # Score: 10 3 | # dificulty: Easy 4 | 5 | if __name__ == '__main__': 6 | a = int(input()) 7 | b = int(input()) 8 | 9 | print(a//b) # integer division 10 | print(a/b) # float division 11 | -------------------------------------------------------------------------------- /Python/01. Introduction/Python If-Else.py: -------------------------------------------------------------------------------- 1 | # Hackerrank Problem link: https://www.hackerrank.com/challenges/py-if-else/problem 2 | # Score: 10.0 3 | # Difficulty: Easy 4 | 5 | import math 6 | import os 7 | import random 8 | import re 9 | import sys 10 | 11 | 12 | 13 | if __name__ == '__main__': 14 | n = int(input().strip()) 15 | if n%2==1: 16 | print("Weird") 17 | elif n%2==0 and n>=2 and n<=5: 18 | print("Not Weird") 19 | elif n%2==0 and n>=6 and n<=20: 20 | print("Weird") 21 | elif n%2==0 and n>20: 22 | print("Not Weird") 23 | -------------------------------------------------------------------------------- /Python/01. Introduction/Write a function.py: -------------------------------------------------------------------------------- 1 | # Problem : https://www.hackerrank.com/challenges/write-a-function/problem?isFullScreen=true 2 | # Score : 10 3 | # Difficulty : Medium 4 | 5 | 6 | def is_leap(year): 7 | leap = False 8 | if not year % 100 : 9 | if not year % 400 : 10 | leap = True 11 | elif not year % 4 : 12 | leap = True 13 | return leap 14 | 15 | year = int(input()) 16 | print(is_leap(year)) -------------------------------------------------------------------------------- /Python/02. Basic Data Types/Find the Runner-Up Score.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem 2 | # Score: 10 3 | # Difficulty: Easy 4 | 5 | if __name__ == '__main__': 6 | n = int(input()) 7 | arr = map(int, input().split()) 8 | 9 | list_arr = list(arr) 10 | 11 | print( 12 | max([x for x in list_arr if x != max(list_arr)]) 13 | ) 14 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/Finding The Percentage.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/finding-the-percentage/problem?isFullScreen=true 2 | # Score: 10 3 | # Difficulty : Easy 4 | 5 | if __name__ == '__main__': 6 | n = int(input()) 7 | student_marks = {} 8 | for _ in range(n): 9 | name, *line = input().split() 10 | scores = list(map(float, line)) 11 | student_marks[name] = scores 12 | query_name = input() 13 | final = list(student_marks[query_name]) 14 | percentage = sum(final)/len(final) 15 | print("%.2f" % percentage) -------------------------------------------------------------------------------- /Python/02. Basic Data Types/List Comprehensions.py: -------------------------------------------------------------------------------- 1 | # Problem : https://www.hackerrank.com/challenges/list-comprehensions/problem?isFullScreen=false 2 | # Score : 10 3 | # Difficulty : Easy 4 | 5 | if __name__ == '__main__': 6 | x = int(input()) 7 | y = int(input()) 8 | z = int(input()) 9 | n = int(input()) 10 | lst=[] 11 | for i in range(x+1): 12 | for j in range(y+1): 13 | for k in range(z+1): 14 | if(i+j+k)!=n: 15 | lst.append([i,j,k]) 16 | print(lst) -------------------------------------------------------------------------------- /Python/03. Strings/StringValidators.py: -------------------------------------------------------------------------------- 1 | 2 | //-- # Problem : https://www.hackerrank.com/challenges/string-validators/problem 3 | 4 | //-- # Score : 10 5 | 6 | //-- # Difficulty : Easy 7 | 8 | if __name__ == "__main__": 9 | s = input() 10 | #it checks all the characters of a string alphanumeric 11 | print(any(i.isalnum() for i in s)) 12 | #it checks all the characters of a string are alphabetical 13 | print(any(i.isalpha() for i in s)) 14 | #it checks all the characters of a string are digits 15 | print(any(i.isdigit() for i in s)) 16 | #it checks all the characters of a string are lowercase characters 17 | print(any(i.islower() for i in s)) 18 | #it checks all the characters of a string are uppercase characters 19 | print(any(i.isupper() for i in s)) 20 | 21 | -------------------------------------------------------------------------------- /Python/03. Strings/dummy.py: -------------------------------------------------------------------------------- 1 | # this file has ro be deleted -------------------------------------------------------------------------------- /Python/03. Strings/sWAP_cASE.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | //-- # Problem : https://www.hackerrank.com/challenges/swap-case/problem 4 | 5 | //-- # Score : 10 6 | 7 | //-- # Difficulty : Easy 8 | 9 | """ 10 | 11 | 12 | def swap_case(s): 13 | """ 14 | Swap case method: map the input string 15 | changing each letter to its opposite case, 16 | after that, convert the output to string 17 | """ 18 | return "".join(map(lambda l: l.upper() if l.islower() else l.lower(), s)) 19 | 20 | 21 | if __name__ == "__main__": 22 | s = input() 23 | result = swap_case(s) 24 | print(result) 25 | -------------------------------------------------------------------------------- /Python/04. Sets/No Idea!.py: -------------------------------------------------------------------------------- 1 | #Problem Link : https://www.hackerrank.com/challenges/no-idea/problem?isFullScreen=true 2 | # Problem : No Idea! 3 | # Language : Python 4 | # Subdomain : Sets 5 | # Max Score : 50 6 | # Difficulty : Medium 7 | 8 | io = input().split() 9 | m = int(io[0]) 10 | n = int(io[1]) 11 | 12 | storage = list() 13 | count = 0 14 | 15 | storage = list(map(int, input().strip().split())) 16 | 17 | A = set(map(int, input().strip().split())) 18 | B = set(map(int, input().strip().split())) 19 | 20 | for i in storage: 21 | if i in A: 22 | count = count+1 23 | if i in B: 24 | count = count-1 25 | 26 | print(count) 27 | -------------------------------------------------------------------------------- /Python/Debugging/Words Score.py: -------------------------------------------------------------------------------- 1 | #Problem Statement- https://www.hackerrank.com/challenges/words-score/problem 2 | #Score-10 3 | #Difficulty- Medium 4 | 5 | 6 | def is_vowel(letter): 7 | return letter in ['a', 'e', 'i', 'o', 'u', 'y'] 8 | 9 | def score_words(words): 10 | score = 0 11 | for word in words: 12 | num_vowels = 0 13 | for letter in word: 14 | if is_vowel(letter): 15 | num_vowels += 1 16 | if num_vowels % 2 == 0: 17 | score += 2 18 | else: 19 | # Words Score in Python - Hacker Rank Solution START 20 | score += 1 21 | # Words Score in Python - Hacker Rank Solution END 22 | return score 23 | 24 | 25 | n = int(input()) 26 | words = input().split() 27 | print(score_words(words)) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

3 | 4 | # Hackerrank Practice Problems 5 | 6 | - This repository contains solutions to [Hackerrank](https://Hackerrank.com) practice problems in SQL, C++, Java Python and Problem Solving (Data Structures and Algorithms). 7 | - If you are interested in adding more Hackerrank problem solutions, please feel free to contribute. 8 | - If you feel this repo is helpful for you, please do star it. 9 | - Kindly follow [CODE_OF_CONDUCT.md](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/CODE_OF_CONDUCT.md) and [CONTRIBUTING.md](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/CONTRIBUTING.md) before contributing. 10 | - Happy Coding 🥳! 11 | 12 | [![GitHub license](https://badgen.net/github/license/Naereen/Strapdown.js)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/Riddhi9570/HackerrankPracticeProblems/issues) ![Profile views](https://gpvc.arturio.dev/Riddhi9570) 13 | 14 | ### Topics 15 | 16 |
17 | 18 | SQL 19 | 20 | * [Basic Select](#basic-select) 21 | * [Advanced Select](#advanced-select) 22 | * [Aggregation](#aggregation) 23 | * [Basic Join](#basic-join) 24 | * [Advanced Join](#advanced-join) 25 | * [Alternative Queries](#alternative-queries) 26 | 27 |
28 | 29 |
30 | 31 | C++ 32 | 33 | * [Introduction](#introduction) 34 | * [Strings](#strings) 35 | * [Classes](#classes) 36 | * [STL](#stl) 37 | * [Inheritance](#inheritance) 38 | * [Debugging](#debugging) 39 | * [Other Concepts](#other-concepts) 40 | 41 |
42 | 43 |
44 | 45 | Algorithims 46 | * [Dynamic Programming](#dynamic-programming) 47 | 48 |
49 | 50 |
51 | 52 | Java 53 | 54 | * [Introduction](#introduction-1) 55 | * [Strings](#strings-1) 56 | * [BigNumber](#bignumber) 57 | * [Data Structures](#data-structures) 58 | * [Object Oriented Programming](#object-oriented-programming) 59 | * [Exception Handling](#exception-handling) 60 | * [Advanced](#advanced) 61 | 62 | 63 |
64 | 65 |
66 | 67 | Python 68 | 69 | * [Introduction](#introduction-2) 70 | * [Basic Data Types](#basic-data-types) 71 | * [Strings](#strings-2) 72 | * [Sets](#sets) 73 | * [Math](#math) 74 | * [Itertools](#itertools) 75 | * [Collections](#collections) 76 | * [Date and Time](#date-and-time) 77 | * [Errors and Exceptions](#errors-and-exceptions) 78 | * [Classes](#classes) 79 | * [Built-Ins](#built-ins) 80 | * [Python Functionals](#python-functionals) 81 | * [Regex and Parsing](#regex-and-parsing) 82 | * [XML](#xml) 83 | * [Closures and Decorators](#closures-and-decorators) 84 | * [Numpy](#numpy) 85 | * [Debugging](#debugging) 86 | 87 |
88 | 89 | ## SQL (All the solutions are given in MySQL) 90 | 91 | ### Basic Select 92 | | S.No. | Problem | Solution | Score | Difficulty | 93 | |--|--|--|--|--| 94 | | 01. | [Revising the Select Query I](https://www.hackerrank.com/challenges/revising-the-select-query/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/01.%20Revising%20the%20Select%20Query%20I.sql) | 10 | Easy | 95 | | 02. | [Revising the Select Query II](https://www.hackerrank.com/challenges/revising-the-select-query-2/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/02.%20Revising%20the%20Select%20Query%20II.sql) | 10 | Easy | 96 | | 03. | [Select All](https://www.hackerrank.com/challenges/select-all-sql/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/03.%20Select%20All.sql) | 10 | Easy | 97 | | 04. | [Select By ID](https://www.hackerrank.com/challenges/select-by-id/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/04.%20Select%20By%20ID.sql) | 10 | Easy | 98 | | 05. | [Japanese Cities' Attributes](https://www.hackerrank.com/challenges/japanese-cities-attributes/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/05.%20Japanese%20Cities'%20Attributes.sql) | 10 | Easy | 99 | | 06. | [Japanese Cities' Names](https://www.hackerrank.com/challenges/japanese-cities-name/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/06.%20Japanese%20Cities'%20Names.sql) | 10 | Easy | 100 | | 07. | [Weather Observation Station 1](https://www.hackerrank.com/challenges/weather-observation-station-1/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/07.%20Weather%20Observation%20Station%201.sql) | 15 | Easy | 101 | | 08. | [Weather Observation Station 3](https://www.hackerrank.com/challenges/weather-observation-station-3/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/08.%20Weather%20Observation%20Station%203.sql) | 10 | Easy | 102 | | 09. | [Weather Observation Station 4](https://www.hackerrank.com/challenges/weather-observation-station-4/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/09.%20Weather%20Observation%20Station%204.sql) | 10 | Easy | 103 | | 10. | [Weather Observation Station 5](https://www.hackerrank.com/challenges/weather-observation-station-5/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/10.%20Weather%20Observation%20Station%205.sql) | 30 | Easy | 104 | | 11. | [Weather Observation Station 6](https://www.hackerrank.com/challenges/weather-observation-station-6/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/11.%20Weather%20Observation%20Station%206.sql) | 10 | Easy | 105 | | 12. | [Weather Observation Station 7](https://www.hackerrank.com/challenges/weather-observation-station-7/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/12.%20Weather%20Observation%20Station%207.sql) | 10 | Easy | 106 | | 13. | [Weather Observation Station 8](https://www.hackerrank.com/challenges/weather-observation-station-8/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/13.%20Weather%20Observation%20Station%208.sql) | 15 | Easy | 107 | | 14. | [Weather Observation Station 9](https://www.hackerrank.com/challenges/weather-observation-station-9/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/14.%20Weather%20Observation%20Station%209.sql) | 10 | Easy | 108 | | 15. | [Weather Observation Station 10](https://www.hackerrank.com/challenges/weather-observation-station-10/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/15.%20Weather%20Observation%20Station%2010.sql) | 10 | Easy 109 | | 16. | [Weather Observation Station 11](https://www.hackerrank.com/challenges/weather-observation-station-11/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/16.%20Weather%20Observation%20Station%2011.sql) | 15 | Easy | 110 | | 17. | [Weather Observation Station 12](https://www.hackerrank.com/challenges/weather-observation-station-11/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/17.%20Weather%20Observation%20Station%2012.sql) | 15 | Easy | 111 | | 18. | [Higher Than 75 Marks](https://www.hackerrank.com/challenges/more-than-75-marks/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/18.%20Higher%20Than%2075%20Marks.sql) | 15 | Easy | 112 | | 19. | [Employee Names](https://www.hackerrank.com/challenges/name-of-employees/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/19.%20Employee%20Names.sql) | 10 | Easy | 113 | | 20. | [Employee Salaries](https://www.hackerrank.com/challenges/salary-of-employees/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/1.%20BASIC%20SELECT/20.%20Employee%20Salaries.sql) | 10 | Easy | 114 | 115 | ### Advanced Select 116 | | S.No. | Problem | Solution | Score | Difficulty | 117 | |--|--|--|--|--| 118 | | 01. | [Type of Triangle](https://www.hackerrank.com/challenges/what-type-of-triangle/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/2.%20ADVANCED%20SELECT/01.Type%20of%20Triangle.sql) | 20 | Easy | 119 | | 02. | [The PADS](https://www.hackerrank.com/challenges/the-pads/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/2.%20ADVANCED%20SELECT/02.%20The%20PADS.sql) | 30 | Medium | 120 | | 03. | [Occupations ](https://www.hackerrank.com/challenges/occupations/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/2.%20ADVANCED%20SELECT/03.%20Occupations.sql) | 30 | Medium | 121 | | 04. | [Binary Tree Nodes](https://www.hackerrank.com/challenges/binary-search-tree-1/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/2.%20ADVANCED%20SELECT/04.%20Binary%20Tree%20Nodes.sql) | 30 | Medium | 122 | | 05. | [New Companies]( https://www.hackerrank.com/challenges/binary-search-tree-1/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/2.%20ADVANCED%20SELECT/05.%20New%20Companies.sql) | 30 | Medium | 123 | 124 | ### Aggregation 125 | | S.No. | Problem | Solution | Score | Difficulty | 126 | |--|--|--|--|--| 127 | | 01. | [Revising Aggregations - The Count Function](https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/01.Revising%20Aggregations%20-%20The%20Count%20Function.sql) | 10 | Easy | 128 | | 02. | [Revising Aggregations - The Sum Function](https://www.hackerrank.com/challenges/revising-aggregations-sum/problem) |[Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/02.%20Revising%20Aggregations%20-%20The%20Sum%20Function.sql) | 10 | Easy | 129 | | 03. | [Revising Aggregations - Averages](https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/03.%20Revising%20Aggregations%20-%20Averages.sql) | 10 | Easy | 130 | | 04. | [Average Population](https://www.hackerrank.com/challenges/average-population/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/04.%20Average%20Population.sql) | 10 | Easy | 131 | | 05. | [Japan Population](https://www.hackerrank.com/challenges/japan-population/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/05.%20Japan%20Population.sql) | 10 | Easy | 132 | | 06. | [Population Density Difference](https://www.hackerrank.com/challenges/population-density-difference/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/06.%20Population%20Density%20Difference.sql) | 10 | Easy | 133 | | 07. | [The Blunder](https://www.hackerrank.com/challenges/the-blunder/problem) | [solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/07.%20The%20Blunder.sql) | 15 | Easy | 134 | | 08. | [Top Earners](https://www.hackerrank.com/challenges/earnings-of-employees/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/08.%20Top%20Earners.sql) | 20 | Easy | 135 | | 09. | [Weather Observation Station 2](https://www.hackerrank.com/challenges/weather-observation-station-2/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/09.%20Weather%20Observation%20Station%202.sql) | 15 | Easy | 136 | | 10. | [Weather Observation Station 13](https://www.hackerrank.com/challenges/weather-observation-station-13/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/10.%20Weather%20Observation%20Station%2013.sql) | 10 | Easy | 137 | | 11. | [Weather Observation Station 14](https://www.hackerrank.com/challenges/weather-observation-station-14/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/11.%20Weather%20Observation%20Station%2014.sql) | 10 | Easy | 138 | | 12. | [Weather Observation Station 15](https://www.hackerrank.com/challenges/weather-observation-station-15/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/12.%20Weather%20Observation%20Station%2015.sql) | 15 | Easy | 139 | | 13. | [Weather Observation Station 16](https://www.hackerrank.com/challenges/weather-observation-station-16/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/13.%20Weather%20Observation%20Station%2016.sql) | 10 | Easy | 140 | | 14. | [Weather Observation Station 17](https://www.hackerrank.com/challenges/weather-observation-station-17/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/14.%20Weather%20Observation%20Station%2017.sql) | 15 | Easy | 141 | | 15. | [Weather Observation Station 18](https://www.hackerrank.com/challenges/weather-observation-station-18/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/15.%20Weather%20Observation%20Station%2018.sql) | 25 | Medium | 142 | | 16. | [Weather Observation Station 19](https://www.hackerrank.com/challenges/weather-observation-station-19/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/16.%20Weather%20Observation%20Station%2019.sql) | 30 | Medium | 143 | | 17. | [Weather Observation Station 20](https://www.hackerrank.com/challenges/weather-observation-station-20/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/3.%20AGGREGATION/17.%20Weather%20Observation%20Station%2020.sql) | 40 | Medium | 144 | 145 | ### Basic Join 146 | | S.No. | Problem | Solution | Score | Difficulty | 147 | |--|--|--|--|--| 148 | | 01. | [Population Census](https://www.hackerrank.com/challenges/asian-population/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/01.%20Population%20Census.sql) | 10 | Easy | 149 | | 02. | [African Cities](https://www.hackerrank.com/challenges/african-cities/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/02.%20African%20Cities.sql) | 10 | Easy | 150 | | 03. | [Average Population of Each Continent](https://www.hackerrank.com/challenges/average-population-of-each-continent/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/03.%20Average%20Population%20of%20Each%20Continent.sql) | 10 | Easy | 151 | | 04. | [The Report](https://www.hackerrank.com/challenges/the-report/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/04.%20The%20Report.sql) | 20 | Medium | 152 | | 05. | [Top Competitors](https://www.hackerrank.com/challenges/full-score/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/05.%20Top%20Competitors.sql) | 30 | Medium | 153 | | 06. | [Ollivander's Inventory](https://www.hackerrank.com/challenges/harry-potter-and-wands/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/06.%20Ollivander's%20Inventory.sql) | 30 | Medium | 154 | | 07. | [Challenges](https://www.hackerrank.com/challenges/challenges/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/07.%20Challenges.sql) | 30 | Medium | 155 | | 08. | [Contest Leaderboard](https://www.hackerrank.com/challenges/contest-leaderboard/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/4.%20BASIC%20JOIN/08.%20Contest%20Leaderboard.sql) | 30 | Medium | 156 | 157 | ### Advanced Join 158 | | S.No. | Problem | Solution | Score | Difficulty | 159 | |--|--|--|--|--| 160 | | 01. | [SQL Project Planning](https://www.hackerrank.com/challenges/sql-projects/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/5.%20ADVANCED%20JOIN/01.%20SQL%20Project%20Planning.sql) | 40 | Medium | 161 | | 02. | [SQL Symmetric Pairs](https://www.hackerrank.com/challenges/symmetric-pairs/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/5.%20ADVANCED%20JOIN/02.%20SQL%20Symmetric%20Pairs.sql) | 40 | Medium | 162 | | 03. | [15 Days of Learning SQL](https://www.hackerrank.com/challenges/sql-projects/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/5.%20ADVANCED%20JOIN/03.%2015%20Days%20of%20Learning%20SQL.sql) | 40 | Medium | 163 | 164 | ### Alternative Queries 165 | | S.No. | Problem | Solution | Score | Difficulty | 166 | |--|--|--|--|--| 167 | | 01. | [Draw The Triangle 1](https://www.hackerrank.com/challenges/draw-the-triangle-1/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/6.%20ALTERNATIVE%20QUERIES/01.%20Draw%20The%20Triangle%201.sql) | 25 | Easy | 168 | | 02. | [Draw The Triangle 2](https://www.hackerrank.com/challenges/draw-the-triangle-2/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/SQL/6.%20ALTERNATIVE%20QUERIES/02.%20Draw%20The%20Triangle%202.sql) | 25 | Easy | 169 | 170 | ## C++ 171 | 172 | ### Introduction 173 | | S.No. | Problem | Solution | Score | Difficulty | 174 | |--|--|--|--|--| 175 | | 01. | [Arrays Introduction](https://www.hackerrank.com/challenges/arrays-introduction/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Arrays%20Introduction.cpp) | 10 | Easy | 176 | | 02. | [Basic Data Types](https://www.hackerrank.com/challenges/c-tutorial-basic-data-types/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Basic%20Data%20Types.cpp) | 10 | Easy | 177 | | 03. | [Conditional Statements](https://www.hackerrank.com/challenges/c-tutorial-conditional-if-else/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Conditional%20Statements.cpp) | 10 | Easy | 178 | | 04. | [For Loop](https://www.hackerrank.com/challenges/c-tutorial-for-loop/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/For%20Loop.cpp) | 10 | Easy | 179 | | 05. | [Pointer](https://www.hackerrank.com/challenges/c-tutorial-pointer/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Pointer.cpp) | 10 | Easy | 180 | | 06. | [Say "Hello, World!" With C++](https://www.hackerrank.com/challenges/cpp-hello-world/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Say_Hello_World_With_C%2B%2B.cpp) | 05 | Easy | 181 | | 07. | [Variable Sized Arrays](https://www.hackerrank.com/challenges/variable-sized-arrays/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Variable%20Sized%20Arrays.cpp) | 30 | Easy | 182 | | 08. | [Input and Output](https://www.hackerrank.com/challenges/cpp-input-and-output/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/01.%20Introduction/Input%20and%20Output.cpp) | 05 | Easy | 183 | 184 | ### Strings 185 | | S.No. | Problem | Solution | Score | Difficulty | 186 | |--|--|--|--|--| 187 | | 01. | [Attribute Parser](https://www.hackerrank.com/challenges/attribute-parser/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/02.%20Strings/Attribute%20Parser.cpp) | 35 | Medium | 188 | | 02. | [StringStream](https://www.hackerrank.com/challenges/c-tutorial-stringstream/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/02.%20Strings/StringStream.cpp) | 10 | Easy | 189 | | 03. | [Strings](https://www.hackerrank.com/challenges/c-tutorial-strings/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/02.%20Strings/Strings.cpp) | 10 | Easy | 190 | 191 | ### Classes 192 | | S.No. | Problem | Solution | Score | Difficulty | 193 | |--|--|--|--|--| 194 | | 01. | [Class](https://www.hackerrank.com/challenges/c-tutorial-class/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/03.%20Classes/Class.cpp) | 10 | Easy | 195 | | 02. | [Structs](https://www.hackerrank.com/challenges/c-tutorial-struct/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/03.%20Classes/Structs.cpp) | 10 | Easy | 196 | 197 | ### STL 198 | | S.No. | Problem | Solution | Score | Difficulty | 199 | |--|--|--|--|--| 200 | | 01. | [Deque-STL](https://www.hackerrank.com/challenges/deque-stl/problem?isFullScreen=false) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/04.%20STL/Deque-STL.cpp) | 50 | Medium | 201 | | 02. | [Lower Bound-STL](https://www.hackerrank.com/challenges/cpp-lower-bound/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/04.%20STL/Lower%20Bound-STL.cpp) | 15 | Easy | 202 | | 03. | [Sets-STL](https://www.hackerrank.com/challenges/cpp-sets/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/04.%20STL/Sets-STL.cpp) | 15 | Easy | 203 | | 04. | [Vector-Sort](https://www.hackerrank.com/challenges/vector-sort/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/04.%20STL/Vector-Sort.cpp) | 10 | Easy | 204 | 205 | ### Inheritance 206 | | S.No. | Problem | Solution | Score | Difficulty | 207 | |--|--|--|--|--| 208 | | 01. | [Multi Level Inheritance](https://www.hackerrank.com/challenges/multi-level-inheritance-cpp/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/05.%20Inheritance/Multi_Level_Inheritance.cpp) | 50 | Medium | 209 | | 02. | [Rectangle Area](https://www.hackerrank.com/challenges/rectangle-area/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/05.%20Inheritance/Rectangle%20Area.cpp) | 25 | Easy | 210 | 211 | ### Debugging 212 | | S.No. | Problem | Solution | Score | Difficulty | 213 | |--|--|--|--|--| 214 | | 01. | [CPP Exception Handling](https://www.hackerrank.com/challenges/cpp-exception-handling/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/06.%20Debugging/CPP%20Exception%20Handling.cpp) | 20 | Medium | 215 | | 02. | [Overloading Ostream Operator](https://www.hackerrank.com/challenges/overloading-ostream-operator/problem?isFullScreen=true) | [Solution](https://www.hackerrank.com/challenges/overloading-ostream-operator/submissions/code/293723048) | 20 | Medium | 216 | 217 | ### Other Concepts 218 | | S.No. | Problem | Solution | Score | Difficulty | 219 | |--|--|--|--|--| 220 | | 01. | [Operator Overloading](https://www.hackerrank.com/challenges/operator-overloading/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/C%2B%2B/07.%20Other%20Concepts/Operator%20Overloading.cpp) | 25 | Medium | 221 | 222 | ## Algorithims 223 | 224 | ### Dynamic programming 225 | | S.No. | Problem | Solution | Score | Difficulty | 226 | |--|--|--|--|--| 227 | | 01. | [The Coin Change Problem](https://www.hackerrank.com/challenges/coin-change/problem?isFullScreen=true) | [Solution]() | 60 | Medium | 228 | | 02. | [Equal](https://www.hackerrank.com/challenges/equal/problem?isFullScreen=true) | [Solution]() | 30 | Medium | 229 | | 03. | [Stock Maximize](https://www.hackerrank.com/challenges/stockmax/problem?isFullScreen=true) | [Solution]() | 50 | Medium | 230 | 231 | ## Java 232 | 233 | ### Introduction 234 | | S.No. | Problem | Solution | Score | Difficulty | 235 | |--|--|--|--|--| 236 | | 01. | [Java Date and Time](https://www.hackerrank.com/challenges/java-date-and-time/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/01.%20Introduction/Java%20Date%20and%20Time.java) | 15 | Easy | 237 | | 02. | [Java If-Else](https://www.hackerrank.com/challenges/java-if-else/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/01.%20Introduction/Java%20If-Else.java) | 10 | Easy | 238 | | 03. | [Java Int to String](https://www.hackerrank.com/challenges/java-int-to-string/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/01.%20Introduction/Java%20Int%20to%20String.java) | 10 | Easy | 239 | | 04. | [Java Loops II](https://www.hackerrank.com/challenges/java-loops/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/01.%20Introduction/Java%20Loops%20II.java) | 10 | Easy | 240 | | 05. | [Java Stdin and Stdout I](https://www.hackerrank.com/challenges/java-stdin-and-stdout-1/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/01.%20Introduction/Java%20Stdin%20and%20Stdout%20I.java) | 05 | Easy | 241 | | 06. | [Java Stdin and Stdout II](https://www.hackerrank.com/challenges/java-stdin-stdout/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/Introduction/DateTime.java) | 10 | Easy | 242 | | 07. | [Welcome To Java](https://www.hackerrank.com/challenges/welcome-to-java/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/01.%20Introduction/Welcome%20To%20Java.java) | 03 | Easy | 243 | 244 | ### Strings 245 | | S.No. | Problem | Solution | Score | Difficulty | 246 | |--|--|--|--|--| 247 | | 01. | [Java Substring](https://www.hackerrank.com/challenges/java-substring/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/02.%20Strings/Java%20Substring.java) | 05 | Easy | 248 | 249 | ### BigNumber 250 | | S.No. | Problem | Solution | Score | Difficulty | 251 | |--|--|--|--|--| 252 | 253 | ### Data Structures 254 | | S.No. | Problem | Solution | Score | Difficulty | 255 | |--|--|--|--|--| 256 | | 01. | [Java 1D Array](https://www.hackerrank.com/challenges/java-1d-array-introduction/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/04.%20Data%20Structures/Java%201D%20Array.java) | 05 | Easy | 257 | | 02. | [Java Stack](https://www.hackerrank.com/challenges/java-stack/problem) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Java/04.%20Data%20Structures/Java%20Stack.java) | 20 | Medium | 258 | 259 | ### Object Oriented Programming 260 | | S.No. | Problem | Solution | Score | Difficulty | 261 | |--|--|--|--|--| 262 | | 01. | [Java Abstract Class](https://www.hackerrank.com/challenges/java-abstract-class/problem) | [Solution]() | 10 | Easy | 263 | | 02. | [Java Inheritance I](https://www.hackerrank.com/challenges/java-inheritance-1/problem) | [Solution]() | 05 | Easy | 264 | | 03. | [Java Inheritance II](https://www.hackerrank.com/challenges/java-inheritance-2/problem) | [Solution]() | 10 | Easy | 265 | 266 | ## Python 267 | 268 | ### Introduction 269 | | S.No. | Problem | Solution | Score | Difficulty | 270 | |--|--|--|--|--| 271 | | 01. | [Loops](https://www.hackerrank.com/challenges/python-loops/problem?isFullScreen=true) | [Solution]()| 10 | Easy | 272 | | 02. | [Python Division](https://www.hackerrank.com/challenges/python-division/problem?isFullScreen=true) | [Solution]() | 10 | Easy | 273 | | 03. | [Python If-Else](https://www.hackerrank.com/challenges/py-if-else/problem) | [Solution]() | 10 | Easy | 274 | | 04. | [Write a Function](https://www.hackerrank.com/challenges/write-a-function/problem?isFullScreen=true) | [Solution]() | 10 | Medium | 275 | 276 | ### Basic Data Types 277 | | S.No. | Problem | Solution | Score | Difficulty | 278 | |--|--|--|--|--| 279 | | 01. | [Finding the Runner-Up Score](https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem) | [Solution]()| 10 | Easy | 280 | | 02. | [Finding the percentage](https://www.hackerrank.com/challenges/finding-the-percentage/problem) | [Solution]()| 10 | Easy | 281 | | 03. | [List Comprehensions](https://www.hackerrank.com/challenges/list-comprehensions/problem?isFullScreen=true) | [Solution](https://github.com/Riddhi9570/HackerrankPracticeProblems/blob/main/Python/Basic%20Data%20Types/ListComprehensions.py) | 10 | Easy | 282 | 283 | ### Strings 284 | | S.No. | Problem | Solution | Score | Difficulty | 285 | |--|--|--|--|--| 286 | | 01. | [sWAP CASE](https://www.hackerrank.com/challenges/swap-case/problem?isFullScreen=true) | [Solution](https://www.hackerrank.com/challenges/swap-case/submissions/code/293772315) | 10 | Easy | 287 | -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/01. Revising the Select Query I.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-the-select-query/problem 2 | -- # Score: 10 3 | -- # Difficulty : Easy 4 | 5 | SELECT * 6 | FROM CITY 7 | WHERE 8 | POPULATION > 100000 9 | AND COUNTRYCODE = 'USA'; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/02. Revising the Select Query II.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-the-select-query-2/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT NAME 6 | FROM CITY 7 | WHERE 8 | COUNTRYCODE = 'USA' 9 | AND POPULATION > 120000; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/03. Select All.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/select-all-sql/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT * 6 | FROM CITY; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/04. Select By ID.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/select-by-id/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT * 6 | FROM CITY 7 | WHERE ID = 1661; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/05. Japanese Cities' Attributes.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/japanese-cities-attributes/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT * 6 | FROM CITY 7 | WHERE COUNTRYCODE = 'JPN'; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/06. Japanese Cities' Names.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/japanese-cities-name/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT NAME 6 | FROM CITY 7 | WHERE COUNTRYCODE = 'JPN'; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/07. Weather Observation Station 1.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-1/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | SELECT CITY, STATE FROM STATION; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/08. Weather Observation Station 3.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-3/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT DISTINCT CITY -- # DISTINCT keyword is used to exclude duplicate values 6 | FROM STATION 7 | WHERE MOD(ID,2) = 0; -- # MOD(A,B) is equivalent to A%B -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/09. Weather Observation Station 4.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-4/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT COUNT(CITY) - COUNT(DISTINCT CITY) 6 | FROM STATION; -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/10. Weather Observation Station 5.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-5/problem 2 | -- # Score: 30 3 | -- # Difficulty: Easy 4 | 5 | SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY), CITY LIMIT 1; 6 | SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY LIMIT 1; 7 | 8 | /*EXPLANATION of solution: 9 | 10 | For the shortest city name, we can sort city names according to their length in ascending order, and for cities having the same length, sort with their names in alphabetical order. Then we output city name and its length of the first entry. 11 | 12 | For the longest city name, we can sort city names with length in descending order. Then sort cities’ names in alphabetical order for those having the same length. Finally output city name and length of first entry. 13 | 14 | NOTE: 15 | 16 | -'LENGTH(A)' is used to get the length of the A. 17 | -'ORDER BY A' sort the result in ascending order of A. 18 | -'ORDER BY A DESC' sort the result in descending order of A. 19 | -'ORDER BY A, B' sort the result in ascending order of A, but for the same values of A, it will sort in ascending order of B. 20 | -'ORDER BY A DESC, B' sort the result in descending order of A, but for the same values of A, it will sort in ascending order of B. 21 | -'LIMIT n' is used to limit the number of outputs to n when there are more than n outputs. 22 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/11. Weather Observation Station 6.sql: -------------------------------------------------------------------------------- 1 | 2 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-6/problem 3 | -- # Score: 10 4 | -- # Difficulty: Easy 5 | 6 | SELECT DISTINCT CITY 7 | FROM STATION 8 | WHERE CITY REGEXP '^[aeiou]' 9 | 10 | /* NOTE: 11 | 12 | -REGEXP is the operator used when performing regular expression pattern matches. 13 | -^ :- caret(^) matches the beginning of the string. 14 | -[abc] :- any character listed between the square brackets. 15 | -REGEXP is not case sensitive.i.e, we can also take '^[AEIOU]' in this question. 16 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/12. Weather Observation Station 7.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-7/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT DISTINCT CITY 7 | FROM STATION 8 | WHERE CITY REGEXP '[aeiou]$'; 9 | 10 | /* NOTE: 11 | 12 | -DISTINCT excludes duplicates. 13 | -REGEXP is the operator used when performing regular expression pattern matches. 14 | -$:- Matches end of the string. 15 | -[abc] :- any character listed between the square brackets. 16 | -REGEXP is not case sensitive.i.e, we can also take '[AEIOU]$' in this question. 17 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/13. Weather Observation Station 8.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-8/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | SELECT DISTINCT city 6 | FROM station 7 | WHERE city REGEXP '^[AEIOU].*[aeiou]$' 8 | 9 | /* NOTE: 10 | 11 | -DISTINCT excludes duplicates. 12 | -REGEXP is the operator used when performing regular expression pattern matches. 13 | -^ :- The caret (^) character is used to start matches at the beginning of a searched string. 14 | -[abc] :- It is used to match any characters enclosed in the square brackets. 15 | -. :- The dot (.) character matches any single character. 16 | -* :-The asterisk (*) character matches zero (0) or more instances of the preceding strings. 17 | -$ :- The dollar ($) character is used to start matches at the end of a searched string. 18 | -WHERE city REGEXP '^[AEIOU].*[aeiou]$' is equivalent to WHERE REGEXP_LIKE(City, '^[AEIOU].*[aeiou]$') 19 | 20 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/14. Weather Observation Station 9.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-9/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT DISTINCT CITY 7 | FROM STATION 8 | WHERE REGEXP_LIKE(City, '^[^AEIOU]'); 9 | 10 | 11 | /* NOTE: 12 | 13 | -DISTINCT excludes duplicates. 14 | -REGEXP_LIKE() :- This function represents whether the string matches regular expression or not. 15 | -^ :- The caret (^) character is used to start matches at the beginning of a searched string. 16 | -[abc] :- It is used to match any characters enclosed in the square brackets. 17 | -[^abc] :- It is used to match any characters not specified in the square brackets. 18 | 19 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/15. Weather Observation Station 10.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-10/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT DISTINCT City 7 | FROM Station 8 | WHERE REGEXP_LIKE(City, '[^aeiou]$'); 9 | 10 | 11 | /* NOTE: 12 | 13 | -DISTINCT excludes duplicates. 14 | -REGEXP_LIKE() :- This function represents whether the string matches regular expression or not. 15 | -[^abc] :- It is used to match any characters not specified in the square brackets. 16 | -$ :- The dollar ($) character is used to start matches at the end of a searched string. 17 | 18 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/16. Weather Observation Station 11.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-11/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT DISTINCT City FROM Station 7 | WHERE REGEXP_LIKE(City, '^[^AEIOU]|[^aeiou]$'); 8 | 9 | 10 | /* NOTE: 11 | 12 | -DISTINCT :- excludes duplicates. 13 | -REGEXP_LIKE() :- This function represents whether the string matches regular expression or not. 14 | -^ :- The caret (^) character is used to start matches at the beginning of a searched string. 15 | -[^abc] :- It is used to match any characters not specified in the square brackets. 16 | -$ :- The dollar ($) character is used to start matches at the end of a searched string. 17 | -p1|p2 :- matches any of the patterns p1 or p2. 18 | 19 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/17. Weather Observation Station 12.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-11/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT DISTINCT City 7 | FROM Station 8 | WHERE REGEXP_LIKE(City, '^[^AEIOU].*[^aeiou]$'); 9 | 10 | 11 | /* NOTE: 12 | 13 | -DISTINCT :- excludes duplicates. 14 | -REGEXP_LIKE() :- This function represents whether the string matches regular expression or not. 15 | -[abc] :- It is used to match any characters enclosed in the square brackets. 16 | -[^abc] :- It is used to match any characters not specified in the square brackets. 17 | -^ :- The caret (^) character is used to start matches at the beginning of a searched string. 18 | -. :- The dot (.) character matches any single character. 19 | -* :-The asterisk (*) character matches zero (0) or more instances of the preceding strings. 20 | -$ :- The dollar ($) character is used to start matches at the end of a searched string. 21 | 22 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/18. Higher Than 75 Marks.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/more-than-75-marks/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT Name 7 | FROM Students 8 | WHERE Marks > 75 9 | ORDER BY SUBSTR(Name, - 3), Id ASC; 10 | 11 | 12 | /* NOTE: 13 | - > :- greater than. 14 | - 'ORDER BY A' and 'ORDER BY A ASC' sort the result in ascending order of A. 15 | - 'ORDER BY A DESC' sort the result in descending order of A. 16 | - 'ORDER BY A, B' sort the result in ascending order of A, but for the same values of A, it will sort those values in ascending order of B. 17 | - SUBSTR(str,a,b) :- Extract a substring from a string str starting from position a and extract b number of characters. 18 | - if a is negative, it will extract from last a-th position. 19 | - if b is not given, it will extract till the end. 20 | 21 | 22 | */ -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/19. Employee Names.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/name-of-employees/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT Name 7 | FROM Employee 8 | ORDER BY Name; 9 | 10 | 11 | -- # NOTE: 'ORDER BY Name' and 'ORDER BY Name ASC' both sort the result in alphabetical order of Name. -------------------------------------------------------------------------------- /SQL/1. BASIC SELECT/20. Employee Salaries.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/salary-of-employees/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT Name 7 | FROM Employee 8 | WHERE Salary > 2000 AND Months < 10 9 | ORDER BY Employee_id; -------------------------------------------------------------------------------- /SQL/2. ADVANCED SELECT/01.Type of Triangle.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/what-type-of-triangle/problem 2 | -- # Score: 20 3 | -- # Difficulty: Easy 4 | 5 | SELECT 6 | IF(A+B>C AND A+C>B AND B+C>A, IF(A=B AND B=C, 'Equilateral', IF(A=B OR B=C OR A=C, 'Isosceles', 'Scalene')), 'Not A Triangle') 7 | FROM TRIANGLES; -------------------------------------------------------------------------------- /SQL/2. ADVANCED SELECT/02. The PADS.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/the-pads/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | select 7 | concat(name,"(",upper(substr(occupation,1,1)),")") 8 | from 9 | occupations 10 | order by 11 | name; 12 | 13 | 14 | select 15 | "There are a total of ", 16 | concat(count(*)," ",lower(occupation),"s.") 17 | from 18 | occupations 19 | group by 20 | occupation 21 | order by 22 | count(*), 23 | occupation; 24 | 25 | 26 | /* NOTE: 27 | 28 | - The CONCAT() function adds two or more expressions together. 29 | - The UPPER() function converts a string to upper-case. 30 | - The LOWER() function converts a string to lower-case. 31 | - The SUBSTR(str,a,b) function extract a substring from a string 'str' starting from position 'a' and extract 'b' number of characters. 32 | - 'ORDER BY A' sort the result in ascending order of A. 33 | - 'ORDER BY A, B' sort the result in ascending order of A, but for the same values of A, it will sort those values in ascending order of B. 34 | - The COUNT(*) function counts the number of rows produced by the query. 35 | - The GROUP BY statement groups rows that have the same values into summary rows. 36 | 37 | */ -------------------------------------------------------------------------------- /SQL/2. ADVANCED SELECT/03. Occupations.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/occupations/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | set @d=0, @p=0, @s=0, @a=0; 7 | 8 | select min(Doctor), min(Professor), min(Singer), min(Actor) 9 | from( 10 | select 11 | case 12 | when Occupation='Doctor' then (@d:=@d+1) 13 | when Occupation='Professor' then (@p:=@p+1) 14 | when Occupation='Singer' then (@s:=@s+1) 15 | when Occupation='Actor' then (@a:=@a+1) 16 | end 17 | as Rowline, 18 | case 19 | when Occupation='Doctor' then Name 20 | end 21 | as Doctor, 22 | case 23 | when Occupation='Professor' then Name 24 | end 25 | as Professor, 26 | case 27 | when Occupation='Singer' then Name 28 | end 29 | as Singer, 30 | case 31 | when Occupation='Actor' then Name 32 | end 33 | as Actor 34 | from OCCUPATIONS 35 | order by Name 36 | ) 37 | as temp 38 | group by Rowline; 39 | 40 | 41 | /* 42 | 43 | Explaination :- 44 | 45 | To solve this problem, we can create a new table (let's say temp) using user-defined variables which will look like this for the given sample table :- 46 | 47 | RowLine Doctor Professor Singer Actor 48 | 1 NULL Ashely NULL NULL 49 | 2 NULL Christeen NULL NULL 50 | 1 NULL NULL NULL Jane 51 | 1 Jenny NULL NULL NULL 52 | 2 NULL NULL NULL Julia 53 | 3 NULL Ketty NULL NULL 54 | 3 NULL NULL NULL Maria 55 | 1 NULL NULL Meera NULL 56 | 2 NULL NULL Priya NULL 57 | 2 Samantha NULL NULL NULL 58 | 59 | To get the table temp, we create four variables to record the line number RowLine, one for each occupation. We use CASE to add variables according to occupation. We use as (alias) to give field name as Rowline, Doctor, Professor, Singer and Actor. The RowLine represents the line where the name should be put. In addition, because we want to sort names alphabetically for each occupation, the first step of creating the table above is to sort OCCUPATIONS table by name. Once we have got the table temp, we can use “SELECT MIN(Doctor), MIN(Professor), MIN(Singer), MIN(Actor) FROM temp GROUP BY RowLine” to get the desired result. 60 | 61 | Note :- 62 | 63 | - SET statement is used to set a user-defined variable. 64 | - User-defined variables are written as @var_name. 65 | - The MIN() function returns the minimum value in a set of values. By default, it do not count NULL in the evaluation of data. 66 | - The CASE statement goes through conditions and returns a value when the first condition is met. Once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the ELSE clause. If there is no ELSE part and no conditions are true, it returns NULL. 67 | - END is the marker that closes the CASE expression. 68 | - AS is used to give a temporary name to a table or a column in a table for the purpose of a particular query. 69 | - 'ORDER BY A' sort the result in ascending order of A. 70 | - The GROUP BY statement groups rows that have the same values into summary rows. 71 | 72 | */ -------------------------------------------------------------------------------- /SQL/2. ADVANCED SELECT/04. Binary Tree Nodes.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/binary-search-tree-1/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | SELECT 7 | N, 8 | IF(P IS NULL, 'Root', IF(N IN (SELECT P FROM BST), 'Inner', 'Leaf')) 9 | FROM 10 | BST 11 | ORDER BY 12 | N; 13 | 14 | 15 | /* 16 | 17 | How to solve :- 18 | 19 | - If P is null, then the node will be root. 20 | - Next check if the node value appears in Column P, it will be ‘Inner’, otherwise ‘Leaf’. 21 | 22 | NOTE :- 23 | 24 | - The IF() function returns a value if a condition is TRUE, or another value if a condition is FALSE. Syntax. IF(condition, value_if_true, value_if_false) 25 | - 'IS NULL' is the keyword that performs the Boolean comparison. It returns true if the supplied value is NULL and false if the supplied value is not NULL. 26 | - 'ORDER BY N' sort the result in ascending order of N. 27 | 28 | */ -------------------------------------------------------------------------------- /SQL/2. ADVANCED SELECT/05. New Companies.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/binary-search-tree-1/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | select 6 | c.company_code, 7 | c.founder, 8 | count(distinct l.lead_manager_code), 9 | count(distinct s.senior_manager_code), 10 | count(distinct m.manager_code), 11 | count(distinct e.employee_code) 12 | from 13 | Company c, 14 | Lead_Manager l, 15 | Senior_Manager s, 16 | Manager M, 17 | Employee e 18 | where 19 | c.company_code = l.company_code 20 | AND l.lead_manager_code = s.lead_manager_code 21 | AND s.senior_manager_code = m.senior_manager_code 22 | AND m.manager_code = e.manager_code 23 | group by 24 | c.company_code, 25 | c.founder 26 | order by 27 | c.company_code; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/01.Revising Aggregations - The Count Function.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | SELECT COUNT(*) 6 | FROM City 7 | WHERE Population > 100000; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/02. Revising Aggregations - The Sum Function.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-aggregations-sum/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT SUM(Population) 7 | FROM City 8 | WHERE District = 'California'; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/03. Revising Aggregations - Averages.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT AVG(Population) 7 | FROM City 8 | WHERE District = 'California'; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/04. Average Population.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/average-population/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT ROUND(AVG(Population)) 7 | FROM City; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/05. Japan Population.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/japan-population/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT SUM(Population) 7 | FROM City 8 | WHERE CountryCode = 'JPN'; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/06. Population Density Difference.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/population-density-difference/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT MAX(Population) - MIN(Population) 7 | FROM City; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/07. The Blunder.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/the-blunder/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT CEIL(AVG(Salary) - AVG(REPLACE(Salary, '0', ''))) 7 | FROM EMPLOYEES; -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/08. Top Earners.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/earnings-of-employees/problem 2 | -- # Score: 20 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT 7 | (months*salary) as earnings, 8 | COUNT(*) 9 | FROM 10 | Employee 11 | GROUP BY 12 | earnings 13 | ORDER BY 14 | earnings DESC 15 | LIMIT 1; 16 | 17 | 18 | /* 19 | 20 | EXPLAINATION of the solution:- 21 | 22 | - Compute earnings first (month* salary). 23 | - Then group data by earnings. 24 | - Get earnings and number of employees for each group. 25 | - Finally sort groups by earnings in descending order 26 | - Output the first record of the sorted group which will give the maximum earning and the corresponding count. 27 | 28 | 29 | NOTE :- 30 | 31 | - 'SELECT' QUERY is used to fetch the data from the database. 32 | - 'AS' is used to give a temporary name to a table or a column in a table for the purpose of a particular query. 33 | - The 'COUNT(*)' function counts the number of records produced by the query. 34 | - 'FROM' specifies the table or tables to select the data from 35 | - The 'GROUP BY' statement groups rows that have the same values into summary rows. 36 | - 'ORDER BY A DESC' sort the result in descending order of A. 37 | - 'LIMIT n' is used to limit the number of outputs to n when there are more than n outputs. 38 | 39 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/09. Weather Observation Station 2.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-2/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT 7 | ROUND(SUM(Lat_N), 2), 8 | ROUND(SUM(Long_W), 2) 9 | FROM 10 | Station; 11 | 12 | 13 | /* 14 | NOTE:- 15 | 16 | -'SELECT' QUERY is used to fetch the data from the database. 17 | -'ROUND(number,decimal_places)' :- rounds a number to specified number of decimal places. 18 | - The 'SUM()' function returns the total sum of a numeric column. 19 | -'FROM' specifies the table or tables to select the data from. 20 | 21 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/10. Weather Observation Station 13.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-13/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT TRUNCATE(SUM(Lat_N), 4) 7 | FROM STATION 8 | WHERE Lat_N > 38.7880 AND Lat_N < 137.2345; 9 | 10 | 11 | /* 12 | 13 | NOTE:- 14 | 15 | -'SELECT' QUERY is used to fetch the data from the database. 16 | -'TRUNCATE(number,decimal_places)' :- truncate a number to specified number of decimal places. 17 | - The 'SUM()' function returns the total sum of a numeric column. 18 | -'FROM' specifies the table or tables to select the data from. 19 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 20 | - The WHERE condition used together with the AND logical operator, is only executed if ALL filter criteria specified are met. 21 | - '>':- Greater than. 22 | - '<':- Less than. 23 | 24 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/11. Weather Observation Station 14.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-14/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT TRUNCATE(MAX(Lat_N), 4) 7 | FROM Station 8 | WHERE Lat_N < 137.2345; 9 | 10 | 11 | /* 12 | 13 | NOTE:- 14 | 15 | -'SELECT' QUERY is used to fetch the data from the database. 16 | -'TRUNCATE(number,decimal_places)' :- truncate a number to specified number of decimal places. 17 | - The MAX() function returns the largest value of the selected column. 18 | -'FROM' specifies the table or tables to select the data from. 19 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 20 | - '<':- Less than. 21 | 22 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/12. Weather Observation Station 15.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-15/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT ROUND(LONG_W, 4) 7 | FROM STATION 8 | WHERE LAT_N < 137.2345 9 | ORDER BY LAT_N DESC 10 | LIMIT 1; 11 | 12 | 13 | /*NOTE:- 14 | 15 | -'SELECT' QUERY is used to fetch the data from the database. 16 | -'ROUND(number,decimal_places)' :- rounds a number to specified number of decimal places. 17 | -'FROM' specifies the table or tables to select the data from. 18 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 19 | - '<':- Less than. 20 | - 'ORDER BY A DESC' sort the result in descending order of A. 21 | - 'LIMIT n' is used to limit the number of outputs to n when there are more than n outputs. 22 | 23 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/13. Weather Observation Station 16.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-16/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT ROUND(MIN(Lat_N), 4) 7 | FROM Station 8 | WHERE Lat_N > 38.7780; 9 | 10 | 11 | /*NOTE:- 12 | 13 | -'SELECT' QUERY is used to fetch the data from the database. 14 | -'ROUND(number,decimal_places)' :- rounds a number to specified number of decimal places. 15 | - The MIN() function returns the smallest value of the selected column. 16 | -'FROM' specifies the table or tables to select the data from. 17 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 18 | - '>':- Greater than. 19 | 20 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/14. Weather Observation Station 17.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-17/problem 2 | -- # Score: 15 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT ROUND(LONG_W, 4) 7 | FROM STATION 8 | WHERE LAT_N > 38.7780 9 | ORDER BY LAT_N 10 | LIMIT 1; 11 | 12 | 13 | /*NOTE:- 14 | 15 | -'SELECT' QUERY is used to fetch the data from the database. 16 | -'ROUND(number,decimal_places)' :- rounds a number to specified number of decimal places. 17 | -'FROM' specifies the table or tables to select the data from. 18 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 19 | - '>':- Greater than. 20 | - 'ORDER BY A' sort the result in ascending order of A. 21 | - 'LIMIT n' is used to limit the number of outputs to n when there are more than n outputs. 22 | 23 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/15. Weather Observation Station 18.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-18/problem 2 | -- # Score: 25 3 | -- # Difficulty: Medium 4 | 5 | 6 | SELECT ROUND(MAX(Lat_N) - MIN(Lat_N) + MAX(Long_W) - MIN(Long_W), 4) 7 | FROM Station; 8 | 9 | 10 | /*NOTE:- 11 | 12 | - 'Manhattan distance' is the distance between two points measured along axes at right angles. In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 - x2| + |y1 - y2|. 13 | - 'SELECT' QUERY is used to fetch the data from the database. 14 | - 'ROUND(number,decimal_places)' :- rounds a number to specified number of decimal places. 15 | - The MAX() function returns the largest value of the selected column. 16 | - The MIN() function returns the smallest value of the selected column. 17 | - 'FROM' specifies the table or tables to select the data from. 18 | 19 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/16. Weather Observation Station 19.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-19/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | SELECT 7 | ROUND( 8 | SQRT( 9 | POWER((MAX(Lat_N) - MIN(Lat_N)), 2) + 10 | POWER((MAX(Long_W) - MIN(Long_W)), 2) 11 | ) 12 | , 4) 13 | FROM Station; 14 | 15 | 16 | /*NOTE:- 17 | 18 | - The Euclidean distance formula says the distance between two points (x1, y1) and (x2, y2) is d = √[(x2 – x1)^2 + (y2 – y1)^2]. 19 | - 'SELECT' QUERY is used to fetch the data from the database. 20 | - 'ROUND(a,b)' :- rounds a number 'a' to specified number of decimal places 'b'. 21 | - The MAX() function returns the largest value of the selected column. 22 | - The MIN() function returns the smallest value of the selected column. 23 | - The POWER(a,b) function returns the value of a number 'a' raised to the power of 'b'. 24 | - The SQRT() function returns the square root of a number. 25 | - 'FROM' specifies the table or tables to select the data from. 26 | 27 | */ -------------------------------------------------------------------------------- /SQL/3. AGGREGATION/17. Weather Observation Station 20.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-20/problem 2 | -- # Score: 40 3 | -- # Difficulty: Medium 4 | 5 | 6 | SET 7 | @rowIndex := -1; 8 | SELECT 9 | ROUND(AVG(t.LAT_N), 4) 10 | FROM 11 | ( 12 | SELECT 13 | @rowIndex := @rowIndex+1 AS rowIndex, 14 | s.LAT_N 15 | FROM STATION AS s 16 | ORDER BY s.LAT_N 17 | ) AS t 18 | WHERE 19 | t.rowIndex IN (FLOOR(@rowIndex / 2), CEIL(@rowIndex / 2)); 20 | 21 | 22 | /* 23 | APPROACH :- 24 | 25 | - Create a table with 2 fields- rowIndex and LAT_N. 26 | - Set the value of rowIndex as -1 and increase its value for each row. The first row will have the value 0, the second row will have the value 1, and so on. 27 | - Sort the created table in ascending order of LAT_N. 28 | - Name this table as t. 29 | - The table t may look something like this:- 30 | +----------+-------+ 31 | | rowIndex | LAT_N | 32 | +----------+-------+ 33 | | 0 | 1 | 34 | | 1 | 7 | 35 | | 2 | 10 | 36 | | 3 | 19 | 37 | | 4 | 21 | 38 | | 5 | 25 | 39 | | 6 | 36 | 40 | | 7 | 39 | 41 | | 8 | 45 | 42 | | 9 | 52 | 43 | | 10 | 88 | 44 | | 11 | 97 | 45 | +----------+-------+ 46 | - Now, how to find the median of LAT_N from this sorted table- 47 | -For n number of records, 48 | -If n is odd, the median is the number at position floor(n/2) + 1. 49 | -If n is even, the median is the average of numbers at position n/2 and n/2 + 1. 50 | -Here, we have counted the numbers from index 0. 51 | -If n is odd, let's say 9, indexes are 0,1,2,...,8, and the index of the median is 4, which is exactly half of index of the last element. 52 | -If n is even, let's say 10, indexes are 0,1,2,...,9, and the median is average of numbers of index 4 and 5, which are floor and ceil of index of last element divided by 2. 53 | -Thus, we can find the median by taking the average of 54 | (FLOOR(@rowIndex / 2), CEIL(@rowIndex / 2)) 55 | where @rowIndex is the index of last element when started the count from 0. 56 | - Now, round the result to 4 decimal places. 57 | 58 | 59 | NOTE:- 60 | 61 | - 'SET' statement is used to set a user-defined variable. 62 | - User-defined variables are written as @var_name. 63 | - 'SELECT' QUERY is used to fetch the data from the database. 64 | - 'ROUND(a,b)' :- rounds a number 'a' to specified number of decimal places 'b'. 65 | - AVG() function returns the average value in a set of values. 66 | - 'FROM' specifies the table or tables to select the data from. 67 | - 'AS' is used to give a temporary name to a table or a column in a table for the purpose of a particular query. 68 | - 'ORDER BY A' sort the result in ascending order of A. 69 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 70 | - The 'IN' operator allows you to determine if a value matches any value in a list of values. 71 | - FLOOR() function is used to return the largest integer value which will be either equal to or less than from a given input number. 72 | - CEIL() function is used to return the smallest integer value which is either greater than or equal to the given input number. 73 | 74 | */ -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/01. Population Census.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/asian-population/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT 7 | SUM(CITY.POPULATION) 8 | FROM 9 | CITY JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE 10 | WHERE 11 | COUNTRY.CONTINENT = 'Asia'; 12 | 13 | 14 | /*NOTE:- 15 | 16 | -'SELECT' QUERY is used to fetch the data from the database. 17 | - Dot (Table_name.column_name) is used to specify from which table we are looking for that column when we are retreiving data from multiple tables. 18 | -'FROM' specifies the table or tables to select the data from. 19 | - JOIN clause is used to combine and retrieve data from multiple tables, where combination is based on a related column between them. 20 | - ON clause serves for conditions that specify how to join tables. 21 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 22 | 23 | */ -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/02. African Cities.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/african-cities/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT 7 | ci.NAME 8 | FROM 9 | CITY AS ci 10 | JOIN 11 | COUNTRY AS co 12 | ON ci.COUNTRYCODE=co.CODE 13 | WHERE 14 | co.CONTINENT='Africa'; 15 | 16 | 17 | /*NOTE:- 18 | 19 | -'SELECT' QUERY is used to fetch the data from the database. 20 | -'FROM' specifies the table or tables to select the data from. 21 | - 'AS' (Alias) is used to give a temporary name to a table or a column in a table for the purpose of a particular query. In the solution, we want to fetch rows from the table CITY and COUNTRY but reference it as ci and co respectively. 22 | - Dot (Table_name.column_name) is used to specify from which table we are looking for that column when we are retreiving data from multiple tables. 23 | - JOIN clause is used to combine and retrieve data from multiple tables, where combination is based on a related column between them. 24 | - ON clause serves for conditions that specify how to join tables. 25 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 26 | 27 | */ -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/03. Average Population of Each Continent.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/average-population-of-each-continent/problem 2 | -- # Score: 10 3 | -- # Difficulty: Easy 4 | 5 | 6 | SELECT 7 | o.CONTINENT, 8 | FLOOR(AVG(i.POPULATION)) 9 | FROM 10 | CITY AS i JOIN COUNTRY AS o 11 | ON i.COUNTRYCODE=o.CODE 12 | GROUP BY 13 | o.CONTINENT; 14 | 15 | 16 | /* NOTE: 17 | 18 | - FLOOR() function is used to return the largest integer value which will be either equal to or less than from a given input number. 19 | - The AVG() function returns the average value of all records in a field. 20 | - AVG() when used with GROUP BY clause, returns the average value of group of records in a field. 21 | - JOINS are used to retrieve data from multiple tables. 22 | - ON clause serves for conditions that specify how to join tables. 23 | - AS is used to give a temporary name to a table or a column in a table for the purpose of a particular query. 24 | 25 | */ 26 | -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/04. The Report.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/the-report/problem 2 | -- # Score: 20 3 | -- # Difficulty: Medium 4 | 5 | 6 | select 7 | if(g.Grade<8, NULL, s.Name), 8 | g.grade, 9 | s.marks 10 | from 11 | Students s, 12 | Grades g 13 | where 14 | s.marks between g.Min_Mark and g.Max_Mark 15 | order by 16 | g.grade desc, 17 | s.name; 18 | 19 | 20 | /*NOTE:- 21 | 22 | -'SELECT' is used to fetch the data from the database. 23 | - The IF() function returns a value if a condition is TRUE, or another value if a condition is FALSE. 24 | Syntax:- IF(condition, value_if_true, value_if_false) 25 | - We can give a temporary name to a table or a column in a table for the purpose of a particular query. In the solution, we want to fetch rows from the table Students and Grades but reference it as s and g respectively. 26 | - Dot (Table_name.column_name) is used to specify from which table we are looking for that column when we are retreiving data from multiple tables. 27 | -'FROM' specifies the table or tables to select the data from. 28 | - Using 'WHERE' clause, we can specify a selection criteria to select the required records from a table. 29 | - The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included. 30 | - 'ORDER BY A DESC' sort the result in descending order of A. 31 | - 'ORDER BY A' sort the result in ascending order of A. 32 | - 'ORDER BY A DESC, B' sort the result in descending order of A, but for the same values of A, it will sort those values in ascending order of B. 33 | 34 | */ -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/05. Top Competitors.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/full-score/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | select h.Hacker_Id, h.Name 7 | from submissions s 8 | inner join Challenges c on c.challenge_id = s.challenge_id 9 | inner join Difficulty d on d.difficulty_level = c.difficulty_level and d.score = s.score 10 | inner join Hackers h on s.hacker_id = h.hacker_id 11 | group by h.hacker_id, h.name 12 | having count(s.score) > 1 13 | order by count(s.score) desc, h.hacker_Id; -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/06. Ollivander's Inventory.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/harry-potter-and-wands/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | SELECT 7 | W.ID, 8 | WP.AGE, 9 | W.COINS_NEEDED, 10 | W.POWER 11 | FROM 12 | WANDS AS W 13 | JOIN 14 | WANDS_PROPERTY AS WP 15 | ON (W.CODE = WP.CODE) 16 | WHERE 17 | WP.IS_EVIL = 0 18 | AND 19 | W.COINS_NEEDED=(SELECT 20 | MIN(COINS_NEEDED) 21 | FROM 22 | WANDS AS X 23 | JOIN 24 | WANDS_PROPERTY AS Y 25 | ON (X.CODE = Y.CODE) 26 | WHERE 27 | X.POWER = W.POWER 28 | AND 29 | Y.AGE = WP.AGE) 30 | ORDER BY 31 | W.POWER DESC, 32 | WP.AGE DESC; -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/07. Challenges.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/challenges/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | select 7 | h.hacker_id, 8 | h.name, 9 | count(c.challenge_id) as cnt 10 | from 11 | Hackers h 12 | join 13 | Challenges c 14 | on h.hacker_id = c.hacker_id 15 | group by 16 | h.hacker_id, 17 | h.name 18 | having 19 | cnt = ( select count(challenge_id) as cn 20 | from Challenges 21 | group by hacker_id 22 | order by cn desc 23 | limit 1 ) 24 | or 25 | cnt in (select t.total 26 | from (select count(*) as total 27 | from Challenges 28 | group by hacker_id) t 29 | group by t.total 30 | having count(t.total)=1) 31 | order by 32 | cnt desc, 33 | h.hacker_id; -------------------------------------------------------------------------------- /SQL/4. BASIC JOIN/08. Contest Leaderboard.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/contest-leaderboard/problem 2 | -- # Score: 30 3 | -- # Difficulty: Medium 4 | 5 | 6 | select 7 | t.hacker_id, 8 | h.name, 9 | sum(t.s) as total 10 | from 11 | (select 12 | hacker_id, 13 | challenge_id, 14 | max(score) as s 15 | from 16 | Submissions 17 | group by 18 | hacker_id, 19 | challenge_id 20 | ) t 21 | join 22 | hackers h 23 | on h.hacker_id= t.hacker_id 24 | group by 25 | t.hacker_id, 26 | h.name 27 | having 28 | total>0 29 | order by 30 | total desc, 31 | t.hacker_id; -------------------------------------------------------------------------------- /SQL/5. ADVANCED JOIN/01. SQL Project Planning.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/sql-projects/problem 2 | -- # Score: 40 3 | -- # Difficulty: Medium 4 | 5 | 6 | SELECT Start_Date, MIN(End_Date) FROM 7 | (SELECT Start_Date FROM Projects WHERE Start_Date NOT IN (SELECT End_Date FROM Projects)) AS sd, 8 | (SELECT End_Date FROM Projects WHERE End_Date NOT IN (SELECT Start_Date FROM Projects)) AS ed 9 | WHERE Start_Date < End_Date 10 | GROUP BY Start_Date 11 | ORDER BY DATEDIFF(MIN(End_Date), Start_Date), Start_Date; -------------------------------------------------------------------------------- /SQL/5. ADVANCED JOIN/02. SQL Symmetric Pairs.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/symmetric-pairs/problem?isFullScreen=true 2 | -- # Score: 40 3 | -- # Difficulty: Medium 4 | 5 | 6 | 7 | SELECT DISTINCT f1.x,f1.y 8 | FROM functions f1 9 | inner join functions f2 10 | ON f1.x IN f2.y 11 | AND f1.y IN f2.x 12 | WHERE f1.x < f1.y 13 | OR f1.x IN (SELECT x 14 | FROM functions 15 | WHERE x = y 16 | GROUP BY x,y 17 | HAVING Count(*) > 1) 18 | ORDER BY f1.x; 19 | 20 | -------------------------------------------------------------------------------- /SQL/5. ADVANCED JOIN/03. 15 Days of Learning SQL.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/15-days-of-learning-sql/problem?isFullScreen=true 2 | -- # Score: 50 3 | -- # Difficulty: Hard 4 | 5 | 6 | 7 | SELECT t1.submission_date, hkr_cnt, t2.hacker_id, name 8 | FROM (SELECT p1.submission_date, 9 | COUNT(DISTINCT p1.hacker_id) AS hkr_cnt 10 | FROM (SELECT submission_date, hacker_id, 11 | @h_rnk := CASE WHEN @h_grp != hacker_id THEN 1 ELSE @h_rnk+1 END AS hacker_rank, 12 | @h_grp := hacker_id AS hacker_group 13 | FROM (SELECT DISTINCT submission_date, hacker_id 14 | FROM submissions 15 | ORDER BY hacker_id, submission_date) AS a, 16 | (SELECT @h_rnk := 1, @h_grp := 0) AS r) AS p1 17 | JOIN (SELECT submission_date, 18 | @d_rnk := @d_rnk + 1 AS date_rank 19 | FROM (SELECT DISTINCT submission_date 20 | FROM submissions 21 | ORDER BY submission_date) AS b, 22 | (SELECT @d_rnk := 0) r) AS p2 23 | ON p1.submission_date = p2.submission_date 24 | AND hacker_rank = date_rank 25 | GROUP BY p1.submission_Date) AS t1 26 | JOIN (SELECT submission_date, hacker_id, sub_cnt, 27 | @s_rnk := CASE WHEN @d_grp != submission_date THEN 1 ELSE @s_rnk+1 END AS max_rnk, 28 | @d_grp := submission_date AS date_group 29 | FROM (SELECT submission_date, hacker_id, COUNT(*) AS sub_cnt 30 | FROM submissions AS s 31 | GROUP BY submission_date, hacker_id 32 | ORDER BY submission_date, sub_cnt DESC, hacker_id) AS c, 33 | (SELECT @s_rnk := 1, @d_grp := 0) AS r) AS t2 34 | ON t1.submission_date = t2.submission_date AND max_rnk = 1 35 | JOIN hackers AS h ON h.hacker_id = t2.hacker_id 36 | ORDER BY t1.submission_date 37 | ; 38 | -------------------------------------------------------------------------------- /SQL/5. ADVANCED JOIN/Interviews.sql: -------------------------------------------------------------------------------- 1 | --PROBLEM LINK 2 | --https://www.hackerrank.com/challenges/interviews/problem?isFullScreen=true 3 | 4 | --PROBLEM NAME 5 | --Interviews 6 | 7 | --LANGUAGE 8 | --SQL 9 | 10 | --SUBDOMAIN 11 | --Advanced Join 12 | 13 | --MAX SCORE 14 | --50 15 | 16 | --DIFFICULTY 17 | --Hard 18 | 19 | 20 | WITH total_submit as ( 21 | 22 | SELECT 23 | coll.contest_id, 24 | SUM(ss.total_submissions) as sumts, 25 | SUM(ss.total_accepted_submissions) as sumtas 26 | FROM Colleges coll 27 | INNER JOIN Challenges chall ON chall.college_id = coll.college_id 28 | INNER JOIN Submission_Stats ss ON chall.challenge_id = ss.challenge_id 29 | GROUP BY coll.contest_id 30 | 31 | ), 32 | 33 | total_view as ( 34 | 35 | SELECT 36 | coll.contest_id, 37 | SUM(vs.total_views) as sumtv, 38 | SUM(vs.total_unique_views) as sumtuv 39 | FROM Colleges coll 40 | INNER JOIN Challenges chall ON chall.college_id = coll.college_id 41 | INNER JOIN View_Stats vs ON chall.challenge_id = vs.challenge_id 42 | GROUP BY coll.contest_id 43 | 44 | ) 45 | 46 | SELECT 47 | cont.contest_id, 48 | cont.hacker_id, 49 | cont.name, 50 | ts.sumts, 51 | ts.sumtas, 52 | tv.sumtv, 53 | tv.sumtuv 54 | FROM Contests cont 55 | INNER JOIN total_submit ts ON ts.contest_id = cont.contest_id 56 | INNER JOIN total_view tv ON tv.contest_id = cont.contest_id 57 | WHERE ts.sumts > 0 58 | OR ts.sumtas > 0 59 | OR tv.sumtv > 0 60 | OR tv.sumtuv > 0 61 | ORDER BY cont.contest_id 62 | ; 63 | -------------------------------------------------------------------------------- /SQL/6. ALTERNATIVE QUERIES/01. Draw The Triangle 1.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/draw-the-triangle-1/problem 2 | -- # Score: 25 3 | -- # Difficulty: Easy 4 | 5 | 6 | SET @num = 21; 7 | SELECT REPEAT('* ', @num := @num - 1) 8 | FROM information_schema.tables 9 | WHERE @num > 0; -------------------------------------------------------------------------------- /SQL/6. ALTERNATIVE QUERIES/02. Draw The Triangle 2.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/draw-the-triangle-2/problem 2 | -- # Score: 25 3 | -- # Difficulty: Easy 4 | 5 | 6 | SET @num = 0; 7 | SELECT REPEAT('* ', @num := @num + 1) 8 | FROM information_schema.tables 9 | limit 20; --------------------------------------------------------------------------------