diff --git a/HackerRank-C-main/1D Arrays in C.c b/HackerRank-C-main/1D Arrays in C.c new file mode 100644 index 00000000..4db5cbd8 --- /dev/null +++ b/HackerRank-C-main/1D Arrays in C.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +int main() { + + /* Enter your code here. Read input from STDIN. Print output to STDOUT */ + unsigned int n; + scanf("%u",&n); + unsigned int a[n],sum=0; + for (int i=0; i +#include + +int main() +{ + int num, *arr, i; + scanf("%d", &num); + arr = (int*) malloc(num * sizeof(int)); + for(i = 0; i < num; i++) { + scanf("%d", arr + i); + } + + + /* Write the logic to reverse the array. */ + int temp=0; + for(int i=0,j=num-1;i<=j;i++,j--){ + temp=arr[i]; + arr[i]=arr[j]; + arr[j]=temp; + } + + for(i = 0; i < num; i++) + printf("%d ", *(arr + i)); + return 0; +} diff --git a/HackerRank-C-main/Bitwise Operators.c b/HackerRank-C-main/Bitwise Operators.c new file mode 100644 index 00000000..9ac99ae0 --- /dev/null +++ b/HackerRank-C-main/Bitwise Operators.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +//Complete the following function. + + +void calculate_the_maximum(int n, int k) { + int AND=0,OR=0,XOR=0; + for (int i=1;i<=n;i++){ + for(int j=i+1;j<=n;j++){ + if (((i&j) > AND) && ((i&j) < k)) { + AND = i&j; + } + if (((i|j) > OR) && ((i|j) < k)) { + OR = i|j; + } + if (((i^j) > XOR) && ((i^j) < k)) { + XOR = i^j; + } + } + } + printf("%d\n%d\n%d\n",AND,OR,XOR); +} + +int main() { + int n, k; + + scanf("%d %d", &n, &k); + calculate_the_maximum(n, k); + + return 0; +} diff --git a/HackerRank-C-main/Boxes through a Tunnel.c b/HackerRank-C-main/Boxes through a Tunnel.c new file mode 100644 index 00000000..ddcde0bf --- /dev/null +++ b/HackerRank-C-main/Boxes through a Tunnel.c @@ -0,0 +1,40 @@ +#include +#include +#define MAX_HEIGHT 41 + +struct box +{ + /* Define three fields of type int: length, width and height*/ + int length, width, height; +}; + +typedef struct box box; + +int get_volume(box b) { + /*Return the volume of the box*/ + return (b.length)*(b.width)*(b.height); //volume=length*width*height +} + +int is_lower_than_max_height(box b) { + /* Return 1 if the box's height is lower than MAX_HEIGHT and 0 otherwise*/ + if (b.height +#include +#include +#include +//Complete the following function. + +int find_nth_term(int n, int a, int b, int c) { + //Write your code here. + if (n<=4) + return 6; + return find_nth_term(n-1,a-1,b-2,c-3); +} + +int main() { + int n, a, b, c; + + scanf("%d %d %d %d", &n, &a, &b, &c); + int ans = find_nth_term(n, a, b, c); + + printf("%d", ans); + return 0; +} diff --git a/HackerRank-C-main/Conditional Statements in C.c b/HackerRank-C-main/Conditional Statements in C.c new file mode 100644 index 00000000..79f59a91 --- /dev/null +++ b/HackerRank-C-main/Conditional Statements in C.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char* readline(); + + + +int main() +{ + char* n_endptr; + char* n_str = readline(); + int n = strtol(n_str, &n_endptr, 10); + + if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); } + + // Write Your Code Here + if (n==1) + printf("one"); + else if (n==2) + printf("two"); + else if (n==3) + printf("three"); + else if (n==4) + printf("four"); + else if (n==5) + printf("five"); + else if (n==6) + printf("six"); + else if (n==7) + printf("seven"); + else if (n==8) + printf("eight"); + else if (n==9) + printf("nine"); + else + printf("Greater than 9"); + return 0; +} + +char* readline() { + size_t alloc_length = 1024; + size_t data_length = 0; + char* data = malloc(alloc_length); + + while (true) { + char* cursor = data + data_length; + char* line = fgets(cursor, alloc_length - data_length, stdin); + + if (!line) { break; } + + data_length += strlen(cursor); + + if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; } + + size_t new_length = alloc_length << 1; + data = realloc(data, new_length); + + if (!data) { break; } + + alloc_length = new_length; + } + + if (data[data_length - 1] == '\n') { + data[data_length - 1] = '\0'; + } + + data = realloc(data, data_length); + + return data; +} diff --git a/HackerRank-C-main/Digit Frequency.c b/HackerRank-C-main/Digit Frequency.c new file mode 100644 index 00000000..6e05fe16 --- /dev/null +++ b/HackerRank-C-main/Digit Frequency.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +int main() { + + char S[1000]; + int h[10]={0,0,0,0,0,0,0,0,0,0} ; //hasing technique + + scanf("%s",S); + + for(int i = 0 ; i <= strlen(S);i++){ + if(S[i]>='0' && S[i]<='9') + h[S[i]-'0']++ ; + } + + for(int i = 0 ; i <= 9 ;i++) + printf("%d ",h[i]) ; + + return 0; +} diff --git a/HackerRank-C-main/Dynamic Array in C.c b/HackerRank-C-main/Dynamic Array in C.c new file mode 100644 index 00000000..ac8bedb1 --- /dev/null +++ b/HackerRank-C-main/Dynamic Array in C.c @@ -0,0 +1,68 @@ +#include +#include + +int* total_number_of_books; + +int** total_number_of_pages; + +int main() +{ + int total_number_of_shelves; + scanf("%d", &total_number_of_shelves); + + int total_number_of_queries; + scanf("%d", &total_number_of_queries); + + total_number_of_books=(int*)malloc(sizeof(int)*total_number_of_shelves); + + total_number_of_pages=(int**)malloc(sizeof(int*)*total_number_of_shelves); + + for(int i=0; i +#include +#include +#include + + + +int main() +{ + int a, b; + scanf("%d\n%d", &a, &b); + // Complete the code. + char c[10][10]={"","one","two","three","four","five","six","seven","eight","nine"}; + for (int n=a; n<=b; n++) { + ((n<=9)?printf("%s\n",c[n]):(n%2==0)?printf("even\n"):printf("odd\n")); + } + return 0; +} + diff --git a/HackerRank-C-main/Functions in C.c b/HackerRank-C-main/Functions in C.c new file mode 100644 index 00000000..2a2f29d3 --- /dev/null +++ b/HackerRank-C-main/Functions in C.c @@ -0,0 +1,16 @@ +#include +/* +Add `int max_of_four(int a, int b, int c, int d)` here. +*/ +int max_of_four(int w,int x,int y,int z){ + return ((w>x && w>y && w>z)?w:(x>w && x>y && x>z)?x:(y>w && y>x && y>z)?y:z); +} + +int main() { + int a, b, c, d; + scanf("%d %d %d %d", &a, &b, &c, &d); + int ans = max_of_four(a, b, c, d); + printf("%d", ans); + + return 0; +} diff --git a/HackerRank-C-main/Playing With Characters.c b/HackerRank-C-main/Playing With Characters.c new file mode 100644 index 00000000..505ee8a1 --- /dev/null +++ b/HackerRank-C-main/Playing With Characters.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +int main() +{ + + /* Enter your code here. Read input from STDIN. Print output to STDOUT */ + char ch,s[100],sen[100]; + scanf("%c",&ch); + scanf("%s",s); + scanf(" %[^\n]s",sen); + printf("%c\n",ch); + printf("%s\n",s); + printf("%s\n",sen); + + return 0; +} diff --git a/HackerRank-C-main/Pointers in C.c b/HackerRank-C-main/Pointers in C.c new file mode 100644 index 00000000..cbdaaff2 --- /dev/null +++ b/HackerRank-C-main/Pointers in C.c @@ -0,0 +1,23 @@ +#include + +void update(int *a,int *b) { + // Complete this function + int bb; + bb = *a; + *a=*a+*b; + if (bb>*b) + *b=bb-*b; + else + *b=*b-bb; +} + +int main() { + int a, b; + int *pa = &a, *pb = &b; + + scanf("%d %d", &a, &b); + update(pa, pb); + printf("%d\n%d", a, b); + + return 0; +} diff --git a/HackerRank-C-main/Printing Pattern Using Loops.c b/HackerRank-C-main/Printing Pattern Using Loops.c new file mode 100644 index 00000000..69c9599c --- /dev/null +++ b/HackerRank-C-main/Printing Pattern Using Loops.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +int main() +{ + + int n; + scanf("%d", &n); + // Complete the code to print the pattern. + int len = n*2 - 1; + for(int i=0;i +#include +#include +#include + +int main() { + + char *s; + s = malloc(1024 * sizeof(char)); + scanf("%[^\n]", s); + s = realloc(s, strlen(s) + 1); + //Write your logic to print the tokens of the sentence here. + for(int i=0;i C C + +# List of Problems + + +| Problem | Subdomain | Problem Link| +| ----------- | ----------- | ----------- | +| "Hello World!" in C | Introduction| [Link](https://www.hackerrank.com/challenges/hello-world-c) | +| Playing With Characters| Introduction| [Link](https://www.hackerrank.com/challenges/playing-with-characters) | +| Sum and Difference of Two Numbers| Introduction| [Link](https://www.hackerrank.com/challenges/sum-numbers-c) | +| Functions in C | Introduction| [Link](https://www.hackerrank.com/challenges/functions-in-c) | +| Pointers in C | Introduction| [Link](https://www.hackerrank.com/challenges/pointer-in-c) | +| Conditional Statements in C |Conditionals and Loops| [Link](https://www.hackerrank.com/challenges/conditional-statements-in-c)| +| For Loop in C |Conditionals and Loops| [Link](https://www.hackerrank.com/challenges/for-loop-in-c)| +| Sum of Digits of a Five Digit Number|Conditionals and Loops| [Link](https://www.hackerrank.com/challenges/sum-of-digits-of-a-five-digit-number)| +| Bitwise Operators |Conditionals and Loops| [Link](https://www.hackerrank.com/challenges/bitwise-operators-in-c)| +| Printing Pattern Using Loops |Conditionals and Loops| [Link](https://www.hackerrank.com/challenges/printing-pattern-2)| +| 1D Arrays in C| Arrays and Strings |[Link](https://www.hackerrank.com/challenges/1d-arrays-in-c)| +| Array Reversal | Arrays and Strings |[Link](https://www.hackerrank.com/challenges/reverse-array-c)| +| Printing Tokens | Arrays and Strings |[Link](https://www.hackerrank.com/challenges/printing-tokens-)| +| Digit Frequency | Arrays and Strings |[Link](https://www.hackerrank.com/challenges/frequency-of-digits-1/problem)| +| Dynamic Array in C | Arrays and Strings |[Link](https://www.hackerrank.com/challenges/dynamic-array-in-c/problem)| +| Calculate the Nth term | Functions |[Link](https://www.hackerrank.com/challenges/recursion-in-c)| +| Students Marks Sum | Functions |[Link](https://www.hackerrank.com/challenges/students-marks-sum)| +| Variadic functions in C | Functions |[Link](https://www.hackerrank.com/challenges/variadic-functions-in-c)| +| Boxes through a Tunnel | Structs and Enums |[Link](https://www.hackerrank.com/challenges/too-high-boxes)| +| Small Triangles, Large Triangles | Structs and Enums |[Link](https://www.hackerrank.com/challenges/small-triangles-large-triangles)| diff --git a/HackerRank-C-main/Small Triangles, Large Triangles.c b/HackerRank-C-main/Small Triangles, Large Triangles.c new file mode 100644 index 00000000..ff7fef9f --- /dev/null +++ b/HackerRank-C-main/Small Triangles, Large Triangles.c @@ -0,0 +1,49 @@ +#include +#include +#include + +struct triangle +{ + int a; + int b; + int c; +}; + +typedef struct triangle triangle; + +/*for finding area of triangle*/ +double area(triangle tr){ + double p=(tr.a+tr.b+tr.c)/2.0; + return sqrt(p*(p-tr.a)*(p-tr.b)*(p-tr.c)); +} +/*for swapping triangles*/ +void swap(triangle* t1,triangle* t2){ + triangle temp; + temp=*t1; + *t1=*t2; + *t2=temp; +} +void sort_by_area(triangle* tr, int n) { + /* Sort an array a of the length n*/ + /*Bubble sort*/ + for (int i=0;iarea(tr[j+1])) + swap(&tr[j],&tr[j+1]); + } +} + +int main() +{ + int n; + scanf("%d", &n); + triangle *tr = malloc(n * sizeof(triangle)); + for (int i = 0; i < n; i++) { + scanf("%d%d%d", &tr[i].a, &tr[i].b, &tr[i].c); + } + sort_by_area(tr, n); + for (int i = 0; i < n; i++) { + printf("%d %d %d\n", tr[i].a, tr[i].b, tr[i].c); + } + return 0; +} diff --git a/HackerRank-C-main/Students Marks Sum.c b/HackerRank-C-main/Students Marks Sum.c new file mode 100644 index 00000000..652243a8 --- /dev/null +++ b/HackerRank-C-main/Students Marks Sum.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +//Complete the following function. + +int marks_summation(int* marks, int number_of_students, char gender) { + //Write your code here. + int girls_sum=0; + int boys_sum=0; + for (int i=0;i +#include +#include +#include + +int main() +{ + + int a,b; + float c,d; + scanf("%d %d",&a,&b); + scanf("%f %f",&c,&d); + printf("%d %d\n",a+b,a-b); + printf("%.1f %.1f",c+d,c-d); + return 0; +} diff --git a/HackerRank-C-main/Sum of Digits of a Five Digit Number.c b/HackerRank-C-main/Sum of Digits of a Five Digit Number.c new file mode 100644 index 00000000..3d824f6a --- /dev/null +++ b/HackerRank-C-main/Sum of Digits of a Five Digit Number.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +int main() { + + int n; + scanf("%d", &n); + //Complete the code to calculate the sum of the five digits on n. + int sum=0; + while (n>0){ + sum+=n%10; + n/=10; + } + printf("%d\n",sum); + return 0; +} diff --git a/HackerRank-C-main/Variadic functions in C.c b/HackerRank-C-main/Variadic functions in C.c new file mode 100644 index 00000000..7cde0e19 --- /dev/null +++ b/HackerRank-C-main/Variadic functions in C.c @@ -0,0 +1,205 @@ +#include +#include +#include +#include + +#define MIN_ELEMENT 1 +#define MAX_ELEMENT 1000000 +/* Go through the link to understand c standard library +https://www.tutorialspoint.com/c_standard_library/stdarg_h.htm +*/ +/*This is a type suitable for holding information needed by the three macros va_start(), va_arg() and va_end().*/ +int sum (int count,...) { + int sum=0; + va_list values; + va_start(values,count); + for(int i=0;itest){ + min=test; + } + } + va_end(values); + return min; +} + +int max(int count,...) { + int max=MIN_ELEMENT,test; + va_list values; + va_start(values,count); + for(int i=0;i maximum_element) { + return 0; + } + + expected_elements_sum += elements[i]; + } + + return elements_sum == expected_elements_sum; +} + +int test_implementations_by_sending_five_elements() { + srand(time(NULL)); + + int elements[5]; + + elements[0] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[1] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[2] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[3] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[4] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + + fprintf(stderr, "Sending following five elements:\n"); + for (int i = 0; i < 5; i++) { + fprintf(stderr, "%d\n", elements[i]); + } + + int elements_sum = sum(5, elements[0], elements[1], elements[2], elements[3], elements[4]); + int minimum_element = min(5, elements[0], elements[1], elements[2], elements[3], elements[4]); + int maximum_element = max(5, elements[0], elements[1], elements[2], elements[3], elements[4]); + + fprintf(stderr, "Your output is:\n"); + fprintf(stderr, "Elements sum is %d\n", elements_sum); + fprintf(stderr, "Minimum element is %d\n", minimum_element); + fprintf(stderr, "Maximum element is %d\n\n", maximum_element); + + int expected_elements_sum = 0; + for (int i = 0; i < 5; i++) { + if (elements[i] < minimum_element) { + return 0; + } + + if (elements[i] > maximum_element) { + return 0; + } + + expected_elements_sum += elements[i]; + } + + return elements_sum == expected_elements_sum; +} + +int test_implementations_by_sending_ten_elements() { + srand(time(NULL)); + + int elements[10]; + + elements[0] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[1] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[2] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[3] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[4] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[5] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[6] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[7] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[8] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + elements[9] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; + + fprintf(stderr, "Sending following ten elements:\n"); + for (int i = 0; i < 10; i++) { + fprintf(stderr, "%d\n", elements[i]); + } + + int elements_sum = sum(10, elements[0], elements[1], elements[2], elements[3], elements[4], + elements[5], elements[6], elements[7], elements[8], elements[9]); + int minimum_element = min(10, elements[0], elements[1], elements[2], elements[3], elements[4], + elements[5], elements[6], elements[7], elements[8], elements[9]); + int maximum_element = max(10, elements[0], elements[1], elements[2], elements[3], elements[4], + elements[5], elements[6], elements[7], elements[8], elements[9]); + + fprintf(stderr, "Your output is:\n"); + fprintf(stderr, "Elements sum is %d\n", elements_sum); + fprintf(stderr, "Minimum element is %d\n", minimum_element); + fprintf(stderr, "Maximum element is %d\n\n", maximum_element); + + int expected_elements_sum = 0; + for (int i = 0; i < 10; i++) { + if (elements[i] < minimum_element) { + return 0; + } + + if (elements[i] > maximum_element) { + return 0; + } + + expected_elements_sum += elements[i]; + } + + return elements_sum == expected_elements_sum; +} + +int main () +{ + int number_of_test_cases; + scanf("%d", &number_of_test_cases); + + while (number_of_test_cases--) { + if (test_implementations_by_sending_three_elements()) { + printf("Correct Answer\n"); + } else { + printf("Wrong Answer\n"); + } + + if (test_implementations_by_sending_five_elements()) { + printf("Correct Answer\n"); + } else { + printf("Wrong Answer\n"); + } + + if (test_implementations_by_sending_ten_elements()) { + printf("Correct Answer\n"); + } else { + printf("Wrong Answer\n"); + } + } + + return 0; +} diff --git a/HackerRank-C-main/_Hello World!_ in C.c b/HackerRank-C-main/_Hello World!_ in C.c new file mode 100644 index 00000000..67f0c170 --- /dev/null +++ b/HackerRank-C-main/_Hello World!_ in C.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +int main() +{ + + char s[100]; + scanf("%[^\n]%*c", &s); + + /* Enter your code here. Read input from STDIN. Print output to STDOUT */ + printf("Hello, World!\n"); + printf("%s",s); + return 0; +} diff --git a/HackerRank-Python-main/Alphabet Rangoli.py b/HackerRank-Python-main/Alphabet Rangoli.py new file mode 100644 index 00000000..ac7c7152 --- /dev/null +++ b/HackerRank-Python-main/Alphabet Rangoli.py @@ -0,0 +1,12 @@ +import string + +def print_rangoli(n): + alpha = string.ascii_lowercase + L = [] + for i in range(n): + s = "-".join(alpha[i:n]) + L.append((s[::-1]+s[1:]).center(4*n-3, "-")) + print('\n'.join(L[:0:-1]+L)) +if __name__ == '__main__': + n = int(input()) + print_rangoli(n) diff --git a/HackerRank-Python-main/Arithmetic Operators.py b/HackerRank-Python-main/Arithmetic Operators.py new file mode 100644 index 00000000..e71213fc --- /dev/null +++ b/HackerRank-Python-main/Arithmetic Operators.py @@ -0,0 +1,6 @@ +if __name__ == '__main__': + a = int(input()) + b = int(input()) + print(a+b) + print(a-b) + print(a*b) diff --git a/HackerRank-Python-main/Calendar Module.py b/HackerRank-Python-main/Calendar Module.py new file mode 100644 index 00000000..8748015a --- /dev/null +++ b/HackerRank-Python-main/Calendar Module.py @@ -0,0 +1,4 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +import calendar +m,d,y=map(int,input().split()) +print(list(calendar.day_name)[calendar.weekday(y, m, d)].upper()) diff --git a/HackerRank-Python-main/Capitalize!.py b/HackerRank-Python-main/Capitalize!.py new file mode 100644 index 00000000..f9d6c757 --- /dev/null +++ b/HackerRank-Python-main/Capitalize!.py @@ -0,0 +1,23 @@ +#!/bin/python3 + +import math +import os +import random +import re +import sys +import string + +# Complete the solve function below. +def solve(s): + return string.capwords(s, ' ') + +if __name__ == '__main__': + fptr = open(os.environ['OUTPUT_PATH'], 'w') + + s = input() + + result = solve(s) + + fptr.write(result + '\n') + + fptr.close() diff --git a/HackerRank-Python-main/Designer Door Mat.py b/HackerRank-Python-main/Designer Door Mat.py new file mode 100644 index 00000000..788917ed --- /dev/null +++ b/HackerRank-Python-main/Designer Door Mat.py @@ -0,0 +1,4 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +n, m = map(int,input().split()) +pattern = [('.|.'*(2*i + 1)).center(m, '-') for i in range(n//2)] +print('\n'.join(pattern + ['WELCOME'.center(m, '-')] + pattern[::-1])) diff --git a/HackerRank-Python-main/Find a String.py b/HackerRank-Python-main/Find a String.py new file mode 100644 index 00000000..66dcaeb1 --- /dev/null +++ b/HackerRank-Python-main/Find a String.py @@ -0,0 +1,16 @@ +def count_substring(string, sub_string): + count =0 + for i in range(len(string)-len(sub_string)+1): + try: + if string[i:i+len(sub_string)]==sub_string: + count+=1 + except IndexError: + break + return count + +if __name__ == '__main__': + string = input().strip() + sub_string = input().strip() + + count = count_substring(string, sub_string) + print(count) diff --git a/HackerRank-Python-main/Find the Runner-Up Score!.py b/HackerRank-Python-main/Find the Runner-Up Score!.py new file mode 100644 index 00000000..d178e956 --- /dev/null +++ b/HackerRank-Python-main/Find the Runner-Up Score!.py @@ -0,0 +1,9 @@ +if __name__ == '__main__': + n = int(input()) + arr = list(map(int, input().split())) + arr.sort(reverse=True) + first=arr[0] + for i in range(len(arr)): + if (first>arr[i]): + print(arr[i]) + break diff --git a/HackerRank-Python-main/Finding the percentage.py b/HackerRank-Python-main/Finding the percentage.py new file mode 100644 index 00000000..6c3ced7d --- /dev/null +++ b/HackerRank-Python-main/Finding the percentage.py @@ -0,0 +1,9 @@ +if __name__ == '__main__': + n = int(input()) + student_marks = {} + for _ in range(n): + name, *line = input().split() + scores = list(map(float, line)) + student_marks[name] = scores + query_name = input() + print('{:.2f}'.format(sum(student_marks[query_name])/len(student_marks[query_name]))) diff --git a/HackerRank-Python-main/Incorrect Regex.py b/HackerRank-Python-main/Incorrect Regex.py new file mode 100644 index 00000000..9cdfb77b --- /dev/null +++ b/HackerRank-Python-main/Incorrect Regex.py @@ -0,0 +1,7 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +import re +for t in range(int(input())): + try: + print(bool(re.compile(input()))) + except: + print('False') diff --git a/HackerRank-Python-main/Input().py b/HackerRank-Python-main/Input().py new file mode 100644 index 00000000..724a42eb --- /dev/null +++ b/HackerRank-Python-main/Input().py @@ -0,0 +1,7 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +x,k=map(int,input().split()) +p=input() +if eval(p)==k: + print(True) +else: + print(False) diff --git a/HackerRank-Python-main/Integers Come In All Sizes.py b/HackerRank-Python-main/Integers Come In All Sizes.py new file mode 100644 index 00000000..c7606da2 --- /dev/null +++ b/HackerRank-Python-main/Integers Come In All Sizes.py @@ -0,0 +1,6 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +a=int(input()) +b=int(input()) +c=int(input()) +d=int(input()) +print(pow(a,b)+pow(c,d)) diff --git a/HackerRank-Python-main/List Comprehensions.py b/HackerRank-Python-main/List Comprehensions.py new file mode 100644 index 00000000..301084b3 --- /dev/null +++ b/HackerRank-Python-main/List Comprehensions.py @@ -0,0 +1,3 @@ +if __name__ == '__main__': + x, y, z, n = int(input()), int(input()), int(input()), int(input()) +print ([[a,b,c] for a in range(0,x+1) for b in range(0,y+1) for c in range(0,z+1) if a + b + c != n ]) diff --git a/HackerRank-Python-main/Lists.py b/HackerRank-Python-main/Lists.py new file mode 100644 index 00000000..8ec93a0e --- /dev/null +++ b/HackerRank-Python-main/Lists.py @@ -0,0 +1,11 @@ +n = int(input()) +l = [] +for _ in range(n): + s = input().split() + cmd = s[0] + args = s[1:] + if (cmd !="print"): + cmd += "("+ ",".join(args) +")" + eval("l."+cmd) + else: + print (l) diff --git a/HackerRank-Python-main/Loops.py b/HackerRank-Python-main/Loops.py new file mode 100644 index 00000000..c8869e0e --- /dev/null +++ b/HackerRank-Python-main/Loops.py @@ -0,0 +1,4 @@ +if __name__ == '__main__': + n = int(input()) + for i in range(n): + print(i**2) diff --git a/HackerRank-Python-main/Mod Divmod.py b/HackerRank-Python-main/Mod Divmod.py new file mode 100644 index 00000000..7657927a --- /dev/null +++ b/HackerRank-Python-main/Mod Divmod.py @@ -0,0 +1,6 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +a=int(input()) +b=int(input()) +print(a//b) +print(a%b) +print(divmod(a,b)) diff --git a/HackerRank-Python-main/Mutations.py b/HackerRank-Python-main/Mutations.py new file mode 100644 index 00000000..603cbc1f --- /dev/null +++ b/HackerRank-Python-main/Mutations.py @@ -0,0 +1,8 @@ +def mutate_string(string, position, character): + return (string[:position]+character+string[position+1:]) + +if __name__ == '__main__': + s = input() + i, c = input().split() + s_new = mutate_string(s, int(i), c) + print(s_new) diff --git a/HackerRank-Python-main/Nested Lists.py b/HackerRank-Python-main/Nested Lists.py new file mode 100644 index 00000000..7d2968c5 --- /dev/null +++ b/HackerRank-Python-main/Nested Lists.py @@ -0,0 +1,6 @@ +marksheet = [] +for _ in range(0,int(input())): + marksheet.append([input(), float(input())]) + +second_highest = sorted(list(set([marks for name, marks in marksheet])))[1] +print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest])) diff --git a/HackerRank-Python-main/Polar Coordinates.py b/HackerRank-Python-main/Polar Coordinates.py new file mode 100644 index 00000000..f6529e38 --- /dev/null +++ b/HackerRank-Python-main/Polar Coordinates.py @@ -0,0 +1,3 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +from cmath import polar +print ('{}\n{}'.format(*polar(complex(input())))) diff --git a/HackerRank-Python-main/Power - Mod Power.py b/HackerRank-Python-main/Power - Mod Power.py new file mode 100644 index 00000000..ed38798c --- /dev/null +++ b/HackerRank-Python-main/Power - Mod Power.py @@ -0,0 +1,6 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +a=int(input()) +b=int(input()) +m=int(input()) +print(pow(a,b)) +print(pow(a,b,m)) diff --git a/HackerRank-Python-main/Print Function.py b/HackerRank-Python-main/Print Function.py new file mode 100644 index 00000000..a81e9728 --- /dev/null +++ b/HackerRank-Python-main/Print Function.py @@ -0,0 +1,4 @@ +if __name__ == '__main__': + n = int(input()) + for i in range(1,n+1): + print(i,end='') diff --git a/HackerRank-Python-main/Python If-Else.py b/HackerRank-Python-main/Python If-Else.py new file mode 100644 index 00000000..e8d69baf --- /dev/null +++ b/HackerRank-Python-main/Python If-Else.py @@ -0,0 +1,20 @@ +#!/bin/python3 + +import math +import os +import random +import re +import sys + + + +if __name__ == '__main__': + n = int(input().strip()) + if (n%2==0 and n in range(2,6)): + print('Not Weird') + elif (n%2==0 and n in range(6,21)): + print('Weird') + elif(n%2==0 and n>20): + print('Not Weird') + elif(n%2!=0): + print('Weird') diff --git a/HackerRank-Python-main/Python_ Division.py b/HackerRank-Python-main/Python_ Division.py new file mode 100644 index 00000000..1908c3ff --- /dev/null +++ b/HackerRank-Python-main/Python_ Division.py @@ -0,0 +1,5 @@ +if __name__ == '__main__': + a = int(input()) + b = int(input()) + print(a//b) + print(a/b) diff --git a/HackerRank-Python-main/README.md b/HackerRank-Python-main/README.md new file mode 100644 index 00000000..34a6bf11 --- /dev/null +++ b/HackerRank-Python-main/README.md @@ -0,0 +1,49 @@ +# HackerRank-Python +This repository contains **HackerRank Python** Problem Solution. + +Follow me on **HackerRank** [Click here!](https://www.hackerrank.com/arwazkhan189) + +> Python Python + +# List of Problems + + +| Problem | Subdomain | Problem Link| +| ----------- | ----------- | ----------- | +| Say "Hello, World!" With Python | Introduction | [Link](https://www.hackerrank.com/challenges/py-hello-world) | +| Python If-Else | Introduction | [Link](https://www.hackerrank.com/challenges/py-if-else) | +| Arithmetic Operators | Introduction | [Link](https://www.hackerrank.com/challenges/python-arithmetic-operators) | +| Python: Division | Introduction | [Link](https://www.hackerrank.com/challenges/python-division) | +| Loops | Introduction | [Link](https://www.hackerrank.com/challenges/python-loops) | +| Write a function | Introduction | [Link](https://www.hackerrank.com/challenges/write-a-function) | +| Print Function | Introduction | [Link](https://www.hackerrank.com/challenges/python-print) | +| List Comprehensions | Basic Data Types | [Link](https://www.hackerrank.com/challenges/list-comprehensions) | +| Find the Runner-Up Score! | Basic Data Types | [Link](https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list) | +| Nested Lists | Basic Data Types | [Link](https://www.hackerrank.com/challenges/nested-list) | +| Finding the percentage | Basic Data Types | [Link](https://www.hackerrank.com/challenges/finding-the-percentage) | +| Lists | Basic Data Types | [Link](https://www.hackerrank.com/challenges/python-lists) | +| Tuples | Basic Data Types | [Link](https://www.hackerrank.com/challenges/python-tuples) | +| sWAP cASE | Strings | [Link](https://www.hackerrank.com/challenges/swap-case) | +| String Split and Join | Strings | [Link](https://www.hackerrank.com/challenges/python-string-split-and-join) | +| What's Your Name? | Strings | [Link](https://www.hackerrank.com/challenges/whats-your-name) | +| Mutations | Strings | [Link](https://www.hackerrank.com/challenges/python-mutations) | +| Find a string | Strings | [Link](https://www.hackerrank.com/challenges/find-a-string) | +| String Validators | Strings | [Link](https://www.hackerrank.com/challenges/string-validators) | +| Tesxt Alignment | Strings | [Link](https://www.hackerrank.com/challenges/text-alignment) | +| Text Wrap | Strings | [Link](https://www.hackerrank.com/challenges/text-wrap) | +| Designer Door Mat | Strings | [Link](https://www.hackerrank.com/challenges/designer-door-mat) | +| String Formatting | Strings | [Link](https://www.hackerrank.com/challenges/python-string-formatting) | +| Alphabet Rangoli | Strings | [Link](https://www.hackerrank.com/challenges/alphabet-rangoli) | +| Capitalize! | Strings | [Link](https://www.hackerrank.com/challenges/capitalize) | +| Set .discard(), .remove() & .pop() | Sets | [Link](https://www.hackerrank.com/challenges/py-set-discard-remove-pop) | +| Set .union() Operation | Sets | [Link](https://www.hackerrank.com/challenges/py-set-union) | +| Set .intersection() Operation | Sets | [Link](https://www.hackerrank.com/challenges/py-set-intersection-operation) | +| Set .difference() Operation | Sets | [Link](https://www.hackerrank.com/challenges/py-set-difference-operation) | +| Polar Coordinates | Math | [Link](https://www.hackerrank.com/challenges/polar-coordinates) | +| Mod Divmod | Math | [Link](https://www.hackerrank.com/challenges/python-mod-divmod) | +| Power - Mod Power | Math | [Link](https://www.hackerrank.com/challenges/python-power-mod-power) | +| Integers Come In All Sizes | Math | [Link](https://www.hackerrank.com/challenges/python-integers-come-in-all-sizes) | +| Triangle Quest | Math | [Link](https://www.hackerrank.com/challenges/python-quest-1) | +| Calendar Module | Date and Time | [Link](https://www.hackerrank.com/challenges/calendar-module) | +| Incorrect Regex | Errors and Exceptions | [Link](https://www.hackerrank.com/challenges/incorrect-regex) | +| Input() | Built-Ins | [Link](https://www.hackerrank.com/challenges/input) | diff --git a/HackerRank-Python-main/Say _Hello, World!_ With Python.py b/HackerRank-Python-main/Say _Hello, World!_ With Python.py new file mode 100644 index 00000000..7df869a1 --- /dev/null +++ b/HackerRank-Python-main/Say _Hello, World!_ With Python.py @@ -0,0 +1 @@ +print("Hello, World!") diff --git a/HackerRank-Python-main/Set .difference() Operation.py b/HackerRank-Python-main/Set .difference() Operation.py new file mode 100644 index 00000000..20a48647 --- /dev/null +++ b/HackerRank-Python-main/Set .difference() Operation.py @@ -0,0 +1,6 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +ne=int(input()) +re=set(map(int,input().split())) +nb=int(input()) +rb=set(map(int,input().split())) +print(len(re-rb)) diff --git a/HackerRank-Python-main/Set .discard(), .remove() & .pop().py b/HackerRank-Python-main/Set .discard(), .remove() & .pop().py new file mode 100644 index 00000000..368f0a94 --- /dev/null +++ b/HackerRank-Python-main/Set .discard(), .remove() & .pop().py @@ -0,0 +1,6 @@ +n = int(input()) +s = set(map(int, input().split())) +for i in range(int(input())): + eval('s.{0}({1})'.format(*input().split()+[''])) + +print(sum(s)) diff --git a/HackerRank-Python-main/Set .intersection() Operation.py b/HackerRank-Python-main/Set .intersection() Operation.py new file mode 100644 index 00000000..e148e9f6 --- /dev/null +++ b/HackerRank-Python-main/Set .intersection() Operation.py @@ -0,0 +1,6 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +ne=int(input()) +re=set(map(int,input().split())) +nb=int(input()) +rb=set(map(int,input().split())) +print(len(re&rb)) diff --git a/HackerRank-Python-main/Set .union() Operation.py b/HackerRank-Python-main/Set .union() Operation.py new file mode 100644 index 00000000..9caf7e24 --- /dev/null +++ b/HackerRank-Python-main/Set .union() Operation.py @@ -0,0 +1,6 @@ +# Enter your code here. Read input from STDIN. Print output to STDOUT +ne=int(input()) +re=set(map(int,input().split())) +nb=int(input()) +rb=set(map(int,input().split())) +print(len(re|rb)) diff --git a/HackerRank-Python-main/String Formatting.py b/HackerRank-Python-main/String Formatting.py new file mode 100644 index 00000000..8c08b364 --- /dev/null +++ b/HackerRank-Python-main/String Formatting.py @@ -0,0 +1,8 @@ +def print_formatted(number): + # your code goes here + width = len("{0:b}".format(number)) + for i in range(1,n+1): + print( "{0:{width}d} {0:{width}o} {0:{width}X} {0:{width}b}".format(i, width=width)) +if __name__ == '__main__': + n = int(input()) + print_formatted(n) diff --git a/HackerRank-Python-main/String Split and Join.py b/HackerRank-Python-main/String Split and Join.py new file mode 100644 index 00000000..f7be01a3 --- /dev/null +++ b/HackerRank-Python-main/String Split and Join.py @@ -0,0 +1,7 @@ +def split_and_join(line): + return ("-".join(line.split())) + +if __name__ == '__main__': + line = input() + result = split_and_join(line) + print(result) diff --git a/HackerRank-Python-main/String Validators.py b/HackerRank-Python-main/String Validators.py new file mode 100644 index 00000000..df9ae529 --- /dev/null +++ b/HackerRank-Python-main/String Validators.py @@ -0,0 +1,4 @@ +if __name__ == '__main__': + s = input() + for test in ('isalnum', 'isalpha', 'isdigit', 'islower', 'isupper'): + print(any(eval("c." + test + "()") for c in s)) diff --git a/HackerRank-Python-main/Text Alignment.py b/HackerRank-Python-main/Text Alignment.py new file mode 100644 index 00000000..0265c300 --- /dev/null +++ b/HackerRank-Python-main/Text Alignment.py @@ -0,0 +1,24 @@ +#Replace all ______ with rjust, ljust or center. + +thickness = int(input()) #This must be an odd number +c = 'H' + +#Top Cone +for i in range(thickness): + print((c*i).rjust(thickness-1)+c+(c*i).ljust(thickness-1)) + +#Top Pillars +for i in range(thickness+1): + print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) + +#Middle Belt +for i in range((thickness+1)//2): + print((c*thickness*5).center(thickness*6)) + +#Bottom Pillars +for i in range(thickness+1): + print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) + +#Bottom Cone +for i in range(thickness): + print(((c*(thickness-i-1)).rjust(thickness)+c+(c*(thickness-i-1)).ljust(thickness)).rjust(thickness*6)) diff --git a/HackerRank-Python-main/Text Wrap.py b/HackerRank-Python-main/Text Wrap.py new file mode 100644 index 00000000..18e7bf70 --- /dev/null +++ b/HackerRank-Python-main/Text Wrap.py @@ -0,0 +1,10 @@ +import textwrap + +def wrap(string, max_width): + + return '\n'.join(textwrap.wrap(string,max_width)) + +if __name__ == '__main__': + string, max_width = input(), int(input()) + result = wrap(string, max_width) + print(result) diff --git a/HackerRank-Python-main/Triangle Quest.py b/HackerRank-Python-main/Triangle Quest.py new file mode 100644 index 00000000..12e66502 --- /dev/null +++ b/HackerRank-Python-main/Triangle Quest.py @@ -0,0 +1,2 @@ +for i in range(1,int(input())): + print((10**(i)//9)*i) diff --git a/HackerRank-Python-main/Tuples.py b/HackerRank-Python-main/Tuples.py new file mode 100644 index 00000000..7274dbe2 --- /dev/null +++ b/HackerRank-Python-main/Tuples.py @@ -0,0 +1,3 @@ +n=int(input()) +t=tuple(map(int,input().split())) +print(hash(t)) diff --git a/HackerRank-Python-main/What's Your Name_.py b/HackerRank-Python-main/What's Your Name_.py new file mode 100644 index 00000000..4d2200c2 --- /dev/null +++ b/HackerRank-Python-main/What's Your Name_.py @@ -0,0 +1,7 @@ +def print_full_name(a, b): + print(f"Hello {a} {b}! You just delved into python.") + +if __name__ == '__main__': + first_name = input() + last_name = input() + print_full_name(first_name, last_name) diff --git a/HackerRank-Python-main/Write a function.py b/HackerRank-Python-main/Write a function.py new file mode 100644 index 00000000..35cc5c66 --- /dev/null +++ b/HackerRank-Python-main/Write a function.py @@ -0,0 +1,11 @@ +def is_leap(year): + leap = False + + # Write your logic here + if (year%4==0 and year%100!=0 or year%400==0 ): + leap=True + + return leap + +year = int(input()) +print(is_leap(year)) diff --git a/HackerRank-Python-main/python.png b/HackerRank-Python-main/python.png new file mode 100644 index 00000000..fead838a Binary files /dev/null and b/HackerRank-Python-main/python.png differ diff --git a/HackerRank-Python-main/sWAP cASE.py b/HackerRank-Python-main/sWAP cASE.py new file mode 100644 index 00000000..c5820e24 --- /dev/null +++ b/HackerRank-Python-main/sWAP cASE.py @@ -0,0 +1,13 @@ +def swap_case(s): + a = "" + for let in s: + if (let.isupper() == True): + a+=(let.lower()) + else: + a+=(let.upper()) + return a + +if __name__ == '__main__': + s = input() + result = swap_case(s) + print(result) diff --git a/HackerRank-SQL-main/Employee Names.sql b/HackerRank-SQL-main/Employee Names.sql new file mode 100644 index 00000000..24bef8e4 --- /dev/null +++ b/HackerRank-SQL-main/Employee Names.sql @@ -0,0 +1,3 @@ +-- Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee table in alphabetical order. + +SELECT NAME FROM EMPLOYEE ORDER BY NAME ; diff --git a/HackerRank-SQL-main/Employee Salaries.sql b/HackerRank-SQL-main/Employee Salaries.sql new file mode 100644 index 00000000..3cfb892c --- /dev/null +++ b/HackerRank-SQL-main/Employee Salaries.sql @@ -0,0 +1,4 @@ +/* Write a query that prints a list of employee names (i.e.: the name attribute) for employees in Employee having a salary greater than $2000 +per month who have been employees for less than 10 months. Sort your result by ascending employee_id. */ + +SELECT NAME FROM EMPLOYEE WHERE SALARY > 2000 AND MONTHS <10 ORDER BY EMPLOYEE_ID ; diff --git a/HackerRank-SQL-main/Higher Than 75 Marks.sql b/HackerRank-SQL-main/Higher Than 75 Marks.sql new file mode 100644 index 00000000..6ff83013 --- /dev/null +++ b/HackerRank-SQL-main/Higher Than 75 Marks.sql @@ -0,0 +1,4 @@ +/* Query the Name of any student in STUDENTS who scored higher than 75 Marks. Order your output by the last three characters of each name. +If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID.*/ + +SELECT NAME FROM STUDENTS WHERE MARKS > 75 ORDER BY RIGHT(NAME, 3), ID; diff --git a/HackerRank-SQL-main/Japanese Cities' Attributes.sql b/HackerRank-SQL-main/Japanese Cities' Attributes.sql new file mode 100644 index 00000000..0cb23748 --- /dev/null +++ b/HackerRank-SQL-main/Japanese Cities' Attributes.sql @@ -0,0 +1,3 @@ +--Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN. + +SELECT * FROM CITY WHERE COUNTRYCODE = "JPN" ; diff --git a/HackerRank-SQL-main/Japanese Cities' Names.sql b/HackerRank-SQL-main/Japanese Cities' Names.sql new file mode 100644 index 00000000..b44ff1ab --- /dev/null +++ b/HackerRank-SQL-main/Japanese Cities' Names.sql @@ -0,0 +1,3 @@ +--Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN. + +SELECT NAME FROM CITY WHERE COUNTRYCODE = "JPN" ; diff --git a/HackerRank-SQL-main/README.md b/HackerRank-SQL-main/README.md new file mode 100644 index 00000000..47844368 --- /dev/null +++ b/HackerRank-SQL-main/README.md @@ -0,0 +1,42 @@ +# HackerRank-SQL +This repository contains **HackerRank SQL** Problem Solution. + +Follow me on **HackerRank** [Click here!](https://www.hackerrank.com/arwazkhan189) + +> SQL + +# List of Problems + +| S.No. | Problem | Subdomain | Problem Link| +|-------| ---------------------------- | ------------ | ----------- | +| 1 | Revising the Select Query I | Basic Select | [Link](https://www.hackerrank.com/challenges/revising-the-select-query/problem)| +| 2 | Revising the Select Query II | Basic Select | [Link](https://www.hackerrank.com/challenges/revising-the-select-query-2/problem)| +| 3 | Select All | Basic Select | [Link](https://www.hackerrank.com/challenges/select-all-sql/problem)| +| 4 | Select By ID | Basic Select | [Link](https://www.hackerrank.com/challenges/select-by-id/problem) | +| 5 | Japanese Cities' Attributes | Basic Select | [Link](https://www.hackerrank.com/challenges/japanese-cities-attributes/problem) | +| 6 | Japanese Cities' Names | Basic Select | [Link](https://www.hackerrank.com/challenges/japanese-cities-name/problem) | +| 7 | Weather Observation Station 1 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-1/problem) | +| 8 | Weather Observation Station 3 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-3/problem) | +| 9 | Weather Observation Station 4 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-4/problem) | +| 10 | Weather Observation Station 5 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-5/problem) | +| 11 | Weather Observation Station 6 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-6/problem) | +| 12 | Weather Observation Station 7 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-7/problem) | +| 13 | Weather Observation Station 8 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-8/problem) | +| 14 | Weather Observation Station 9 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-9/problem) | +| 15 | Weather Observation Station 10 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-10/problem) | +| 16 | Weather Observation Station 11 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-11/problem) | +| 17 | Weather Observation Station 12 | Basic Select | [Link](https://www.hackerrank.com/challenges/weather-observation-station-12/problem) | +| 18 | Higher Than 75 Marks | Basic Select | [Link](https://www.hackerrank.com/challenges/more-than-75-marks/problem) | +| 19 | Employee Names | Basic Select | [Link](https://www.hackerrank.com/challenges/name-of-employees/problem) | +| 20 | Employee Salaries | Basic Select | [Link](https://www.hackerrank.com/challenges/salary-of-employees/problem) | +| 21 | Type of Triangle | Advanced Select | [Link](https://www.hackerrank.com/challenges/what-type-of-triangle/problem) | + +--- + +# Useful material to solve queries + +### REGEXP TABLE +

+ regexp table + +

diff --git a/HackerRank-SQL-main/Revising the Select Query I.sql b/HackerRank-SQL-main/Revising the Select Query I.sql new file mode 100644 index 00000000..a67f11f3 --- /dev/null +++ b/HackerRank-SQL-main/Revising the Select Query I.sql @@ -0,0 +1,3 @@ +--Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA. + +SELECT * FROM CITY WHERE COUNTRYCODE = "USA" AND POPULATION > 100000 ; diff --git a/HackerRank-SQL-main/Revising the Select Query II.sql b/HackerRank-SQL-main/Revising the Select Query II.sql new file mode 100644 index 00000000..66416a51 --- /dev/null +++ b/HackerRank-SQL-main/Revising the Select Query II.sql @@ -0,0 +1,3 @@ +--Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA. + +SELECT NAME FROM CITY WHERE COUNTRYCODE="USA" AND POPULATION >120000 ; diff --git a/HackerRank-SQL-main/Select All.sql b/HackerRank-SQL-main/Select All.sql new file mode 100644 index 00000000..fdf2f0ed --- /dev/null +++ b/HackerRank-SQL-main/Select All.sql @@ -0,0 +1,3 @@ +--Query all columns (attributes) for every row in the CITY table. + +SELECT * FROM CITY ; diff --git a/HackerRank-SQL-main/Select By ID.sql b/HackerRank-SQL-main/Select By ID.sql new file mode 100644 index 00000000..5bbb6290 --- /dev/null +++ b/HackerRank-SQL-main/Select By ID.sql @@ -0,0 +1,3 @@ +-- Query all columns for a city in CITY with the ID 1661. + +SELECT * FROM CITY WHERE ID=1661 ; diff --git a/HackerRank-SQL-main/Tables/regexp_sql.png b/HackerRank-SQL-main/Tables/regexp_sql.png new file mode 100644 index 00000000..e8aef1f3 Binary files /dev/null and b/HackerRank-SQL-main/Tables/regexp_sql.png differ diff --git a/HackerRank-SQL-main/Type of Triangle.sql b/HackerRank-SQL-main/Type of Triangle.sql new file mode 100644 index 00000000..3711ba5a --- /dev/null +++ b/HackerRank-SQL-main/Type of Triangle.sql @@ -0,0 +1,19 @@ +/* +Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table: + +Equilateral: It's a triangle with 3 sides of equal length. +Isosceles: It's a triangle with 2 sides of equal length. +Scalene: It's a triangle with 3 sides of differing lengths. +Not A Triangle: The given values of A, B, and C don't form a triangle. +*/ + +SELECT CASE + WHEN A + B > C AND B + C > A AND A + C > B THEN + CASE + WHEN A = B AND B = C THEN 'Equilateral' + WHEN A = B OR B = C OR A = C THEN 'Isosceles' + ELSE 'Scalene' + END + ELSE 'Not A Triangle' + END +FROM TRIANGLES; diff --git a/HackerRank-SQL-main/Weather Observation Station 1.sql b/HackerRank-SQL-main/Weather Observation Station 1.sql new file mode 100644 index 00000000..9078ce0d --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 1.sql @@ -0,0 +1,3 @@ +--Query a list of CITY and STATE from the STATION table. + +SELECT CITY, STATE FROM STATION ; diff --git a/HackerRank-SQL-main/Weather Observation Station 10.sql b/HackerRank-SQL-main/Weather Observation Station 10.sql new file mode 100644 index 00000000..e4b44f11 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 10.sql @@ -0,0 +1,3 @@ +--Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '[^aeiou]$' ; diff --git a/HackerRank-SQL-main/Weather Observation Station 11.sql b/HackerRank-SQL-main/Weather Observation Station 11.sql new file mode 100644 index 00000000..3ee11582 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 11.sql @@ -0,0 +1,3 @@ +--Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '^[^aieou]|.*[^aeiou]$' ; diff --git a/HackerRank-SQL-main/Weather Observation Station 12.sql b/HackerRank-SQL-main/Weather Observation Station 12.sql new file mode 100644 index 00000000..6d65b6de --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 12.sql @@ -0,0 +1,3 @@ +--Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '^[^aeiou].*[^aeiou]$'; diff --git a/HackerRank-SQL-main/Weather Observation Station 3.sql b/HackerRank-SQL-main/Weather Observation Station 3.sql new file mode 100644 index 00000000..eca5a7a5 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 3.sql @@ -0,0 +1,3 @@ +--Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer. + +SELECT DISTINCT CITY FROM STATION WHERE ID%2=0 ; diff --git a/HackerRank-SQL-main/Weather Observation Station 4.sql b/HackerRank-SQL-main/Weather Observation Station 4.sql new file mode 100644 index 00000000..b25c2241 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 4.sql @@ -0,0 +1,3 @@ +--Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table. + +SELECT COUNT(CITY)- COUNT(DISTINCT CITY) FROM STATION ; diff --git a/HackerRank-SQL-main/Weather Observation Station 5.sql b/HackerRank-SQL-main/Weather Observation Station 5.sql new file mode 100644 index 00000000..36fdf0c2 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 5.sql @@ -0,0 +1,5 @@ +--Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically. + +(SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY ASC LIMIT 1) +UNION +(SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) ASC, CITY ASC LIMIT 1); diff --git a/HackerRank-SQL-main/Weather Observation Station 6.sql b/HackerRank-SQL-main/Weather Observation Station 6.sql new file mode 100644 index 00000000..8b24bc02 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 6.sql @@ -0,0 +1,3 @@ +--Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '^[aeiou]+'; diff --git a/HackerRank-SQL-main/Weather Observation Station 7.sql b/HackerRank-SQL-main/Weather Observation Station 7.sql new file mode 100644 index 00000000..11a7d64b --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 7.sql @@ -0,0 +1,3 @@ +-- Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '[aeiou]$' ; diff --git a/HackerRank-SQL-main/Weather Observation Station 8.sql b/HackerRank-SQL-main/Weather Observation Station 8.sql new file mode 100644 index 00000000..94dc5b25 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 8.sql @@ -0,0 +1,3 @@ +--Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '^[aeiou].+[aeiou]$' ; diff --git a/HackerRank-SQL-main/Weather Observation Station 9.sql b/HackerRank-SQL-main/Weather Observation Station 9.sql new file mode 100644 index 00000000..fa24ce54 --- /dev/null +++ b/HackerRank-SQL-main/Weather Observation Station 9.sql @@ -0,0 +1,3 @@ +--Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates. + +SELECT DISTINCT(CITY) FROM STATION WHERE CITY REGEXP '^[^AEIOU]' ;