text
stringlengths
2
104M
meta
dict
// Interview Preparation Kit > Miscellaneous > Maximum Xor // Find the maximum xor value in the array. // // https://www.hackerrank.com/challenges/maximum-xor/problem?h_l=playlist&slugs%5B%5D%5B%5D=interview&slugs%5B%5D%5B%5D=interview-preparation-kit&slugs%5B%5D%5B%5D=miscellaneous // challenge id: 71420 // #include <bits/stdc++.h> using namespace std; // ref: https://www.geeksforgeeks.org/maximum-possible-xor-every-element-array-another-array/ // Structure of Trie DS struct trie { int value = 0; trie *child[2] = { nullptr, nullptr }; }; // Computing maximum xor int max_xor(trie * root, int key) { trie * temp = root; // Checking for all bits in integer range for (int i = 31; i >= 0; i--) { // Current bit in the number int current_bit = (key & (1 << i)) ? 1 : 0; // Traversing Trie for opposite bit, if found if (temp->child[1 - current_bit] != nullptr) temp = temp->child[1 - current_bit]; // Traversing Trie for same bit else temp = temp->child[current_bit]; } // Returning xor value of maximum bit difference // value. Thus, we get maximum xor value return (key ^ temp->value); } // Inserting A[] in Trie void insert(trie * root, int key) { trie * temp = root; // Storing 32 bits as integer representation for (int i = 31; i >= 0; i--) { // Current bit in the number int current_bit = (key & (1 << i)) ? 1 : 0; // New node required if (temp->child[current_bit] == nullptr) temp->child[current_bit] = new trie; // Traversing in Trie temp = temp->child[current_bit]; } // Assigning value to the leaf node temp->value = key; } int main() { trie * root = new trie; int n, x; cin >> n; while (n--) { cin >> x; insert(root, x); } cin >> n; while (n--) { cin >> x; cout << max_xor(root, x) << endl; } return 0; } int trivial() { vector<int> A; size_t n, t; int x, y, m; cin >> n; A.resize(n); for (size_t i = 0; i < n; ++i) cin >> A[i]; cin >> t; while (t--) { cin >> x; m = 0; for (size_t i = 0; i < n; ++i) { y = x ^ A[i]; if (y > m) m = y; } cout << m << endl; } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Miscellaneous](https://www.hackerrank.com/interview/interview-preparation-kit/miscellaneous/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Time Complexity: Primality](https://www.hackerrank.com/challenges/ctci-big-o/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=miscellaneous)|Determine whether or not a number is prime in optimal time.|[C++](../../tutorials/cracking-the-coding-interview/ctci-big-o.cpp)|Medium [Flipping bits](https://www.hackerrank.com/challenges/flipping-bits/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=miscellaneous)|Flip bits in its binary representation.|[C++](../../algorithms/bit-manipulation/flipping-bits.cpp)|Easy [Friend Circle Queries](https://www.hackerrank.com/challenges/friend-circle-queries/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=miscellaneous)|Process the queries and after each query print the number of people largest friend circle.|[Python](friend-circle-queries.py)|Medium [Maximum Xor](https://www.hackerrank.com/challenges/maximum-xor/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=miscellaneous)|Find the maximum xor value in the array.|[C++](maximum-xor.cpp)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Stacks and Queues](https://www.hackerrank.com/interview/interview-preparation-kit/stacks-queues/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Balanced Brackets](https://www.hackerrank.com/challenges/balanced-brackets/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=stacks-queues)|Given a string containing three types of brackets, determine if it is balanced.|[Python](../../data-structures/stacks/balanced-brackets.py)|Medium [Queues: A Tale of Two Stacks](https://www.hackerrank.com/challenges/ctci-queue-using-two-stacks/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=stacks-queues)|Create a queue data structure using two stacks.|[C++](../../tutorials/cracking-the-coding-interview/ctci-queue-using-two-stacks.cpp)|Medium [Largest Rectangle ](https://www.hackerrank.com/challenges/largest-rectangle/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=stacks-queues)|Given n buildings, find the largest rectangular area possible by joining consecutive K buildings.|[Python](../../data-structures/stacks/largest-rectangle.py)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
#add_hackerrank_py(2d-array.py) #add_hackerrank_py(ctci-array-left-rotation.py) #add_hackerrank_py(crush.py) #add_hackerrank_py(new-year-chaos.py) add_hackerrank_py(minimum-swaps-2.py)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
# Interview Preparation Kit > Arrays > Minimum Swaps 2 # Return the minimum number of swaps to sort the given array. # # https://www.hackerrank.com/challenges/minimum-swaps-2/problem?h_l=playlist&slugs%5B%5D%5B%5D=interview&slugs%5B%5D%5B%5D=interview-preparation-kit&slugs%5B%5D%5B%5D=arrays # challenge id: 70816 # def minimumSwaps(q): q.insert(0, 0) length = len(q) # minimal swaps: ref = [0] * length for i, x in enumerate(q): ref[x] = i swaps = 0 for i in range(length): k = q[i] if k != i: q[i], q[ref[i]] = q[ref[i]], q[i] ref[i], ref[k] = ref[k], ref[i] swaps += 1 print(swaps) n = int(input()) arr = list(map(int, input().split())) minimumSwaps(arr)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Arrays](https://www.hackerrank.com/interview/interview-preparation-kit/arrays/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [2D Array - DS](https://www.hackerrank.com/challenges/2d-array/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=arrays)|How to access and use 2d-arrays.|[Python](../../data-structures/arrays/2d-array.py)|Easy [Array Manipulation](https://www.hackerrank.com/challenges/crush/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=arrays)|Perform m operations on an array and print the maximum of the values.|[Python](../../data-structures/arrays/crush.py)|Hard [Arrays: Left Rotation](https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=arrays)|Given an array and a number, d, perform d left rotations on the array.|[Python](../../tutorials/cracking-the-coding-interview/ctci-array-left-rotation.py)|Easy [Minimum Swaps 2](https://www.hackerrank.com/challenges/minimum-swaps-2/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=arrays)|Return the minimum number of swaps to sort the given array.|[Python](minimum-swaps-2.py)|Medium [New Year Chaos](https://www.hackerrank.com/challenges/new-year-chaos/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=arrays)|Determine how many bribes took place to get a queue into its current state.|[Python](../../algorithms/constructive-algorithms/new-year-chaos.py)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Graphs](https://www.hackerrank.com/interview/interview-preparation-kit/graphs/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [BFS: Shortest Reach in a Graph](https://www.hackerrank.com/challenges/ctci-bfs-shortest-reach/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=graphs)|Implement a Breadth First Search (BFS).|[C++](../../tutorials/cracking-the-coding-interview/ctci-bfs-shortest-reach.cpp)|Hard [DFS: Connected Cell in a Grid](https://www.hackerrank.com/challenges/ctci-connected-cell-in-a-grid/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=graphs)|Find the largest connected region in a 2D Matrix.|[C++](../../tutorials/cracking-the-coding-interview/ctci-connected-cell-in-a-grid.cpp)|Hard
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Dictionaries and Hashmaps](https://www.hackerrank.com/interview/interview-preparation-kit/dictionaries-hashmaps/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Hash Tables: Ransom Note](https://www.hackerrank.com/challenges/ctci-ransom-note/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=dictionaries-hashmaps)|Given two sets of dictionaries, tell if one of them is a subset of the other.|[C++](../../tutorials/cracking-the-coding-interview/ctci-ransom-note.cpp)|Easy [Sherlock and Anagrams](https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=dictionaries-hashmaps)|Find the number of unordered anagramic pairs of substrings of a string.|[Python](../../algorithms/strings/sherlock-and-anagrams.py)|Medium [Two Strings](https://www.hackerrank.com/challenges/two-strings/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=dictionaries-hashmaps)|Given two strings, you find a common substring of non-zero length.|[Python](../../algorithms/strings/two-strings.py)|Easy
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Greedy Algorithms](https://www.hackerrank.com/interview/interview-preparation-kit/greedy-algorithms/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Minimum Absolute Difference in an Array](https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=greedy-algorithms)|Given a list of integers, calculate their differences and find the difference with the smallest absolute value.|[Python](../../algorithms/greedy/minimum-absolute-difference-in-an-array.py)|Easy
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Trees](https://www.hackerrank.com/interview/interview-preparation-kit/trees/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Binary Search Tree : Lowest Common Ancestor](https://www.hackerrank.com/challenges/binary-search-tree-lowest-common-ancestor/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=trees)|Given two nodes of a binary search tree, find the lowest common ancestor of these two nodes.|[C++](../../data-structures/trees/binary-search-tree-lowest-common-ancestor.cpp)|Easy [Trees: Is This a Binary Search Tree?](https://www.hackerrank.com/challenges/ctci-is-binary-search-tree/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=trees)|Given the root of a binary tree, determine if it's a binary search tree.|[Python](../../tutorials/cracking-the-coding-interview/ctci-is-binary-search-tree.py)|Medium [Tree: Height of a Binary Tree](https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=trees)|Given a binary tree, print its height.|[C++](../../data-structures/trees/tree-height-of-a-binary-tree.cpp) [Python](../../data-structures/trees/tree-height-of-a-binary-tree.py)|Easy [Tree: Huffman Decoding ](https://www.hackerrank.com/challenges/tree-huffman-decoding/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=trees)|Given a Huffman tree and an encoded binary string, you have to print the original string.|[C++](../../data-structures/trees/tree-huffman-decoding.cpp)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Interview Preparation Kit](https://www.hackerrank.com/interview/interview-preparation-kit) #### [Linked Lists](https://www.hackerrank.com/interview/interview-preparation-kit/linked-lists/challenges) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Linked Lists: Detect a Cycle](https://www.hackerrank.com/challenges/ctci-linked-list-cycle/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=linked-lists)|Given a pointer to the head of a linked list, determine whether the list has a cycle.|[C++](../../tutorials/cracking-the-coding-interview/ctci-linked-list-cycle.cpp)|Easy [Find Merge Point of Two Lists](https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=linked-lists)|Given two linked lists, find the node where they merge into one.|[C++](../../data-structures/linked-lists/find-the-merge-point-of-two-joined-linked-lists.cpp)|Easy [Insert a node at a specific position in a linked list](https://www.hackerrank.com/challenges/insert-a-node-at-a-specific-position-in-a-linked-list/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=linked-lists)|Insert a node at a specific position in a linked list.|[C++](../../data-structures/linked-lists/insert-a-node-at-a-specific-position-in-a-linked-list.cpp)|Easy [Inserting a Node Into a Sorted Doubly Linked List](https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-linked-list/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=linked-lists)|Create a node with a given value and insert it into a sorted doubly-linked list|[C++](../../data-structures/linked-lists/insert-a-node-into-a-sorted-doubly-linked-list.cpp)|Easy [Reverse a doubly linked list](https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list/problem?h_l=playlist&slugs%5B%5D=interview&slugs%5B%5D=interview-preparation-kit&slugs%5B%5D=linked-lists)|Given the head node of a doubly linked list, reverse it.|[Python](../../data-structures/linked-lists/reverse-a-doubly-linked-list.py)|Easy
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_subdirectory(java-introduction)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Java](https://www.hackerrank.com/domains/java) A strictly object-oriented language designed to write industry-standard code. #### [Introduction](https://www.hackerrank.com/domains/java/java-introduction) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Welcome to Java!](https://www.hackerrank.com/challenges/welcome-to-java)|Practice printing to stdout.|[Java](java-introduction/welcome-to-java.java)|Easy [ Java Stdin and Stdout I](https://www.hackerrank.com/challenges/java-stdin-and-stdout-1)|Get started with standard input and output.|[Java](java-introduction/java-stdin-and-stdout-1.java)|Easy [Java If-Else](https://www.hackerrank.com/challenges/java-if-else)|Practice using if-else conditional statements!|[Java](java-introduction/java-if-else.java)|Easy [Java Stdin and Stdout II](https://www.hackerrank.com/challenges/java-stdin-stdout)|Familiarize yourself with Standard Input/Output.|[Java](java-introduction/java-stdin-stdout.java)|Easy [Java Output Formatting](https://www.hackerrank.com/challenges/java-output-formatting)|Format a string using printf.|[Java](java-introduction/java-output-formatting.java)|Easy [Java Loops I](https://www.hackerrank.com/challenges/java-loops-i)|Let's talk about loops.|[Java](java-introduction/java-loops-i.java)|Easy [Java Loops II](https://www.hackerrank.com/challenges/java-loops)|Use loops to find sum of a series.|[Java](java-introduction/java-loops.java)|Easy [Java Datatypes](https://www.hackerrank.com/challenges/java-datatypes)|Learn about different Java Datatypes.|[Java](java-introduction/java-datatypes.java)|Easy [Java End-of-file](https://www.hackerrank.com/challenges/java-end-of-file)|Learn how to read from standard input until EOF.|[Java](java-introduction/java-end-of-file.java)|Easy [Java Static Initializer Block](https://www.hackerrank.com/challenges/java-static-initializer-block)|Initialize some variables using Static initialization blocks!|[Java](java-introduction/java-static-initializer-block.java)|Easy [Java Int to String](https://www.hackerrank.com/challenges/java-int-to-string)|Convert an integer to a string.|[Java](java-introduction/java-int-to-string.java)|Easy [Java Date and Time](https://www.hackerrank.com/challenges/java-date-and-time)|Print the day of a given date.|[Java](java-introduction/java-date-and-time.java)|Easy [Java Currency Formatter](https://www.hackerrank.com/challenges/java-currency-formatter)|Format Currency in Java|[Java](java-introduction/java-currency-formatter.java)|Easy
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Output Formatting // Format a string using printf. // // https://www.hackerrank.com/challenges/java-output-formatting/problem // challenge id: 9472 // import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("================================"); for(int i=0;i<3;i++) { String s1=sc.next(); int x=sc.nextInt(); //Complete this line System.out.printf("%-15s%03d\n", s1, x); } System.out.println("================================"); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java End-of-file // Learn how to read from standard input until EOF. // // https://www.hackerrank.com/challenges/java-end-of-file/problem // challenge id: 8279 // import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { /* * Enter your code here. Read input from STDIN. Print output to STDOUT. Your * class should be named Solution. */ Scanner sc = new Scanner(System.in); int line = 0; while (sc.hasNextLine()) { System.out.printf("%d %s\n", ++line, sc.nextLine()); } sc.close(); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Date and Time // Print the day of a given date. // // https://www.hackerrank.com/challenges/java-date-and-time/problem // challenge id: 23448 // import java.util.Scanner; // (skeliton_head) ---------------------------------------------------------------------- import java.util.*; public class Solution { private static String getDay(String day, String month, String year) { Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); String s = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US); return s.toUpperCase(); } // (skeliton_tail) ---------------------------------------------------------------------- public static void main(String[] args) { Scanner in = new Scanner(System.in); String month = in.next(); String day = in.next(); String year = in.next(); System.out.println(getDay(day, month, year)); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Stdin and Stdout I // Get started with standard input and output. // // https://www.hackerrank.com/challenges/java-stdin-and-stdout-1/problem // challenge id: 9762 // import java.util.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); System.out.println(a); System.out.println(b); System.out.println(c); scan.close(); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Currency Formatter // Format Currency in Java // // https://www.hackerrank.com/challenges/java-currency-formatter/problem // challenge id: 23733 // import java.util.*; import java.text.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close(); // Write your code here. String us = NumberFormat.getCurrencyInstance(Locale.US).format(payment); String india = NumberFormat.getCurrencyInstance(new Locale("en", "IN")).format(payment); String china = NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment); String france = NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment); System.out.println("US: " + us); System.out.println("India: " + india); System.out.println("China: " + china); System.out.println("France: " + france); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Static Initializer Block // Initialize some variables using Static initialization blocks! // // https://www.hackerrank.com/challenges/java-static-initializer-block/problem // challenge id: 13800 // import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { // (skeliton_head) ---------------------------------------------------------------------- private static boolean flag; private static int B, H; static { Scanner scanner = new Scanner(System.in); B = scanner.nextInt(); H = scanner.nextInt(); scanner.close(); flag = (B > 0 && H > 0); try { if (! flag) throw new Exception("Breadth and height must be positive"); } catch (Exception e) { System.out.println(e); } } // (skeliton_tail) ---------------------------------------------------------------------- public static void main(String[] args){ if(flag){ int area=B*H; System.out.print(area); } }//end of main }//end of class
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_hackerrank_java(welcome-to-java.java) add_hackerrank_java(java-stdin-and-stdout-1.java) add_hackerrank_java(java-if-else.java) add_hackerrank_java(java-stdin-stdout.java) add_hackerrank_java(java-output-formatting.java) add_hackerrank_java(java-loops-i.java) add_hackerrank_java(java-loops.java) add_hackerrank_java(java-datatypes.java) add_hackerrank_java(java-end-of-file.java) add_hackerrank_java(java-static-initializer-block.java) add_hackerrank_java(java-int-to-string.java) add_hackerrank_java(java-date-and-time.java) add_hackerrank_java(java-currency-formatter.java)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Stdin and Stdout II // Familiarize yourself with Standard Input/Output. // // https://www.hackerrank.com/challenges/java-stdin-stdout/problem // challenge id: 9458 // import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int i = scan.nextInt(); // Write your code here. double d = scan.nextDouble(); scan.nextLine(); // lit le retour à la ligne après le double String s = scan.nextLine(); System.out.println("String: " + s); System.out.println("Double: " + d); System.out.println("Int: " + i); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Loops II // Use loops to find sum of a series. // // https://www.hackerrank.com/challenges/java-loops/problem // challenge id: 8018 // import java.util.*; import java.io.*; class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int t=in.nextInt(); for(int i=0;i<t;i++){ int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); int x = a; for (int j = 0; j < n; ++j) { x += Math.pow(2, j) * b; System.out.printf("%d ", x); } System.out.println(); } in.close(); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Loops I // Let's talk about loops. // // https://www.hackerrank.com/challenges/java-loops-i/problem // challenge id: 23447 // import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int N = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); scanner.close(); for (int i = 1; i <= 10; ++i) System.out.printf("%d x %d = %d\n", N, i, N * i); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Int to String // Convert an integer to a string. // // https://www.hackerrank.com/challenges/java-int-to-string/problem // challenge id: 14556 // import java.util.*; import java.security.*; public class Solution { public static void main(String[] args) { DoNotTerminate.forbidExit(); try { Scanner in = new Scanner(System.in); int n = in .nextInt(); in.close(); //String s=???; Complete this line below // (skeliton_head) ---------------------------------------------------------------------- //Write your code here String s = Integer.toString(n); // (skeliton_tail) ---------------------------------------------------------------------- if (n == Integer.parseInt(s)) { System.out.println("Good job"); } else { System.out.println("Wrong answer."); } } catch (DoNotTerminate.ExitTrappedException e) { System.out.println("Unsuccessful Termination!!"); } } } //The following class will prevent you from terminating the code using exit(0)! class DoNotTerminate { public static class ExitTrappedException extends SecurityException { private static final long serialVersionUID = 1; } public static void forbidExit() { final SecurityManager securityManager = new SecurityManager() { @Override public void checkPermission(Permission permission) { if (permission.getName().contains("exitVM")) { throw new ExitTrappedException(); } } }; System.setSecurityManager(securityManager); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java If-Else // Practice using if-else conditional statements! // // https://www.hackerrank.com/challenges/java-if-else/problem // challenge id: 13689 // import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int N = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); if (N % 2 == 1 || N >= 6 && N <= 20) System.out.println("Weird"); else if (N >= 2 && N <= 5 || N > 20) System.out.println("Not Weird"); scanner.close(); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Java Datatypes // Learn about different Java Datatypes. // // https://www.hackerrank.com/challenges/java-datatypes/problem // challenge id: 8098 // import java.util.*; import java.io.*; class Solution { public static void main(String[] argh) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { try { long x = sc.nextLong(); System.out.println(x + " can be fitted in:"); if (x >= -128 && x <= 127) System.out.println("* byte"); // Complete the code if (x >= Short.MIN_VALUE && x <= Short.MAX_VALUE) System.out.println("* short"); if (x >= Integer.MIN_VALUE && x <= Integer.MAX_VALUE) System.out.println("* int"); if (x >= Long.MIN_VALUE && x <= Long.MAX_VALUE) System.out.println("* long"); } catch (Exception e) { System.out.println(sc.next() + " can't be fitted anywhere."); } } } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [Java](https://www.hackerrank.com/domains/java) A strictly object-oriented language designed to write industry-standard code. #### [Introduction](https://www.hackerrank.com/domains/java/java-introduction) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Welcome to Java!](https://www.hackerrank.com/challenges/welcome-to-java)|Practice printing to stdout.|[Java](welcome-to-java.java)|Easy [ Java Stdin and Stdout I](https://www.hackerrank.com/challenges/java-stdin-and-stdout-1)|Get started with standard input and output.|[Java](java-stdin-and-stdout-1.java)|Easy [Java If-Else](https://www.hackerrank.com/challenges/java-if-else)|Practice using if-else conditional statements!|[Java](java-if-else.java)|Easy [Java Stdin and Stdout II](https://www.hackerrank.com/challenges/java-stdin-stdout)|Familiarize yourself with Standard Input/Output.|[Java](java-stdin-stdout.java)|Easy [Java Output Formatting](https://www.hackerrank.com/challenges/java-output-formatting)|Format a string using printf.|[Java](java-output-formatting.java)|Easy [Java Loops I](https://www.hackerrank.com/challenges/java-loops-i)|Let's talk about loops.|[Java](java-loops-i.java)|Easy [Java Loops II](https://www.hackerrank.com/challenges/java-loops)|Use loops to find sum of a series.|[Java](java-loops.java)|Easy [Java Datatypes](https://www.hackerrank.com/challenges/java-datatypes)|Learn about different Java Datatypes.|[Java](java-datatypes.java)|Easy [Java End-of-file](https://www.hackerrank.com/challenges/java-end-of-file)|Learn how to read from standard input until EOF.|[Java](java-end-of-file.java)|Easy [Java Static Initializer Block](https://www.hackerrank.com/challenges/java-static-initializer-block)|Initialize some variables using Static initialization blocks!|[Java](java-static-initializer-block.java)|Easy [Java Int to String](https://www.hackerrank.com/challenges/java-int-to-string)|Convert an integer to a string.|[Java](java-int-to-string.java)|Easy [Java Date and Time](https://www.hackerrank.com/challenges/java-date-and-time)|Print the day of a given date.|[Java](java-date-and-time.java)|Easy [Java Currency Formatter](https://www.hackerrank.com/challenges/java-currency-formatter)|Format Currency in Java|[Java](java-currency-formatter.java)|Easy
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Java > Introduction > Welcome to Java! // Practice printing to stdout. // // https://www.hackerrank.com/challenges/welcome-to-java/problem // challenge id: 7875 // public class Solution { public static void main(String[] args) { System.out.println("Hello, World."); System.out.println("Hello, Java."); } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [SQL](https://www.hackerrank.com/domains/sql) A special-purpose language designed for managing data held in a relational database. #### [Basic Select](https://www.hackerrank.com/domains/sql/select) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Revising the Select Query I](https://www.hackerrank.com/challenges/revising-the-select-query)|Query the data for all American cities with populations larger than 100,000.|[SQL](select/revising-the-select-query.sql)|Easy [Revising the Select Query II](https://www.hackerrank.com/challenges/revising-the-select-query-2)|Query the city names for all American cities with populations larger than 120,000.|[SQL](select/revising-the-select-query-2.sql)|Easy [Select All](https://www.hackerrank.com/challenges/select-all-sql)|Query all columns for every row in a table.|[SQL](select/select-all-sql.sql)|Easy [Select By ID](https://www.hackerrank.com/challenges/select-by-id)|Query the details of the city with ID 1661.|[SQL](select/select-by-id.sql)|Easy [Japanese Cities' Attributes](https://www.hackerrank.com/challenges/japanese-cities-attributes)|Query the attributes of all the cities in Japan.|[SQL](select/japanese-cities-attributes.sql)|Easy [Japanese Cities' Names](https://www.hackerrank.com/challenges/japanese-cities-name)|In this challenge, you will query a list of all the Japanese cities' names.|[SQL](select/japanese-cities-name.sql)|Easy [Weather Observation Station 1](https://www.hackerrank.com/challenges/weather-observation-station-1)|Write a query to print the CITY and STATE for each attribute in the STATION table.|[SQL](select/weather-observation-station-1.sql)|Easy [Weather Observation Station 3](https://www.hackerrank.com/challenges/weather-observation-station-3)|Query a list of unique CITY names with even ID numbers.|[SQL](select/weather-observation-station-3.sql)|Easy [Weather Observation Station 4](https://www.hackerrank.com/challenges/weather-observation-station-4)|Find the number of duplicate CITY names in STATION.|[SQL](select/weather-observation-station-4.sql)|Easy [Weather Observation Station 5](https://www.hackerrank.com/challenges/weather-observation-station-5)|Write a query to print the shortest and longest length city name along with the length of the city names.|[SQL](select/weather-observation-station-5.sql)|Easy [Weather Observation Station 6](https://www.hackerrank.com/challenges/weather-observation-station-6)|Query a list of CITY names beginning with vowels (a, e, i, o, u).|[SQL](select/weather-observation-station-6.sql)|Easy [Weather Observation Station 7](https://www.hackerrank.com/challenges/weather-observation-station-7)|Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION.|[SQL](select/weather-observation-station-7.sql)|Easy [Weather Observation Station 8](https://www.hackerrank.com/challenges/weather-observation-station-8)|Query CITY names that start AND end with vowels.|[SQL](select/weather-observation-station-8.sql)|Easy [Weather Observation Station 9](https://www.hackerrank.com/challenges/weather-observation-station-9)|Query an alphabetically ordered list of CITY names not starting with vowels.|[SQL](select/weather-observation-station-9.sql)|Easy [Weather Observation Station 10](https://www.hackerrank.com/challenges/weather-observation-station-10)|Query a list of CITY names not ending in vowels.|[SQL](select/weather-observation-station-10.sql)|Easy [Weather Observation Station 11](https://www.hackerrank.com/challenges/weather-observation-station-11)|Query a list of CITY names not starting or ending with vowels.|[SQL](select/weather-observation-station-11.sql)|Easy [Weather Observation Station 12](https://www.hackerrank.com/challenges/weather-observation-station-12)|Query an alphabetically ordered list of CITY names not starting and ending with vowels.|[SQL](select/weather-observation-station-12.sql)|Easy [Higher Than 75 Marks](https://www.hackerrank.com/challenges/more-than-75-marks)|Query the names of students scoring higher than 75 Marks. Sort the output by the LAST three characters of each name.|[SQL](select/more-than-75-marks.sql)|Easy [Employee Names](https://www.hackerrank.com/challenges/name-of-employees)|Print employee names.|[SQL](select/name-of-employees.sql)|Easy [Employee Salaries](https://www.hackerrank.com/challenges/salary-of-employees)|Print the names of employees who earn more than $2000 per month and have worked at the company for less than 10 months.|[SQL](select/salary-of-employees.sql)|Easy #### [Advanced Select](https://www.hackerrank.com/domains/sql/advanced-select) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Type of Triangle](https://www.hackerrank.com/challenges/what-type-of-triangle)|Query a triangle's type based on its side lengths.|[SQL](advanced-select/what-type-of-triangle.sql)|Easy [The PADS](https://www.hackerrank.com/challenges/the-pads)|Query the name and abbreviated occupation for each person in OCCUPATIONS.|[SQL](advanced-select/the-pads.sql)|Medium [Occupations](https://www.hackerrank.com/challenges/occupations)|Pivot the Occupation column so the Name of each person in OCCUPATIONS is displayed underneath their respective Occupation.|[SQL](advanced-select/occupations.sql)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Advanced Select > Occupations -- Pivot the Occupation column so the Name of each person in OCCUPATIONS is displayed underneath their respective Occupation. -- -- https://www.hackerrank.com/challenges/occupations/problem -- https://www.hackerrank.com/contests/simply-sql/challenges/occupations -- challenge id: 12890 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- -- solution Oracle SELECT Doctor, Professor, Singer, Actor FROM (SELECT ROW_NUMBER() OVER (PARTITION BY occupation ORDER BY name) as rn, name, occupation FROM occupations) PIVOT (MAX(name) FOR OCCUPATION IN ('Doctor' as Doctor, 'Professor' as Professor, 'Singer' as Singer, 'Actor' as Actor)) ORDER BY rn; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Advanced Select > The PADS -- Query the name and abbreviated occupation for each person in OCCUPATIONS. -- -- https://www.hackerrank.com/challenges/the-pads/problem -- https://www.hackerrank.com/contests/simply-sql/challenges/the-pads -- challenge id: 12889 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- select concat(name, concat('(', concat(substr(occupation, 1, 1), ')'))) from occupations order by name; select concat('There are a total of ', concat(count(name), concat(' ', concat(lower(occupation), 's.')))) from occupations group by occupation order by count(name), occupation; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Advanced Select > Type of Triangle -- Query a triangle's type based on its side lengths. -- -- https://www.hackerrank.com/challenges/what-type-of-triangle/problem -- https://www.hackerrank.com/contests/simply-sql/challenges/what-type-of-triangle -- challenge id: 12887 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select case when a+b<=c or b+c<=a or c+a<=b then 'Not A Triangle' when a=b and b=c then 'Equilateral' when a=b or b=c or c=a then 'Isosceles' else 'Scalene' end from triangles; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [SQL](https://www.hackerrank.com/domains/sql) A special-purpose language designed for managing data held in a relational database. #### [Advanced Select](https://www.hackerrank.com/domains/sql/advanced-select) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Type of Triangle](https://www.hackerrank.com/challenges/what-type-of-triangle)|Query a triangle's type based on its side lengths.|[SQL](what-type-of-triangle.sql)|Easy [The PADS](https://www.hackerrank.com/challenges/the-pads)|Query the name and abbreviated occupation for each person in OCCUPATIONS.|[SQL](the-pads.sql)|Medium [Occupations](https://www.hackerrank.com/challenges/occupations)|Pivot the Occupation column so the Name of each person in OCCUPATIONS is displayed underneath their respective Occupation.|[SQL](occupations.sql)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Employee Salaries -- Print the names of employees who earn more than $2000 per month and have worked at the company for less than 10 months. -- -- https://www.hackerrank.com/challenges/salary-of-employees/problem -- https://www.hackerrank.com/contests/simply-sql-the-sequel/challenges/salary-of-employees -- challenge id: 19630 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select name from employee where salary > 2000 and months < 10; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 1 -- Write a query to print the CITY and STATE for each attribute in the STATION table. -- -- https://www.hackerrank.com/challenges/weather-observation-station-1/problem -- select city,state from station;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 6 -- Query a list of CITY names beginning with vowels (a, e, i, o, u). -- -- https://www.hackerrank.com/challenges/weather-observation-station-6/problem -- challenge id: 9341 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select city from station where instr('aeiou', lower(substr(city,1,1))) > 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 10 -- Query a list of CITY names not ending in vowels. -- -- https://www.hackerrank.com/challenges/weather-observation-station-10/problem -- challenge id: 9345 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select distinct city from station where instr('aeiou', lower(substr(city, length(city), 1))) = 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 12 -- Query an alphabetically ordered list of CITY names not starting and ending with vowels. -- -- https://www.hackerrank.com/challenges/weather-observation-station-12/problem -- challenge id: 9347 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select distinct city from station where instr('aeiou', lower(substr(city, length(city), 1))) = 0 and instr('aeiou', lower(substr(city, 1, 1))) = 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 11 -- Query a list of CITY names not starting or ending with vowels. -- -- https://www.hackerrank.com/challenges/weather-observation-station-11/problem -- challenge id: 9346 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select distinct city from station where instr('aeiou', lower(substr(city, length(city), 1))) = 0 or instr('aeiou', lower(substr(city, 1, 1))) = 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Select By ID -- Query the details of the city with ID 1661. -- -- https://www.hackerrank.com/challenges/select-by-id/problem -- select * from city where id=1661;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Japanese Cities' Names -- In this challenge, you will query a list of all the Japanese cities' names. -- -- https://www.hackerrank.com/challenges/japanese-cities-name/problem -- select name from city where countrycode='JPN';
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Japanese Cities' Attributes -- Query the attributes of all the cities in Japan. -- -- https://www.hackerrank.com/challenges/japanese-cities-attributes/problem -- select * from city where countrycode='JPN';
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 3 -- Query a list of unique CITY names with even ID numbers. -- -- https://www.hackerrank.com/challenges/weather-observation-station-3/problem -- select distinct city from station where mod(id, 2) = 0;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Employee Names -- Print employee names. -- -- https://www.hackerrank.com/challenges/name-of-employees/problem -- https://www.hackerrank.com/contests/simply-sql-the-sequel/challenges/name-of-employees -- challenge id: 19629 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select name from employee order by name; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Higher Than 75 Marks -- Query the names of students scoring higher than 75 Marks. Sort the output by the LAST three characters of each name. -- -- https://www.hackerrank.com/challenges/more-than-75-marks/problem -- https://www.hackerrank.com/contests/simply-sql/challenges/more-than-75-marks -- challenge id: 12965 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select name from students where marks>75 order by lower(substr(name, length(name)-2, 3)), id; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Revising the Select Query I -- Query the data for all American cities with populations larger than 100,000. -- -- https://www.hackerrank.com/challenges/revising-the-select-query/problem -- select * from CITY where POPULATION>100000 and COUNTRYCODE='USA';
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 5 -- Write a query to print the shortest and longest length city name along with the length of the city names. -- -- https://www.hackerrank.com/challenges/weather-observation-station-5/problem -- challenge id: 9340 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ -- Oracle: select city,length(city) from (select city from station order by length(city) asc,city) where rownum=1; select city,length(city) from (select city from station order by length(city) desc,city) where rownum=1; -- MySQL: -- select city,length(city) from station order by length(city) asc,city limit 1; -- select city,length(city) from station order by length(city) desc,city limit 1; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 9 -- Query an alphabetically ordered list of CITY names not starting with vowels. -- -- https://www.hackerrank.com/challenges/weather-observation-station-9/problem -- challenge id: 9344 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select distinct city from station where instr('aeiou', lower(substr(city, 1, 1))) = 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 8 -- Query CITY names that start AND end with vowels. -- -- https://www.hackerrank.com/challenges/weather-observation-station-8/problem -- challenge id: 9343 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select distinct city from station where instr('aeiou', lower(substr(city, length(city), 1))) > 0 and instr('aeiou', lower(substr(city, 1, 1))) > 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 4 -- Find the number of duplicate CITY names in STATION. -- -- https://www.hackerrank.com/challenges/weather-observation-station-4/problem -- select count(*)-count(distinct city) from station;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Revising the Select Query II -- Query the city names for all American cities with populations larger than 120,000. -- -- https://www.hackerrank.com/challenges/revising-the-select-query-2/problem -- select name from city where countrycode='USA' and population>=120000;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Weather Observation Station 7 -- Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. -- -- https://www.hackerrank.com/challenges/weather-observation-station-7/problem -- challenge id: 9342 -- SET NULL "NULL"; SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; SET PAGES 0; SET DEFINE OFF; -- (skeliton_head) ---------------------------------------------------------------------- /* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select distinct city from station where instr('aeiou', lower(substr(city, length(city), 1))) > 0; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [SQL](https://www.hackerrank.com/domains/sql) A special-purpose language designed for managing data held in a relational database. #### [Basic Select](https://www.hackerrank.com/domains/sql/select) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Revising the Select Query I](https://www.hackerrank.com/challenges/revising-the-select-query)|Query the data for all American cities with populations larger than 100,000.|[SQL](revising-the-select-query.sql)|Easy [Revising the Select Query II](https://www.hackerrank.com/challenges/revising-the-select-query-2)|Query the city names for all American cities with populations larger than 120,000.|[SQL](revising-the-select-query-2.sql)|Easy [Select All](https://www.hackerrank.com/challenges/select-all-sql)|Query all columns for every row in a table.|[SQL](select-all-sql.sql)|Easy [Select By ID](https://www.hackerrank.com/challenges/select-by-id)|Query the details of the city with ID 1661.|[SQL](select-by-id.sql)|Easy [Japanese Cities' Attributes](https://www.hackerrank.com/challenges/japanese-cities-attributes)|Query the attributes of all the cities in Japan.|[SQL](japanese-cities-attributes.sql)|Easy [Japanese Cities' Names](https://www.hackerrank.com/challenges/japanese-cities-name)|In this challenge, you will query a list of all the Japanese cities' names.|[SQL](japanese-cities-name.sql)|Easy [Weather Observation Station 1](https://www.hackerrank.com/challenges/weather-observation-station-1)|Write a query to print the CITY and STATE for each attribute in the STATION table.|[SQL](weather-observation-station-1.sql)|Easy [Weather Observation Station 3](https://www.hackerrank.com/challenges/weather-observation-station-3)|Query a list of unique CITY names with even ID numbers.|[SQL](weather-observation-station-3.sql)|Easy [Weather Observation Station 4](https://www.hackerrank.com/challenges/weather-observation-station-4)|Find the number of duplicate CITY names in STATION.|[SQL](weather-observation-station-4.sql)|Easy [Weather Observation Station 5](https://www.hackerrank.com/challenges/weather-observation-station-5)|Write a query to print the shortest and longest length city name along with the length of the city names.|[SQL](weather-observation-station-5.sql)|Easy [Weather Observation Station 6](https://www.hackerrank.com/challenges/weather-observation-station-6)|Query a list of CITY names beginning with vowels (a, e, i, o, u).|[SQL](weather-observation-station-6.sql)|Easy [Weather Observation Station 7](https://www.hackerrank.com/challenges/weather-observation-station-7)|Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION.|[SQL](weather-observation-station-7.sql)|Easy [Weather Observation Station 8](https://www.hackerrank.com/challenges/weather-observation-station-8)|Query CITY names that start AND end with vowels.|[SQL](weather-observation-station-8.sql)|Easy [Weather Observation Station 9](https://www.hackerrank.com/challenges/weather-observation-station-9)|Query an alphabetically ordered list of CITY names not starting with vowels.|[SQL](weather-observation-station-9.sql)|Easy [Weather Observation Station 10](https://www.hackerrank.com/challenges/weather-observation-station-10)|Query a list of CITY names not ending in vowels.|[SQL](weather-observation-station-10.sql)|Easy [Weather Observation Station 11](https://www.hackerrank.com/challenges/weather-observation-station-11)|Query a list of CITY names not starting or ending with vowels.|[SQL](weather-observation-station-11.sql)|Easy [Weather Observation Station 12](https://www.hackerrank.com/challenges/weather-observation-station-12)|Query an alphabetically ordered list of CITY names not starting and ending with vowels.|[SQL](weather-observation-station-12.sql)|Easy [Higher Than 75 Marks](https://www.hackerrank.com/challenges/more-than-75-marks)|Query the names of students scoring higher than 75 Marks. Sort the output by the LAST three characters of each name.|[SQL](more-than-75-marks.sql)|Easy [Employee Names](https://www.hackerrank.com/challenges/name-of-employees)|Print employee names.|[SQL](name-of-employees.sql)|Easy [Employee Salaries](https://www.hackerrank.com/challenges/salary-of-employees)|Print the names of employees who earn more than $2000 per month and have worked at the company for less than 10 months.|[SQL](salary-of-employees.sql)|Easy
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
-- SQL > Basic Select > Select All -- Query all columns for every row in a table. -- -- https://www.hackerrank.com/challenges/select-all-sql/problem -- challenge id: 8137 -- SET FEEDBACK OFF; SET ECHO OFF; SET HEADING OFF; SET WRAP OFF; SET LINESIZE 10000; SET TAB OFF; -- (skeliton_head) ---------------------------------------------------------------------- select * from city; -- (skeliton_tail) ---------------------------------------------------------------------- exit;
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_subdirectory(classes) add_subdirectory(cpp-introduction) add_subdirectory(cpp-strings) add_subdirectory(inheritance) add_subdirectory(other-concepts) add_subdirectory(stl) add_subdirectory(cpp-debugging)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [C++](https://www.hackerrank.com/domains/cpp) A general-purpose programming language with imperative, object-oriented and generic programming features. #### [Introduction](https://www.hackerrank.com/domains/cpp/cpp-introduction) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Say "Hello, World!" With C++](https://www.hackerrank.com/challenges/cpp-hello-world)|Practice printing to stdout.|[C++](cpp-introduction/cpp-hello-world.cpp)|Easy [Input and Output](https://www.hackerrank.com/challenges/cpp-input-and-output)|Learn to take in the input and print the output. Take three number as input and print their sum as output.|[C++](cpp-introduction/cpp-input-and-output.cpp)|Easy [Basic Data Types](https://www.hackerrank.com/challenges/c-tutorial-basic-data-types)|Learn about the basic data types in C++. Take the given input and print them.|[C++](cpp-introduction/c-tutorial-basic-data-types.cpp)|Easy [Conditional Statements](https://www.hackerrank.com/challenges/c-tutorial-conditional-if-else)|Practice using chained conditional statements.|[C++](cpp-introduction/c-tutorial-conditional-if-else.cpp)|Easy [For Loop](https://www.hackerrank.com/challenges/c-tutorial-for-loop)|Learn how to use for loop and print the output as per the given conditions|[C++](cpp-introduction/c-tutorial-for-loop.cpp)|Easy [Functions](https://www.hackerrank.com/challenges/c-tutorial-functions)|Learn how to write functions in C++. Create a function to find the maximum of the four numbers.|[C++](cpp-introduction/c-tutorial-functions.cpp)|Easy [Pointer](https://www.hackerrank.com/challenges/c-tutorial-pointer)|Learn how to declare pointers and use them.|[C++](cpp-introduction/c-tutorial-pointer.cpp)|Easy [Arrays Introduction](https://www.hackerrank.com/challenges/arrays-introduction)|How to access and use arrays. Print the array in the reverse order.|[C++](cpp-introduction/arrays-introduction.cpp)|Easy [Variable Sized Arrays](https://www.hackerrank.com/challenges/variable-sized-arrays)|Find the element described in the query for integer sequences.|[C++](cpp-introduction/variable-sized-arrays.cpp)|Easy #### [Strings](https://www.hackerrank.com/domains/cpp/cpp-strings) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Strings](https://www.hackerrank.com/challenges/c-tutorial-strings)|Learn how to input and output strings.|[C++](cpp-strings/c-tutorial-strings.cpp)|Easy [StringStream](https://www.hackerrank.com/challenges/c-tutorial-stringstream)|Learn how to use stringstreams.|[C++](cpp-strings/c-tutorial-stringstream.cpp)|Easy [Attribute Parser](https://www.hackerrank.com/challenges/attribute-parser)|Parse the values within various tags.|[C++](cpp-strings/attribute-parser.cpp)|Medium #### [Classes](https://www.hackerrank.com/domains/cpp/classes) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Structs](https://www.hackerrank.com/challenges/c-tutorial-struct)|Learn how to create and use structures.|[C++](classes/c-tutorial-struct.cpp)|Easy [Class](https://www.hackerrank.com/challenges/c-tutorial-class)|Learn how to create and use classes.|[C++](classes/c-tutorial-class.cpp)|Easy [Classes and Objects](https://www.hackerrank.com/challenges/classes-objects)|Familiarize yourself with classes and objects.|[C++](classes/classes-objects.cpp)|Easy [Box It!](https://www.hackerrank.com/challenges/box-it)|Design a class named Box with overloaded operators.|[C++](classes/box-it.cpp)|Easy [Inherited Code](https://www.hackerrank.com/challenges/inherited-code)|Handle errors that can occur in the existing code.|[C++](classes/inherited-code.cpp)|Medium [Exceptional Server](https://www.hackerrank.com/challenges/exceptional-server)|Handle server errors.|[C++](classes/exceptional-server.cpp)|Medium [Virtual Functions](https://www.hackerrank.com/challenges/virtual-functions)|Learn how to use virtual functions and solve the given problem.|[C++](classes/virtual-functions.cpp)|Medium [Abstract Classes - Polymorphism](https://www.hackerrank.com/challenges/abstract-classes-polymorphism)|Given an abstract class Cache, write a class LRUCache which extends the class Cache and implement an LRU cache.|[C++](classes/abstract-classes-polymorphism.cpp)|Hard #### [STL](https://www.hackerrank.com/domains/cpp/stl) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Vector-Sort](https://www.hackerrank.com/challenges/vector-sort)|Learn about the container vector. Sort a vector and print the sorted vector.|[C++](stl/vector-sort.cpp)|Easy [Vector-Erase](https://www.hackerrank.com/challenges/vector-erase)|Erasing an element from a vector.|[C++](stl/vector-erase.cpp)|Easy [Lower Bound-STL](https://www.hackerrank.com/challenges/cpp-lower-bound)|Given N numbers, you have to find the smallest integer greater than the given number and print the index of that number.|[C++](stl/cpp-lower-bound.cpp)|Easy [Sets-STL](https://www.hackerrank.com/challenges/cpp-sets)|Learn about the set container. Given a problem with 3 queries, try to answer the queries using the set container.|[C++](stl/cpp-sets.cpp)|Easy [Maps-STL](https://www.hackerrank.com/challenges/cpp-maps)|Learn to use map container. Given some queries, add the marks to a corresponding student, delete a student and print the marks of a particular student.|[C++](stl/cpp-maps.cpp)|Easy [Print Pretty](https://www.hackerrank.com/challenges/prettyprint)|This challenge will test your knowledge of the STL <iomanip> library.|[C++](stl/prettyprint.cpp)|Easy [Deque-STL](https://www.hackerrank.com/challenges/deque-stl)|Learn to use deque container. Find the maximum number in each and every contiguous sub array of size K in the given array.|[C++](stl/deque-stl.cpp)|Medium #### [Inheritance](https://www.hackerrank.com/domains/cpp/inheritance) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Inheritance Introduction](https://www.hackerrank.com/challenges/inheritance-introduction)|Learn how to inherit classes from other classes.|[C++](inheritance/inheritance-introduction.cpp)|Easy [Rectangle Area](https://www.hackerrank.com/challenges/rectangle-area)|Find out the area of a rectangle. You are given the objects to the class and you have to implement these classes.|[C++](inheritance/rectangle-area.cpp)|Easy [Multi Level Inheritance ](https://www.hackerrank.com/challenges/multi-level-inheritance-cpp)|Learn what multiple inheritance is and try to solve this problem.|[C++](inheritance/multi-level-inheritance-cpp.cpp)|Easy [Accessing Inherited Functions](https://www.hackerrank.com/challenges/accessing-inherited-functions)|Access inherited functions with the same name.|[C++](inheritance/accessing-inherited-functions.cpp)|Medium [Magic Spells](https://www.hackerrank.com/challenges/magic-spells)|Identify the correct kind of spell and possibly compare it with your spell journal.|[C++](inheritance/magic-spells.cpp)|Hard #### [Debugging](https://www.hackerrank.com/domains/cpp/cpp-debugging) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Hotel Prices](https://www.hackerrank.com/challenges/hotel-prices)|Debug the existing class definitions so the total hotel's profit is calculated correctly.|[C++](cpp-debugging/hotel-prices.cpp)|Medium [Cpp exception handling](https://www.hackerrank.com/challenges/cpp-exception-handling)|Handle possible exceptions in a correct way.|[C++](cpp-debugging/cpp-exception-handling.cpp)|Medium [Overloading Ostream Operator](https://www.hackerrank.com/challenges/overloading-ostream-operator)|Overload the << operator for Person class.|[C++](cpp-debugging/overloading-ostream-operator.cpp)|Medium [Messages Order](https://www.hackerrank.com/challenges/messages-order)|Implement a software layer over the top of a network, such that sent messages are printed by the recipient in the order they were sent.|[C++](cpp-debugging/messages-order.cpp)|Medium #### [Other Concepts](https://www.hackerrank.com/domains/cpp/other-concepts) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [C++ Class Templates](https://www.hackerrank.com/challenges/c-class-templates)|Learn to use class templates. You are given a problem, solve that using class templates.|[C++](other-concepts/c-class-templates.cpp)|Easy [Preprocessor Solution](https://www.hackerrank.com/challenges/preprocessor-solution)|Create preprocessor macros to make the existing code work.|[C++](other-concepts/preprocessor-solution.cpp)|Easy [Operator Overloading](https://www.hackerrank.com/challenges/operator-overloading)|Learn how to overload operators. Print the sum of two matrices and print the resultant matrix.|[C++](other-concepts/operator-overloading.cpp)|Medium [Overload Operators](https://www.hackerrank.com/challenges/overload-operators)|Operator Overloading in C++.|[C++](other-concepts/overload-operators.cpp)|Easy [Attending Workshops](https://www.hackerrank.com/challenges/attending-workshops)|Define a structure for the workshop and find the number of workshops that the student can attend.|[C++](other-concepts/attending-workshops.cpp)|Medium [C++ Class Template Specialization](https://www.hackerrank.com/challenges/cpp-class-template-specialization)|Class templates in C++ create specializations for certain types. These can be used when difficult to provide a generic implementation.|[C++](other-concepts/cpp-class-template-specialization.cpp)|Medium [C++ Variadics](https://www.hackerrank.com/challenges/cpp-variadics)|Create a function that takes an arbitrary number of binary digits as template parameters in reverse order and returns the value.|[C++](other-concepts/cpp-variadics.cpp)|Hard [Bit Array](https://www.hackerrank.com/challenges/bitset-1)|Calculate the number of distinct integers created from the given code.|[C++](other-concepts/bitset-1.cpp)|Hard
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Classes and Objects // Familiarize yourself with classes and objects. // // https://www.hackerrank.com/challenges/classes-objects/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; // (template_head) ---------------------------------------------------------------------- // Write your Student class here class Student { int score_ = 0 ; public: void input() { int x; score_ = 0; for (int i = 0; i < 5; ++i) { cin >> x; score_ += x; } } int calculateTotalScore() const { return score_; } }; // (template_tail) ---------------------------------------------------------------------- int main() { int n; // number of students cin >> n; Student *s = new Student[n]; // an array of n students for(int i = 0; i < n; i++){ s[i].input(); } // calculate kristen's score int kristen_score = s[0].calculateTotalScore(); // determine how many students scored higher than kristen int count = 0; for(int i = 1; i < n; i++){ int total = s[i].calculateTotalScore(); if(total > kristen_score){ count++; } } // print result cout << count; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Class // Learn how to create and use classes. // // https://www.hackerrank.com/challenges/c-tutorial-class/problem // #include <iostream> #include <sstream> using namespace std; /* Enter code for class Student here. Read statement for specification. */ class Student { int age = 0; int standard = 0; string first_name, last_name; public: void set_first_name(const string& s) { first_name = s; } const string& get_first_name() const { return first_name; } void set_last_name(const string& s) { last_name = s; } const string& get_last_name() const { return last_name; } void set_age(int s) { age = s; } int get_age() const { return age; } void set_standard(int s) { standard = s; } int get_standard() const { return standard; } string to_string() const { stringstream ss; ss << age << "," << first_name << "," << last_name << "," << standard; return ss.str(); } }; int main() { int age, standard; string first_name, last_name; cin >> age >> first_name >> last_name >> standard; Student st; st.set_age(age); st.set_standard(standard); st.set_first_name(first_name); st.set_last_name(last_name); cout << st.get_age() << "\n"; cout << st.get_last_name() << ", " << st.get_first_name() << "\n"; cout << st.get_standard() << "\n"; cout << "\n"; cout << st.to_string(); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Virtual Functions // Learn how to use virtual functions and solve the given problem. // // https://www.hackerrank.com/challenges/virtual-functions/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; // (skeliton_head) ---------------------------------------------------------------------- #include <numeric> class Person { string name; int age; int person_id = 0; public: Person(int id = 0) : person_id(id) {} virtual void putdata() const { cout << name << " " << age << " " << getraw() << " " << person_id << endl; } virtual void getdata() { cin >> name >> age; } protected: void setid(int id) { person_id = id; } virtual int getraw() const = 0; }; class Student : public Person { int subjects[6]; static int id; public: Student() : Person(++id) {} virtual void getdata() override { Person::getdata(); for (int i = 0; i < 6; ++i) cin >> subjects[i]; } private: virtual int getraw() const override { return accumulate(subjects, subjects + 6, 0); } }; class Professor : public Person { int publications; static int id; public: Professor() : Person(++id) {} virtual void getdata() override { Person::getdata(); cin >> publications; } private: virtual int getraw() const override { return publications; } }; int Student::id = 0; int Professor::id = 0; // (skeliton_tail) ---------------------------------------------------------------------- int main(){ int n, val; cin>>n; //The number of objects that is going to be created. Person *per[n]; for(int i = 0;i < n;i++){ cin>>val; if(val == 1){ // If val is 1 current object is of type Professor per[i] = new Professor; } else per[i] = new Student; // Else the current object is of type Student per[i]->getdata(); // Get the data from the user. } for(int i=0;i<n;i++) per[i]->putdata(); // Print the required output for each object. return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Structs // Learn how to create and use structures. // // https://www.hackerrank.com/challenges/c-tutorial-struct/problem #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; /* add code for struct here. */ struct Student { int age; string first_name; string last_name; int standard; }; int main() { Student st; cin >> st.age >> st.first_name >> st.last_name >> st.standard; cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_hackerrank(box-it box-it.cpp) add_hackerrank(c-tutorial-class c-tutorial-class.cpp) add_hackerrank(classes-objects classes-objects.cpp) add_hackerrank(c-tutorial-struct c-tutorial-struct.cpp) add_hackerrank(abstract-classes-polymorphism abstract-classes-polymorphism.cpp) add_hackerrank(virtual-functions virtual-functions.cpp) add_hackerrank(inherited-code inherited-code.cpp) #add_hackerrank(exceptional-server exceptional-server.cpp) dirty_cpp(inherited-code) dirty_cpp(classes-objects) dirty_cpp(abstract-classes-polymorphism)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
#include <iostream> #include <vector> #include <map> #include <string> #include <algorithm> #include <set> #include <cassert> using namespace std; struct Node{ Node* next; Node* prev; int value; int key; Node(Node* p, Node* n, int k, int val):prev(p),next(n),key(k),value(val){}; Node(int k, int val):prev(NULL),next(NULL),key(k),value(val){}; }; class Cache{ protected: map<int,Node*> mp; //map the key to the node in the linked list int cp; //capacity Node* tail; // double linked list tail pointer Node* head; // double linked list head pointer virtual void set(int, int) = 0; //set function virtual int get(int) = 0; //get function }; //--------------------------------------------------------------------------- #include <queue> class LRUCache : protected Cache { std::queue<Node *> lru_; public: LRUCache(int capacity) { cp = capacity; } virtual ~LRUCache() { mp.clear(); while (! lru_.empty()) { Node *node = lru_.front(); delete node; lru_.pop(); } } virtual void set(int key, int val) override { auto i = mp.find(key); if (i != mp.end()) { i->second->value = val; return; } Node *node = new Node(key, val); if (lru_.size() >= cp) { Node *node = lru_.front(); mp.erase(node->key); delete node; lru_.pop(); } mp[key] = node; lru_.push(node); } virtual int get(int key) override { auto i = mp.find(key); if (i == mp.end()) return -1; return i->second->value; } }; //--------------------------------------------------------------------------- int main() { int n, capacity,i; cin >> n >> capacity; LRUCache l(capacity); for(i=0;i<n;i++) { string command; cin >> command; if(command == "get") { int key; cin >> key; cout << l.get(key) << endl; } else if(command == "set") { int key, value; cin >> key >> value; l.set(key,value); } } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/inherited-code/problem #include <iostream> #include <string> #include <sstream> #include <exception> using namespace std; class BadLengthException : public exception { string w; public: BadLengthException(int n) { stringstream ss; ss << n; w = ss.str(); } virtual ~BadLengthException() {} virtual const char* what() const noexcept override { return w.c_str(); } }; bool checkUsername(string username) { bool isValid = true; int n = username.length(); if(n < 5) { throw BadLengthException(n); } for(int i = 0; i < n-1; i++) { if(username[i] == 'w' && username[i+1] == 'w') { isValid = false; } } return isValid; } int main() { int T; cin >> T; while(T--) { string username; cin >> username; try { bool isValid = checkUsername(username); if(isValid) { cout << "Valid" << '\n'; } else { cout << "Invalid" << '\n'; } } catch (BadLengthException e) { cout << "Too short: " << e.what() << '\n'; } } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Box It! // // https://www.hackerrank.com/challenges/box-it/problem //#include<bits/stdc++.h> #include <iostream> using namespace std; //Implement the class Box //l,b,h are integers representing the dimensions of the box // The class should have the following functions : // Constructors: // Box(); // Box(int,int,int); // Box(Box); // int getLength(); // Return box's length // int getBreadth (); // Return box's breadth // int getHeight (); //Return box's height // long long CalculateVolume(); // Return the volume of the box //Overload operator < as specified //bool operator<(Box& b) //Overload operator << as specified //ostream& operator<<(ostream& out, Box& B) class Box { int l, b, h; public: Box() : l(0), b(0), h(0) {} Box(int length, int breadth, int height) : l(length), b(breadth), h(height) {} int getLength() const { return l; } int getBreadth() const { return b; } int getHeight() const { return h; } long long CalculateVolume() const { return (long long)l * (long long)b * (long long) h; } bool operator<(const Box& r) const { return l < r.l || (l == r.l && b < r.b) || (l == r.l && b == r.b && h < r.h); } }; ostream& operator<<(ostream& out, const Box& B) { out << B.getLength() << " " << B.getBreadth() << " " << B.getHeight(); return out; } void check2() { int n; cin>>n; Box temp; for(int i=0;i<n;i++) { int type; cin>>type; if(type ==1) { cout<<temp<<endl; } if(type == 2) { int l,b,h; cin>>l>>b>>h; Box NewBox(l,b,h); temp=NewBox; cout<<temp<<endl; } if(type==3) { int l,b,h; cin>>l>>b>>h; Box NewBox(l,b,h); if(NewBox<temp) { cout<<"Lesser\n"; } else { cout<<"Greater\n"; } } if(type==4) { cout<<temp.CalculateVolume()<<endl; } if(type==5) { Box NewBox(temp); cout<<NewBox<<endl; } } } int main() { check2(); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Exceptional Server // Handle server errors. // // https://www.hackerrank.com/challenges/exceptional-server/problem // // les gars d'hackerrank n'assoient un peu sur la qualité et la sécurité du code // après, faut pas s'étonner de la qualité du code industrialisé... #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wshorten-64-to-32" #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wfloat-conversion" // de plus, ce challenge ne fonctionne pas avec clang, il est ni pertinent // ni judicieux #include <iostream> #include <exception> #include <string> #include <stdexcept> #include <vector> #include <cmath> using namespace std; class Server { private: static int load; public: static int compute(long long A, long long B) { load += 1; if(A < 0) { throw std::invalid_argument("A is negative"); } vector<int> v(A, 0); int real = -1, cmplx = sqrt(-1); if(B == 0) throw 0; real = (A/B)*real; int ans = v.at(B); return real + A - B*ans; } static int getLoad() { return load; } }; int Server::load = 0; int main() { int T; cin >> T; while(T--) { long long A, B; cin >> A >> B; // (skeliton_head) ---------------------------------------------------------------------- /* Enter your code here. */ try { cout << Server::compute(A, B) << endl; } catch (bad_alloc& e) { cout << "Not enough memory" << endl; } catch (exception& e) { cout << "Exception: " << e.what() << endl; } catch (...) { cout << "Other Exception" << endl; } // (skeliton_tail) ---------------------------------------------------------------------- } cout << Server::getLoad() << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [C++](https://www.hackerrank.com/domains/cpp) A general-purpose programming language with imperative, object-oriented and generic programming features. #### [Classes](https://www.hackerrank.com/domains/cpp/classes) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Structs](https://www.hackerrank.com/challenges/c-tutorial-struct)|Learn how to create and use structures.|[C++](c-tutorial-struct.cpp)|Easy [Class](https://www.hackerrank.com/challenges/c-tutorial-class)|Learn how to create and use classes.|[C++](c-tutorial-class.cpp)|Easy [Classes and Objects](https://www.hackerrank.com/challenges/classes-objects)|Familiarize yourself with classes and objects.|[C++](classes-objects.cpp)|Easy [Box It!](https://www.hackerrank.com/challenges/box-it)|Design a class named Box with overloaded operators.|[C++](box-it.cpp)|Easy [Inherited Code](https://www.hackerrank.com/challenges/inherited-code)|Handle errors that can occur in the existing code.|[C++](inherited-code.cpp)|Medium [Exceptional Server](https://www.hackerrank.com/challenges/exceptional-server)|Handle server errors.|[C++](exceptional-server.cpp)|Medium [Virtual Functions](https://www.hackerrank.com/challenges/virtual-functions)|Learn how to use virtual functions and solve the given problem.|[C++](virtual-functions.cpp)|Medium [Abstract Classes - Polymorphism](https://www.hackerrank.com/challenges/abstract-classes-polymorphism)|Given an abstract class Cache, write a class LRUCache which extends the class Cache and implement an LRU cache.|[C++](abstract-classes-polymorphism.cpp)|Hard
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Rectangle Area // Find out the area of a rectangle. You are given the objects to the class and you have to implement these classes. // // https://www.hackerrank.com/challenges/rectangle-area/problem // #include <iostream> using namespace std; // (skeliton_head) ---------------------------------------------------------------------- /* * Create classes Rectangle and RectangleArea */ class Rectangle { protected: int width; int height; public: void display() const { cout << width << " " << height << endl; } void read_input() { cin >> width >> height; } }; class RectangleArea : public Rectangle { public: void display() const { cout << (width * height) << endl; } }; // (skeliton_tail) ---------------------------------------------------------------------- int main() { /* * Declare a RectangleArea object */ RectangleArea r_area; /* * Read the width and height */ r_area.read_input(); /* * Print the width and height */ r_area.Rectangle::display(); /* * Print the area */ r_area.display(); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/magic-spells/problem #include <iostream> #include <vector> #include <string> using namespace std; class Spell { private: string scrollName; public: Spell(): scrollName("") { } Spell(string name): scrollName(name) { } virtual ~Spell() { } string revealScrollName() { return scrollName; } }; class Fireball : public Spell { private: int power; public: Fireball(int power): power(power) { } void revealFirepower(){ cout << "Fireball: " << power << endl; } }; class Frostbite : public Spell { private: int power; public: Frostbite(int power): power(power) { } void revealFrostpower(){ cout << "Frostbite: " << power << endl; } }; class Thunderstorm : public Spell { private: int power; public: Thunderstorm(int power): power(power) { } void revealThunderpower(){ cout << "Thunderstorm: " << power << endl; } }; class Waterbolt : public Spell { private: int power; public: Waterbolt(int power): power(power) { } void revealWaterpower(){ cout << "Waterbolt: " << power << endl; } }; class SpellJournal { public: static string journal; static string read() { return journal; } }; string SpellJournal::journal = ""; void counterspell(Spell *spell) { /* Enter your code here */ if (Fireball *s = dynamic_cast<Fireball *>(spell)) { s->revealFirepower(); } else if (Waterbolt *s = dynamic_cast<Waterbolt *>(spell)) { s->revealWaterpower(); } else if (Frostbite *s = dynamic_cast<Frostbite *>(spell)) { s->revealFrostpower(); } else if (Thunderstorm *s = dynamic_cast<Thunderstorm *>(spell)) { s->revealThunderpower(); } else { auto name = spell->revealScrollName(); auto journal = SpellJournal::read(); vector<vector<size_t> > data(name.size() + 1, vector<size_t>(journal.size() + 1, 0)); for (size_t i = 0; i < name.size(); ++i) { for (size_t j = 0; j < journal.size(); ++j) { if (name[i] == journal[j]) data[i+1][j+1] = data[i][j] + 1; else data[i+1][j+1] = max(data[i][j + 1], data[i + 1][j]); } } cout << data[name.size()][journal.size()] << endl; } } class Wizard { public: Spell *cast() { Spell *spell; string s; cin >> s; int power; cin >> power; if(s == "fire") { spell = new Fireball(power); } else if(s == "frost") { spell = new Frostbite(power); } else if(s == "water") { spell = new Waterbolt(power); } else if(s == "thunder") { spell = new Thunderstorm(power); } else { spell = new Spell(s); cin >> SpellJournal::journal; } return spell; } }; int main() { int T; cin >> T; Wizard Arawn; while(T--) { Spell *spell = Arawn.cast(); counterspell(spell); } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_hackerrank(rectangle-area rectangle-area.cpp) add_hackerrank(inheritance-introduction inheritance-introduction.cpp) add_hackerrank(accessing-inherited-functions accessing-inherited-functions.cpp) add_hackerrank(magic-spells magic-spells.cpp) add_hackerrank(multi-level-inheritance-cpp multi-level-inheritance-cpp.cpp)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Multi Level Inheritance // Learn what multiple inheritance is and try to solve this problem. // // https://www.hackerrank.com/challenges/multi-level-inheritance-cpp/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; class Triangle{ public: void triangle(){ cout<<"I am a triangle\n"; } }; class Isosceles : public Triangle{ public: void isosceles(){ cout<<"I am an isosceles triangle\n"; } }; // (template_head) ---------------------------------------------------------------------- //Write your code here. class Equilateral : public Isosceles{ public: void equilateral(){ cout<<"I am an equilateral triangle\n"; } }; // (template_tail) ---------------------------------------------------------------------- int main(){ Equilateral eqr; eqr.equilateral(); eqr.isosceles(); eqr.triangle(); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Accessing Inherited Functions // Access inherited functions with the same name. // // https://www.hackerrank.com/challenges/accessing-inherited-functions/problem // #include<iostream> using namespace std; class A { public: A(){ callA = 0; } private: int callA; void inc(){ callA++; } protected: void func(int & a) { a = a * 2; inc(); } public: int getA(){ return callA; } }; class B { public: B(){ callB = 0; } private: int callB; void inc(){ callB++; } protected: void func(int & a) { a = a * 3; inc(); } public: int getB(){ return callB; } }; class C { public: C(){ callC = 0; } private: int callC; void inc(){ callC++; } protected: void func(int & a) { a = a * 5; inc(); } public: int getC(){ return callC; } }; // (skeliton_head) ---------------------------------------------------------------------- class D : A, B, C { int val; public: //Initially val is 1 D() { val = 1; } //Implement this function void update_val(int new_val) { for (; new_val % 2 == 0; new_val /= 2) A::func(val); for (; new_val % 3 == 0; new_val /= 3) B::func(val); for (; new_val % 5 == 0; new_val /= 5) C::func(val); } //For Checking Purpose void check(int); //Do not delete this line. }; // (skeliton_tail) ---------------------------------------------------------------------- void D::check(int new_val) { update_val(new_val); cout << "Value = " << val << endl << "A's func called " << getA() << " times " << endl << "B's func called " << getB() << " times" << endl << "C's func called " << getC() << " times" << endl; } int main() { D d; int new_val; cin >> new_val; d.check(new_val); }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Inheritance Introduction // Learn how to inherit classes from other classes. // // https://www.hackerrank.com/challenges/inheritance-introduction/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; class Triangle{ public: void triangle(){ cout<<"I am a triangle\n"; } }; // (template_head) ---------------------------------------------------------------------- class Isosceles : public Triangle{ public: void isosceles(){ cout<<"I am an isosceles triangle\n"; } //Write your code here. void description() { cout << "In an isosceles triangle two sides are equal" << endl; } }; // (template_tail) ---------------------------------------------------------------------- int main(){ Isosceles isc; isc.isosceles(); isc.description(); isc.triangle(); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [C++](https://www.hackerrank.com/domains/cpp) A general-purpose programming language with imperative, object-oriented and generic programming features. #### [Inheritance](https://www.hackerrank.com/domains/cpp/inheritance) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Inheritance Introduction](https://www.hackerrank.com/challenges/inheritance-introduction)|Learn how to inherit classes from other classes.|[C++](inheritance-introduction.cpp)|Easy [Rectangle Area](https://www.hackerrank.com/challenges/rectangle-area)|Find out the area of a rectangle. You are given the objects to the class and you have to implement these classes.|[C++](rectangle-area.cpp)|Easy [Multi Level Inheritance ](https://www.hackerrank.com/challenges/multi-level-inheritance-cpp)|Learn what multiple inheritance is and try to solve this problem.|[C++](multi-level-inheritance-cpp.cpp)|Easy [Accessing Inherited Functions](https://www.hackerrank.com/challenges/accessing-inherited-functions)|Access inherited functions with the same name.|[C++](accessing-inherited-functions.cpp)|Medium [Magic Spells](https://www.hackerrank.com/challenges/magic-spells)|Identify the correct kind of spell and possibly compare it with your spell journal.|[C++](magic-spells.cpp)|Hard
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Attending Workshops // Define a structure for the workshop and find the number of workshops that the student can attend. // // https://www.hackerrank.com/challenges/attending-workshops/problem // #include <bits/stdc++.h> using namespace std; // (skeliton_head) ---------------------------------------------------------------------- //Define the structs Workshops and Available_Workshops. //Implement the functions initialize and CalculateMaxWorkshops struct Workshops { int start_time = 0; int duration = 0; int end_time = 0; Workshops(int s, int d) : start_time(s), duration(d), end_time(s + d) { } }; struct Available_Workshops { vector<Workshops> arr; }; Available_Workshops* initialize (int start_time[], int duration[], int n) { Available_Workshops* aw = new Available_Workshops(); for (int i = 0; i < n; ++i) { aw->arr.push_back(Workshops(start_time[i], duration[i])); } return aw; } int CalculateMaxWorkshops(Available_Workshops *aw) { std::sort(aw->arr.begin(), aw->arr.end(), [](const Workshops & a, const Workshops & b) -> bool { return a.end_time < b.end_time; }); int last_time=-1; int nb = 0; for (const auto& w : aw->arr) { if (w.start_time >= last_time) { last_time = w.end_time; nb++; } } return nb; } // (skeliton_tail) ---------------------------------------------------------------------- int main(int argc, char *argv[]) { int n; // number of workshops cin >> n; // create arrays of unknown size n int* start_time = new int[n]; int* duration = new int[n]; for(int i=0; i < n; i++){ cin >> start_time[i]; } for(int i = 0; i < n; i++){ cin >> duration[i]; } Available_Workshops * ptr; ptr = initialize(start_time,duration, n); cout << CalculateMaxWorkshops(ptr) << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Preprocessor Solution // Create preprocessor macros to make the existing code work. // // https://www.hackerrank.com/challenges/preprocessor-solution/problem // #define INF 1000000000 #define FUNCTION(f, comp) \ void f(int& a, int b) \ { if (b comp a) a = b; } #define io(v) \ cin >> v #define toStr(x) #x #define foreach(v, i) \ for (size_t i = 0; i < v.size(); ++i) // (skeliton_tail) ---------------------------------------------------------------------- #include <iostream> #include <vector> using namespace std; #if !defined toStr || !defined io || !defined FUNCTION || !defined INF #error Missing preprocessor definitions #endif FUNCTION(minimum, <) FUNCTION(maximum, >) int main(){ int n; cin >> n; vector<int> v(n); foreach(v, i) { io(v)[i]; } int mn = INF; int mx = -INF; foreach(v, i) { minimum(mn, v[i]); maximum(mx, v[i]); } int ans = mx - mn; cout << toStr(Result =) <<' '<< ans; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/bitset-1/problem #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <set> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ unsigned int N, S, P, Q; unsigned int i, a; vector<bool> present; // nota: vector<bool> est optimisé present.resize(0x80000000); if (scanf("%u %u %u %u", &N, &S, &P, &Q) != 4) exit(2); int nb = 0; i = 0; a = S % 0x80000000; do { if (! present[a]) { ++nb; present[a] = true; } a = (a * P + Q) % 0x80000000; } while (++i < N); cout << nb << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Operator Overloading // Learn how to overload operators. Print the sum of two matrices and print the resultant matrix. // // https://www.hackerrank.com/challenges/operator-overloading/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; // (skeliton_head) ---------------------------------------------------------------------- class Matrix { public: vector<vector<int>> a; Matrix& operator+(const Matrix& r) { if (a.size() == r.a.size()) { for (size_t i = 0; i < a.size(); ++i) { auto& ai = a[i]; const auto& ri = r.a[i]; if (ai.size() == ri.size()) { for (size_t j = 0; j < ai.size(); ++j) { ai[j] += ri[j]; } } } } return *this; } }; // (skeliton_tail) ---------------------------------------------------------------------- int main () { int cases,k; cin >> cases; for(k=0;k<cases;k++) { Matrix x; Matrix y; Matrix result; int n,m,i,j; cin >> n >> m; for(i=0;i<n;i++) { vector<int> b; int num; for(j=0;j<m;j++) { cin >> num; b.push_back(num); } x.a.push_back(b); } for(i=0;i<n;i++) { vector<int> b; int num; for(j=0;j<m;j++) { cin >> num; b.push_back(num); } y.a.push_back(b); } result = x+y; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cout << result.a[i][j] << " "; } cout << endl; } } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_hackerrank(attending-workshops attending-workshops.cpp) add_hackerrank(c-class-templates c-class-templates.cpp) add_hackerrank(preprocessor-solution preprocessor-solution.cpp) add_hackerrank(bitset-1 bitset-1.cpp) add_hackerrank(cpp-variadics cpp-variadics.cpp) add_hackerrank(cpp-class-template-specialization cpp-class-template-specialization.cpp) add_hackerrank(overload-operators overload-operators.cpp) add_hackerrank(operator-overloading operator-overloading.cpp) dirty_cpp(attending-workshops) dirty_cpp(preprocessor-solution) dirty_cpp(overload-operators) dirty_cpp(operator-overloading)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// C++ Class Template Specialization // Class templates in C++ create specializations for certain types. These can be used when difficult to provide a generic implementation. // // https://www.hackerrank.com/challenges/cpp-class-template-specialization/problem // #include <iostream> using namespace std; enum class Fruit { apple, orange, pear }; enum class Color { red, green, orange }; template <typename T> struct Traits; // (skeliton_head) ---------------------------------------------------------------------- // Define specializations for the Traits class template here. template<> struct Traits<Color> { public: static string name(int i) { if (i == (int) Color::red) return "red"; if (i == (int) Color::green) return "green"; if (i == (int) Color::orange) return "orange"; return "unknown"; } }; template<> struct Traits<Fruit> { public: static string name(int i) { if (i == (int) Fruit::apple) return "apple"; if (i == (int) Fruit::orange) return "orange"; if (i == (int) Fruit::pear) return "pear"; return "unknown"; } }; // (skeliton_tail) ---------------------------------------------------------------------- int main() { int t = 0; std::cin >> t; for (int i=0; i!=t; ++i) { int index1; std::cin >> index1; int index2; std::cin >> index2; cout << Traits<Color>::name(index1) << " "; cout << Traits<Fruit>::name(index2) << "\n"; } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/c-class-templates/problem #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <cassert> using namespace std; /*Write the class AddElements here*/ template<typename T> class AddElements { T t_; public: AddElements(const T& t) : t_(t) {} T add(const T& r) const { return t_ + r; } T concatenate(const T& r) const { return t_ + r; } }; int main () { int n,i; cin >> n; for(i=0;i<n;i++) { string type; cin >> type; if(type=="float") { double element1,element2; cin >> element1 >> element2; AddElements<double> myfloat (element1); cout << myfloat.add(element2) << endl; } else if(type == "int") { int element1, element2; cin >> element1 >> element2; AddElements<int> myint (element1); cout << myint.add(element2) << endl; } else if(type == "string") { string element1, element2; cin >> element1 >> element2; AddElements<string> mystring (element1); cout << mystring.concatenate(element2) << endl; } } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Overload Operators // Operator Overloading in C++. // // https://www.hackerrank.com/challenges/overload-operators/problem // //Operator Overloading #include<iostream> using namespace std; class Complex { public: int a,b; void input(string s) { int v1=0; int i=0; while(s[i]!='+') { v1=v1*10+s[i]-'0'; i++; } while(s[i]==' ' || s[i]=='+'||s[i]=='i') { i++; } int v2=0; while(i<s.length()) { v2=v2*10+s[i]-'0'; i++; } a=v1; b=v2; } }; // (skeliton_head) ---------------------------------------------------------------------- //Overload operators + and << for the class complex //+ should add two complex numbers as (a+ib) + (c+id) = (a+c) + i(b+d) //<< should print a complex number in the format "a+ib" Complex operator+(const Complex& x, const Complex& y) { Complex z; z.a = x.a + y.a; z.b = x.b + y.b; return z; } ostream& operator<<(ostream& o, const Complex& x) { o << x.a << "+i" << x.b; return o; } // (skeliton_tail) ---------------------------------------------------------------------- int main() { Complex x,y; string s1,s2; cin>>s1; cin>>s2; x.input(s1); y.input(s2); Complex z=x+y; cout<<z<<endl; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/cpp-variadics/problem #include <iostream> using namespace std; // Enter your code for reversed_binary_value<bool...>() template<bool...digits> int reversed_binary_value(...) { //bool bits[] = { digits... }; auto i = 0, r = 0; for (auto b : { digits... }) { if (b) r |= 1 << i; i++; } return r; } template <int n, bool...digits> struct CheckValues { static void check(int x, int y) { CheckValues<n-1, 0, digits...>::check(x, y); CheckValues<n-1, 1, digits...>::check(x, y); } }; template <bool...digits> struct CheckValues<0, digits...> { static void check(int x, int y) { int z = reversed_binary_value<digits...>(); std::cout << (z+64*y==x); } }; int main() { int t; std::cin >> t; for (int i=0; i!=t; ++i) { int x, y; cin >> x >> y; CheckValues<6>::check(x, y); cout << "\n"; } }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [C++](https://www.hackerrank.com/domains/cpp) A general-purpose programming language with imperative, object-oriented and generic programming features. #### [Other Concepts](https://www.hackerrank.com/domains/cpp/other-concepts) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [C++ Class Templates](https://www.hackerrank.com/challenges/c-class-templates)|Learn to use class templates. You are given a problem, solve that using class templates.|[C++](c-class-templates.cpp)|Easy [Preprocessor Solution](https://www.hackerrank.com/challenges/preprocessor-solution)|Create preprocessor macros to make the existing code work.|[C++](preprocessor-solution.cpp)|Easy [Operator Overloading](https://www.hackerrank.com/challenges/operator-overloading)|Learn how to overload operators. Print the sum of two matrices and print the resultant matrix.|[C++](operator-overloading.cpp)|Medium [Overload Operators](https://www.hackerrank.com/challenges/overload-operators)|Operator Overloading in C++.|[C++](overload-operators.cpp)|Easy [Attending Workshops](https://www.hackerrank.com/challenges/attending-workshops)|Define a structure for the workshop and find the number of workshops that the student can attend.|[C++](attending-workshops.cpp)|Medium [C++ Class Template Specialization](https://www.hackerrank.com/challenges/cpp-class-template-specialization)|Class templates in C++ create specializations for certain types. These can be used when difficult to provide a generic implementation.|[C++](cpp-class-template-specialization.cpp)|Medium [C++ Variadics](https://www.hackerrank.com/challenges/cpp-variadics)|Create a function that takes an arbitrary number of binary digits as template parameters in reverse order and returns the value.|[C++](cpp-variadics.cpp)|Hard [Bit Array](https://www.hackerrank.com/challenges/bitset-1)|Calculate the number of distinct integers created from the given code.|[C++](bitset-1.cpp)|Hard
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/deque-stl/problem #include <iostream> #include <deque> #include <algorithm> #include <sstream> using namespace std; void printKMax_basic(int arr[], int n, int k) { //Write your code here. std::deque<int> q; for (int i = 0; i < n; ++i) { int a = arr[i]; q.push_back(a); while (q.size() > k) q.pop_front(); if (q.size() == k) { int m = *max_element(q.begin(), q.end()); cout << m << " "; } } cout << endl; } void printKMax(int arr[], int n, int k) { deque<int> dq; for (int i=0; i<n; i++){ // base case for first element if (dq.empty()){ dq.push_back(i); } // remove elements outside the current window if (dq.front() <= (i - k)){ dq.pop_front(); } // move max element to the front while (!dq.empty() && arr[i] >= arr[dq.back()]){ dq.pop_back(); } dq.push_back(i); // print out only when the first window is completed if (i >= (k - 1)) { cout << arr[dq.front()] << " "; } } cout << endl; } int main() { int t; cin >> t; while(t>0) { int n,k; cin >> n >> k; int i; int arr[n]; for(i=0;i<n;i++) cin >> arr[i]; printKMax(arr, n, k); t--; } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Print Pretty // This challenge will test your knowledge of the STL <iomanip> library. // // https://www.hackerrank.com/challenges/prettyprint/problem // #include <iostream> #include <iomanip> using namespace std; int main() { int T; cin >> T; cout << setiosflags(ios::uppercase); cout << setw(0xf) << internal; while(T--) { double A; cin >> A; double B; cin >> B; double C; cin >> C; // (skeliton_head) ---------------------------------------------------------------------- // LINE 1 cout << hex << left << showbase << nouppercase; cout << (long long unsigned int)A << endl; // LINE 2 cout << dec << right << setw(15) << setfill('_') << showpos << fixed << setprecision(2); cout << B << endl; // LINE 3 cout << scientific << uppercase << noshowpos << setprecision(9); cout << C << endl; // (skeliton_tail) ---------------------------------------------------------------------- } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Maps-STL // Learn to use map container. Given some queries, add the marks to a corresponding student, delete a student and print the marks of a particular student. // // https://www.hackerrank.com/challenges/cpp-maps/problem // #include <string> #include <map> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; map<string, int> students; string name; int mark; int cmd; cin >> n; while (n-- != 0) { cin >> cmd; if (cmd == 1) { cin >> name >> mark; students[name] += mark; } else if (cmd == 2) { cin >> name; students.erase(name); } else if (cmd == 3) { cin >> name; cout << students[name] << endl; } } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_hackerrank(vector-erase vector-erase.cpp) add_hackerrank(cpp-sets cpp-sets.cpp) add_hackerrank(cpp-lower-bound cpp-lower-bound.cpp) add_hackerrank(deque-stl deque-stl.cpp) add_hackerrank(vector-sort vector-sort.cpp) add_hackerrank(prettyprint prettyprint.cpp) add_hackerrank(cpp-maps cpp-maps.cpp) dirty_cpp(deque-stl)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Sets-STL // Learn about the set container. Given a problem with 3 queries, try to answer the queries using the set container. // // https://www.hackerrank.com/challenges/cpp-sets/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <set> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ set<int> s; int q, op, i; cin >> q; while (q-- != 0) { cin >> op >> i; switch (op) { case 1: s.insert(i); break; case 2: s.erase(i); break; case 3: cout << (s.count(i) != 0 ? "Yes" : "No") << endl; } } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Vector-Erase // Erasing an element from a vector. // // https://www.hackerrank.com/challenges/vector-erase/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ vector<int> v; int n, x, a, b; cin >> n; while (n--) { int i; cin >> i; v.push_back(i); } cin >> x; v.erase(v.begin() + x - 1); cin >> a >> b; v.erase(v.begin() + a - 1, v.begin() + b - 1); cout << v.size() << endl; for (const auto& i : v) cout << i << " "; cout << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// https://www.hackerrank.com/challenges/vector-sort/problem #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int N, x; vector<int> v; cin >> N; for (int i = 0; i < N; ++i) { cin >> x; v.push_back(x); } std::sort(v.begin(), v.end()); for (const auto& i :v) cout << i << " "; cout << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Lower Bound-STL // Given N numbers, you have to find the smallest integer greater than the given number and print the index of that number. // // https://www.hackerrank.com/challenges/cpp-lower-bound/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ vector<int> v; int n, q; cin >> n; while (n--) { int i; cin >> i; v.push_back(i); } cin >> n; while (n-- != 0) { cin >> q; vector<int>::const_iterator r = lower_bound(v.begin(), v.end(), q); cout << ((*r == q) ? "Yes " : "No ") << 1 + (r - v.begin()) << endl; } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [C++](https://www.hackerrank.com/domains/cpp) A general-purpose programming language with imperative, object-oriented and generic programming features. #### [STL](https://www.hackerrank.com/domains/cpp/stl) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Vector-Sort](https://www.hackerrank.com/challenges/vector-sort)|Learn about the container vector. Sort a vector and print the sorted vector.|[C++](vector-sort.cpp)|Easy [Vector-Erase](https://www.hackerrank.com/challenges/vector-erase)|Erasing an element from a vector.|[C++](vector-erase.cpp)|Easy [Lower Bound-STL](https://www.hackerrank.com/challenges/cpp-lower-bound)|Given N numbers, you have to find the smallest integer greater than the given number and print the index of that number.|[C++](cpp-lower-bound.cpp)|Easy [Sets-STL](https://www.hackerrank.com/challenges/cpp-sets)|Learn about the set container. Given a problem with 3 queries, try to answer the queries using the set container.|[C++](cpp-sets.cpp)|Easy [Maps-STL](https://www.hackerrank.com/challenges/cpp-maps)|Learn to use map container. Given some queries, add the marks to a corresponding student, delete a student and print the marks of a particular student.|[C++](cpp-maps.cpp)|Easy [Print Pretty](https://www.hackerrank.com/challenges/prettyprint)|This challenge will test your knowledge of the STL <iomanip> library.|[C++](prettyprint.cpp)|Easy [Deque-STL](https://www.hackerrank.com/challenges/deque-stl)|Learn to use deque container. Find the maximum number in each and every contiguous sub array of size K in the given array.|[C++](deque-stl.cpp)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// C++ > Debugging > Cpp exception handling // Handle possible exceptions in a correct way. // // https://www.hackerrank.com/challenges/cpp-exception-handling/problem // #include <iostream> #include <stdexcept> using namespace std; int largest_proper_divisor(int n) { if (n == 0) { throw invalid_argument("largest proper divisor is not defined for n=0"); } if (n == 1) { throw invalid_argument("largest proper divisor is not defined for n=1"); } for (int i = n/2; i >= 1; --i) { if (n % i == 0) { return i; } } return -1; // will never happen } // (skeliton_head) ---------------------------------------------------------------------- void process_input(int n) { try { int d = largest_proper_divisor(n); cout << "result=" << d << endl; } catch (exception &e) { cout << e.what() << endl; } cout << "returning control flow to caller" << endl; } // (skeliton_tail) ---------------------------------------------------------------------- int main() { int n; cin >> n; process_input(n); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// C++ > Debugging > Hotel Prices // Debug the existing class definitions so the total hotel's profit is calculated correctly. // // https://www.hackerrank.com/challenges/hotel-prices/problem // #include <iostream> #include <vector> using namespace std; class HotelRoom { public: HotelRoom(int bedrooms, int bathrooms) : bedrooms_(bedrooms), bathrooms_(bathrooms) {} virtual ~HotelRoom() {} virtual int get_price() { return 50*bedrooms_ + 100*bathrooms_; } private: int bedrooms_; int bathrooms_; }; class HotelApartment : public HotelRoom { public: HotelApartment(int bedrooms, int bathrooms) : HotelRoom(bedrooms, bathrooms) {} virtual ~HotelApartment() {} virtual int get_price() override { return HotelRoom::get_price() + 100; } }; int main() { int n; cin >> n; vector<HotelRoom*> rooms; for (int i = 0; i < n; ++i) { string room_type; int bedrooms; int bathrooms; cin >> room_type >> bedrooms >> bathrooms; if (room_type == "standard") { rooms.push_back(new HotelRoom(bedrooms, bathrooms)); } else { rooms.push_back(new HotelApartment(bedrooms, bathrooms)); } } int total_profit = 0; for (auto room : rooms) { total_profit += room->get_price(); } cout << total_profit << endl; for (auto room : rooms) { delete room; } rooms.clear(); return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// C++ > Debugging > Cpp messages order // Implement a software layer over the top of a network, such that sent messages are printed by the recipient in the order they were sent. // // https://www.hackerrank.com/challenges/messages-order/problem // challenge id: 67829 // #include <iostream> #include <algorithm> #include <vector> using namespace std; // (skeliton_head) ---------------------------------------------------------------------- class Message { string text_; int seq_ = 0; public: Message() {} Message(const string& text, int seq = 0) : text_(text), seq_(seq) { } const string& get_text() const { return text_; } bool operator<(const Message& o) const { return seq_ < o.seq_; } }; class MessageFactory { int seq_ = 0; public: MessageFactory() {} Message create_message(const string& text) { return Message(text, seq_++); } }; // (skeliton_tail) ---------------------------------------------------------------------- class Recipient { public: Recipient() {} void receive(const Message& msg) { messages_.push_back(msg); } void print_messages() { fix_order(); for (auto& msg : messages_) { cout << msg.get_text() << endl; } messages_.clear(); } private: void fix_order() { sort(messages_.begin(), messages_.end()); } vector<Message> messages_; }; class Network { public: static void send_messages(vector<Message> messages, Recipient& recipient) { // simulates the unpredictable network, where sent messages might arrive in unspecified order random_shuffle(messages.begin(), messages.end()); for (auto msg : messages) { recipient.receive(msg); } } }; int main() { MessageFactory message_factory; Recipient recipient; vector<Message> messages; string text; while (getline(cin, text)) { messages.push_back(message_factory.create_message(text)); } Network::send_messages(messages, recipient); recipient.print_messages(); }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
add_hackerrank(hotel-prices hotel-prices.cpp) add_hackerrank(cpp-exception-handling cpp-exception-handling.cpp) add_hackerrank(messages-order messages-order.cpp) add_hackerrank(overloading-ostream-operator overloading-ostream-operator.cpp)
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// C++ > Debugging > Cpp overloading ostream operator // Overload the << operator for Person class. // // https://www.hackerrank.com/challenges/cpp-overloading-ostream-operator/problem // challenge id: 67733 // #include <iostream> using namespace std; class Person { public: Person(const string& first_name, const string& last_name) : first_name_(first_name), last_name_(last_name) {} const string& get_first_name() const { return first_name_; } const string& get_last_name() const { return last_name_; } private: string first_name_; string last_name_; }; // (skeliton_head) ---------------------------------------------------------------------- // Enter your code here. ostream& operator<<(ostream& o, const Person& p) { o << "first_name=" << p.get_first_name() << ",last_name=" << p.get_last_name(); return o; } // (skeliton_tail) ---------------------------------------------------------------------- int main() { string first_name, last_name, event; cin >> first_name >> last_name >> event; auto p = Person(first_name, last_name); cout << p << " " << event << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
### [C++](https://www.hackerrank.com/domains/cpp) A general-purpose programming language with imperative, object-oriented and generic programming features. #### [Debugging](https://www.hackerrank.com/domains/cpp/cpp-debugging) Name | Preview | Code | Difficulty ---- | ------- | ---- | ---------- [Hotel Prices](https://www.hackerrank.com/challenges/hotel-prices)|Debug the existing class definitions so the total hotel's profit is calculated correctly.|[C++](hotel-prices.cpp)|Medium [Cpp exception handling](https://www.hackerrank.com/challenges/cpp-exception-handling)|Handle possible exceptions in a correct way.|[C++](cpp-exception-handling.cpp)|Medium [Overloading Ostream Operator](https://www.hackerrank.com/challenges/overloading-ostream-operator)|Overload the << operator for Person class.|[C++](overloading-ostream-operator.cpp)|Medium [Messages Order](https://www.hackerrank.com/challenges/messages-order)|Implement a software layer over the top of a network, such that sent messages are printed by the recipient in the order they were sent.|[C++](messages-order.cpp)|Medium
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Variable Sized Arrays // Find the element described in the query for integer sequences. // // https://www.hackerrank.com/challenges/variable-sized-arrays/problem // #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ vector<vector<int>> w; int n, q; cin >> n >> q; while (n-- != 0) { size_t k; int x; vector<int> v; cin >> k; while (k-- != 0) { cin >> x; v.push_back(x); } w.push_back(v); } while (q-- != 0) { size_t i, j; cin >> i >> j; cout << w[i][j] << endl; } return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }
// Arrays Introduction // // https://www.hackerrank.com/challenges/arrays-introduction/problem #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int N, x; vector<int> v; cin >> N; while (N-- > 0) { cin >> x; v.push_back(x); } for (auto i = v.rbegin(); i != v.rend(); ++i) cout << *i << " "; cout << endl; return 0; }
{ "repo_name": "rene-d/hackerrank", "stars": "65", "repo_language": "Python", "file_name": "README.md", "mime_type": "text/plain" }