├── .github └── ISSUE_TEMPLATE │ └── feature_request.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Day 0 - Hello World.java ├── Day 1 - Data Types.java ├── Day 10 - Binary Numbers.java ├── Day 11 - 2D Arrays.java ├── Day 12 -Inheritance.java ├── Day 13 - Abstract Classes.java ├── Day 14 - Scope.java ├── Day 15 - Linked List.java ├── Day 16 - Exceptions - String to Integer.java ├── Day 17 - More Exceptions.java ├── Day 18 - Queues and Stacks.java ├── Day 19 - Interfaces.java ├── Day 2 - Operators.java ├── Day 20 - Sorting.java ├── Day 21 - Generics.java ├── Day 22 - Binary Search Trees.java ├── Day 23 - BST Level-Order Traversal.java ├── Day 24 - More Linked Lists.java ├── Day 25 - Running Time and Complexity.java ├── Day 26 - Nested Logic.java ├── Day 27 - Testing.java ├── Day 28 - RegEx, Patterns, and Intro to Databases.java ├── Day 29 - Bitwise AND.java ├── Day 3 - Intro to Conditional Statements.java ├── Day 4 - Class vs. Instance.java ├── Day 5 - Loops.java ├── Day 6 - Let's Review.java ├── Day 7 - Arrays.java ├── Day 8 - Dictionaries and Maps.java ├── Day 9 - Recursion 3.java ├── LICENSE └── README.md /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an answer to be updated 4 | title: Feature 5 | labels: enhancement 6 | assignees: Chitturiarunkrishna 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at chitturiarunkrishna@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note there is a code of conduct, please follow it in all your interactions with the repository. 7 | -------------------------------------------------------------------------------- /Day 0 - Hello World.java: -------------------------------------------------------------------------------- 1 | 2 | // just this one line 3 | 4 | System.out.println(inputString); -------------------------------------------------------------------------------- /Day 1 - Data Types.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | int i = 4; 11 | double d = 4.0; 12 | String s = "HackerRank "; 13 | 14 | Scanner scan = new Scanner(System.in); 15 | int a = scan.nextInt(); 16 | double b = scan.nextDouble(); 17 | scan.nextLine(); 18 | String c = scan.nextLine(); 19 | System.out.println(i+a); 20 | System.out.printf("%.1f",(d+b)); 21 | System.out.println(); 22 | System.out.println("HackerRank "+c); 23 | scan.close(); 24 | } 25 | } -------------------------------------------------------------------------------- /Day 10 - Binary Numbers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner in = new Scanner(System.in); 14 | int n = in.nextInt(); 15 | int sum = 0, max = 0; 16 | while (n > 0) 17 | { 18 | if (n % 2 == 1) 19 | { 20 | sum++; 21 | if (sum > max) 22 | { 23 | max = sum; 24 | } 25 | } 26 | else 27 | { 28 | sum = 0; 29 | } 30 | n = n / 2; 31 | } 32 | System.out.println(max); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Day 11 - 2D Arrays.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution 4 | { 5 | public static void main(String[] args) 6 | { 7 | Scanner in = new Scanner(System.in); 8 | int a[][] = new int[6][6]; 9 | int i,j,sum; 10 | int maxSum = Integer.MIN_VALUE; 11 | for (i = 0; i < 6; i++) 12 | { 13 | for (j = 0; j < 6; j++) 14 | { 15 | a[i][j] = in.nextInt(); 16 | } 17 | } 18 | for(i = 0; i < 4; i++) 19 | { 20 | for (j = 0; j < 4; j++) 21 | { 22 | sum = a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2]; 23 | if (maxSum < sum) 24 | { 25 | maxSum = sum; 26 | } 27 | } 28 | } 29 | 30 | System.out.println(maxSum); 31 | } 32 | } -------------------------------------------------------------------------------- /Day 12 -Inheritance.java: -------------------------------------------------------------------------------- 1 | class Student extends Person 2 | { 3 | private int[] testScores; 4 | 5 | Student(String firstName, String lastName, int identification, int[] testScores) 6 | { 7 | super(firstName, lastName, identification); 8 | 9 | this.testScores = testScores; 10 | } 11 | char calculate() 12 | { 13 | int total = 0; 14 | for (int testScore : testScores) 15 | { 16 | total += testScore; 17 | } 18 | int avg = total / testScores.length; 19 | 20 | if (avg >= 90 && avg <= 100) return 'O'; 21 | if (avg >= 80 && avg < 90) return 'E'; 22 | if (avg >= 70 && avg < 80) return 'A'; 23 | if (avg >= 55 && avg < 70) return 'P'; 24 | if (avg >= 40 && avg < 55) return 'D'; 25 | return 'T'; 26 | } 27 | } -------------------------------------------------------------------------------- /Day 13 - Abstract Classes.java: -------------------------------------------------------------------------------- 1 | class MyBook extends Book 2 | { 3 | private int price; 4 | 5 | MyBook(String t, String a, int p) 6 | { 7 | super(t, a); 8 | price = p; 9 | } 10 | void display() 11 | { 12 | System.out.println("Title: " + title + "\nAuthor: " + author + "\nPrice: " + price); 13 | } 14 | } -------------------------------------------------------------------------------- /Day 14 - Scope.java: -------------------------------------------------------------------------------- 1 | class Difference { 2 | private int[] elements; 3 | public int maximumDifference; 4 | 5 | Difference(int[] elements) { 6 | this.elements = elements; 7 | } 8 | 9 | public void computeDifference() { 10 | int max = 0; 11 | 12 | for (int i = 0; i < elements.length; i++) { 13 | for (int j = 0; j < elements.length; j++) { 14 | int abs = Math.abs(elements[i] - elements[j]); 15 | if (abs > max) max = abs; 16 | } 17 | } 18 | 19 | maximumDifference = max; 20 | } 21 | } -------------------------------------------------------------------------------- /Day 15 - Linked List.java: -------------------------------------------------------------------------------- 1 | public static Node insert(Node head,int data) 2 | { 3 | if (head == null) 4 | head = new Node(data); 5 | else 6 | { 7 | Node curr = head; 8 | while (curr.next != null) curr = curr.next; 9 | curr.next = new Node(data); 10 | } 11 | return head; 12 | } -------------------------------------------------------------------------------- /Day 16 - Exceptions - String to Integer.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) 10 | { 11 | Scanner in = new Scanner(System.in); 12 | String S = in.next(); 13 | try 14 | { 15 | Integer integer = Integer.parseInt(S); 16 | System.out.println(integer); 17 | } 18 | catch (Exception e) 19 | { 20 | System.out.println("Bad String"); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Day 17 - More Exceptions.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Calculator 5 | { 6 | public int power(int n, int p) throws Exception 7 | { 8 | if (n < 0 || p < 0) 9 | { 10 | throw new Exception("n and p should be non-negative"); 11 | } 12 | return (int) Math.pow(n, p); 13 | } 14 | } 15 | 16 | class Solution{ 17 | 18 | public static void main(String[] args) { 19 | 20 | Scanner in = new Scanner(System.in); 21 | int t = in.nextInt(); 22 | while (t-- > 0) { 23 | 24 | int n = in.nextInt(); 25 | int p = in.nextInt(); 26 | Calculator myCalculator = new Calculator(); 27 | try { 28 | int ans = myCalculator.power(n, p); 29 | System.out.println(ans); 30 | } 31 | catch (Exception e) { 32 | System.out.println(e.getMessage()); 33 | } 34 | } 35 | in.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Day 18 - Queues and Stacks.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | // Write your code here. 6 | private LinkedList stack; 7 | private LinkedList queue; 8 | 9 | public Solution() { 10 | this.stack = new LinkedList(); 11 | this.queue = new LinkedList(); 12 | } 13 | 14 | private char popCharacter() { 15 | return (char) this.stack.pop(); 16 | } 17 | 18 | private void pushCharacter(char c) { 19 | this.stack.push(c); 20 | } 21 | 22 | private char dequeueCharacter() { 23 | return (char) this.queue.remove(0); 24 | } 25 | 26 | private void enqueueCharacter(char c) { 27 | this.queue.addLast(c); 28 | } 29 | 30 | public static void main(String[] args) { 31 | Scanner scan = new Scanner(System.in); 32 | String input = scan.nextLine(); 33 | scan.close(); 34 | 35 | // Convert input String to an array of characters: 36 | char[] s = input.toCharArray(); 37 | 38 | // Create a Solution object: 39 | Solution p = new Solution(); 40 | 41 | // Enqueue/Push all chars to their respective data structures: 42 | for (char c : s) { 43 | p.pushCharacter(c); 44 | p.enqueueCharacter(c); 45 | } 46 | 47 | // Pop/Dequeue the chars at the head of both data structures and compare them: 48 | boolean isPalindrome = true; 49 | for (int i = 0; i < s.length/2; i++) { 50 | if (p.popCharacter() != p.dequeueCharacter()) { 51 | isPalindrome = false; 52 | break; 53 | } 54 | } 55 | 56 | //Finally, print whether string s is palindrome or not. 57 | System.out.println( "The word, " + input + ", is " 58 | + ( (!isPalindrome) ? "not a palindrome." : "a palindrome." ) ); 59 | } 60 | } -------------------------------------------------------------------------------- /Day 19 - Interfaces.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | interface AdvancedArithmetic{ 5 | int divisorSum(int n); 6 | } 7 | class Calculator implements AdvancedArithmetic 8 | { 9 | public int divisorSum(int n) 10 | { 11 | int sum = 0; 12 | for (int i = 1; i <= n; i++) 13 | { 14 | if (n % i == 0) sum += i; 15 | } 16 | return sum; 17 | } 18 | } 19 | 20 | class Solution { 21 | 22 | public static void main(String[] args) { 23 | Scanner scan = new Scanner(System.in); 24 | int n = scan.nextInt(); 25 | scan.close(); 26 | 27 | AdvancedArithmetic myCalculator = new Calculator(); 28 | int sum = myCalculator.divisorSum(n); 29 | System.out.println("I implemented: " + myCalculator.getClass().getInterfaces()[0].getName() ); 30 | System.out.println(sum); 31 | } 32 | } -------------------------------------------------------------------------------- /Day 2 - Operators.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | double m = sc.nextDouble(); 15 | int tip= sc.nextInt(); 16 | int tax = sc.nextInt(); 17 | double ftip = (m*tip)/100; 18 | double ftax = (m*tax)/100; 19 | int total = (int) Math.round(ftip+ftax+m); 20 | System.out.println(total); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day 20 - Sorting.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) 10 | { 11 | Scanner in = new Scanner(System.in); 12 | int n = in.nextInt(); 13 | int arr[] = new int[n]; 14 | for (int i = 0; i < n; i++) 15 | { 16 | arr[i] = in.nextInt(); 17 | } 18 | int numSwaps = 0; 19 | for (int i = 0; i < n; i++) { 20 | for (int j = 0; j < n - 1; j++) { 21 | if (arr[j] > arr[j + 1]) { 22 | int tmp = arr[j]; 23 | arr[j] = arr[j + 1]; 24 | arr[j + 1] = tmp; 25 | numSwaps++; 26 | } 27 | } 28 | if (numSwaps == 0) { 29 | break; 30 | } 31 | } 32 | System.out.println("Array is sorted in " + numSwaps + " swaps."); 33 | System.out.println("First Element: " + arr[0]); 34 | System.out.println("Last Element: " + arr[arr.length - 1]); 35 | } 36 | } -------------------------------------------------------------------------------- /Day 21 - Generics.java: -------------------------------------------------------------------------------- 1 | class Printer 2 | { 3 | public static < E > void printArray( E[] inputArray ) 4 | { 5 | for ( E element : inputArray ){ 6 | System.out.println( element ); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Day 22 - Binary Search Trees.java: -------------------------------------------------------------------------------- 1 | public static int getHeight(Node root) 2 | { 3 | 4 | return root == null ? -1 : 1 + Math.max(getHeight(root.left), getHeight(root.right)); 5 | } -------------------------------------------------------------------------------- /Day 23 - BST Level-Order Traversal.java: -------------------------------------------------------------------------------- 1 | public static void levelOrder(Node root) 2 | { 3 | Queue queue = new LinkedList<>(); 4 | queue.add(root); 5 | while (!queue.isEmpty()) 6 | { 7 | Node curr = queue.remove(); 8 | System.out.print(curr.data + " "); 9 | 10 | if (curr.left != null) queue.add(curr.left); 11 | if (curr.right != null) queue.add(curr.right); 12 | } 13 | } -------------------------------------------------------------------------------- /Day 24 - More Linked Lists.java: -------------------------------------------------------------------------------- 1 | public static Node removeDuplicates(Node head) 2 | { 3 | Node curr = head; 4 | while ((curr != null) && (curr.next != null)) 5 | { 6 | while ((curr.next != null) && (curr.data == curr.next.data)) 7 | { 8 | curr.next = curr.next.next; 9 | } 10 | curr = curr.next; 11 | } 12 | return head; 13 | } -------------------------------------------------------------------------------- /Day 25 - Running Time and Complexity.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution 5 | { 6 | public static boolean isPrime(int n) 7 | { 8 | for (int i = 2; i <= Math.sqrt(n); i++) 9 | { 10 | if (n % i == 0) 11 | { 12 | return false; 13 | } 14 | } 15 | return true; 16 | } 17 | 18 | public static void main(String[] args) 19 | { 20 | Scanner in = new Scanner(System.in); 21 | int T = in.nextInt(); 22 | for (int i = 0; i < T; i++) 23 | { 24 | int n = in.nextInt(); 25 | if (n >= 2 && isPrime(n)) 26 | System.out.println("Prime"); 27 | else System.out.println("Not prime"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Day 26 - Nested Logic.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Solution { 3 | public static void main(String[] args) { 4 | Scanner in = new Scanner(System.in); 5 | 6 | int da = in.nextInt(); 7 | int ma = in.nextInt(); 8 | int ya = in.nextInt(); 9 | 10 | int de = in.nextInt(); 11 | int me = in.nextInt(); 12 | int ye = in.nextInt(); 13 | 14 | int fine = 0; 15 | 16 | if (ya > ye) fine = 10000; 17 | else if (ya == ye) { 18 | if (ma > me) fine = (ma - me) * 500; 19 | else if (ma == me && da > de) fine = (da - de) * 15; 20 | } 21 | 22 | System.out.println(fine); 23 | } 24 | } -------------------------------------------------------------------------------- /Day 27 - Testing.java: -------------------------------------------------------------------------------- 1 | static class TestDataEmptyArray { 2 | public static int[] get_array() { 3 | // complete this function 4 | return new int[]{}; 5 | } 6 | } 7 | 8 | static class TestDataUniqueValues { 9 | public static int[] get_array() { 10 | // complete this function 11 | return new int[]{1, 2, 3, 4, 5}; 12 | } 13 | 14 | public static int get_expected_result() { 15 | // complete this function 16 | return minimum_index(get_array()); 17 | } 18 | } 19 | 20 | static class TestDataExactlyTwoDifferentMinimums { 21 | public static int[] get_array() { 22 | // complete this function 23 | return new int[] {1, 2, 3, 4, 3, 2, 1}; 24 | } 25 | 26 | public static int get_expected_result() { 27 | // complete this function 28 | return minimum_index(get_array()); 29 | } 30 | } -------------------------------------------------------------------------------- /Day 28 - RegEx, Patterns, and Intro to Databases.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution 10 | { 11 | 12 | public static void main(String[] args) 13 | { 14 | Scanner in = new Scanner(System.in); 15 | int N = in.nextInt(); 16 | 17 | String emailRegEx = ".+@gmail\\.com$"; 18 | Pattern pattern = Pattern.compile(emailRegEx); 19 | 20 | ArrayList list = new ArrayList<>(); 21 | 22 | for (int i = 0; i < N; i++) { 23 | String name = in.next(); 24 | String email = in.next(); 25 | Matcher matcher = pattern.matcher(email); 26 | 27 | if (matcher.find()) list.add(name); 28 | } 29 | 30 | Collections.sort(list); 31 | 32 | list.forEach(System.out::println); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Day 29 - Bitwise AND.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BitwiseAND 4 | { 5 | public static void main(String[] args) 6 | { 7 | Scanner in = new Scanner(System.in); 8 | int T = in.nextInt(); 9 | 10 | for (int i = 0; i < T; i++) { 11 | 12 | int N = in.nextInt(); 13 | int K = in.nextInt(); 14 | 15 | int max = 0; 16 | 17 | for (int j = 1; j < N; j++) 18 | { 19 | for (int k = j + 1; k <= N; k++) 20 | { 21 | int h = j & k; 22 | 23 | if ((h < K) && (max < h)) 24 | max = h; 25 | } 26 | } 27 | 28 | System.out.println(max); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Day 3 - Intro to Conditional Statements.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | int n = sc.nextInt(); 15 | if(n>1&&n<=100) 16 | { 17 | if(n%2!=0) 18 | { 19 | System.out.println("Weird"); 20 | } 21 | else 22 | { 23 | if(n>2&&n<5) 24 | { 25 | System.out.println("Not Weird"); 26 | } 27 | else if(n>6&&n<=20) 28 | { 29 | System.out.println("Weird"); 30 | } 31 | else if(n>20) 32 | { 33 | System.out.println("Not Weird"); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Day 4 - Class vs. Instance.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Person { 5 | private int age; 6 | 7 | public Person(int initialAge) 8 | { 9 | // Add some more code to run some checks on initialAge 10 | if (initialAge > 0) 11 | { 12 | age = initialAge; 13 | } else 14 | { 15 | System.out.println("Age is not valid, setting age to 0."); 16 | age = 0; 17 | } 18 | } 19 | 20 | public void amIOld() 21 | { 22 | // Write code determining if this person's age is old and print the correct statement: 23 | if (age < 13) System.out.println("You are young."); 24 | else if (age < 18) System.out.println("You are a teenager."); 25 | else System.out.println("You are old."); 26 | } 27 | 28 | public void yearPasses() 29 | { 30 | // Increment this person's age. 31 | age++; 32 | } 33 | public static void main(String[] args) { 34 | Scanner sc = new Scanner(System.in); 35 | int T = sc.nextInt(); 36 | for (int i = 0; i < T; i++) { 37 | int age = sc.nextInt(); 38 | Person p = new Person(age); 39 | p.amIOld(); 40 | for (int j = 0; j < 3; j++) { 41 | p.yearPasses(); 42 | } 43 | p.amIOld(); 44 | System.out.println(); 45 | } 46 | sc.close(); 47 | } 48 | } -------------------------------------------------------------------------------- /Day 5 - Loops.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner in = new Scanner(System.in); 14 | int N = in.nextInt(); 15 | in.close(); 16 | 17 | for (int i = 1; i < 11; i++) { 18 | System.out.println(N + " x " + i + " = " + N * i); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day 6 - Let's Review.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution 5 | { 6 | 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | sc.nextLine(); 12 | for(int i=0; i myMap = new HashMap(); 10 | 11 | for(int i = 0; i < n; i++){ 12 | String name = in.next(); 13 | int phone = in.nextInt(); 14 | // Write code here 15 | myMap.put(name, phone); 16 | } 17 | while(in.hasNext()){ 18 | String s = in.next(); 19 | // Write code here 20 | if (myMap.get(s)!=null) 21 | System.out.println(s + "=" + myMap.get(s) ); 22 | else 23 | System.out.println("Not found"); 24 | } 25 | in.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /Day 9 - Recursion 3.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | // Complete the factorial function below. 12 | static int factorial(int n) 13 | { 14 | if(n==1) 15 | { 16 | return 1; 17 | } 18 | return factorial(n - 1) * n; 19 | } 20 | 21 | private static final Scanner scanner = new Scanner(System.in); 22 | 23 | public static void main(String[] args) throws IOException { 24 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 25 | 26 | int n = scanner.nextInt(); 27 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 28 | 29 | int result = factorial(n); 30 | 31 | bufferedWriter.write(String.valueOf(result)); 32 | bufferedWriter.newLine(); 33 | 34 | bufferedWriter.close(); 35 | 36 | scanner.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2020, Chitturiarunkrishna 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hackerrank 30 Days Of Code JAVA Solutions 2 | 3 |

4 | 5 | 6 | 7 |
8 | Efficient solutions to HackerRank 30 Days Of Code JAVA problems 9 |

10 | 11 | 12 | 13 |
14 |

15 | 16 | A 30-day tutorial series for people with no programming experience and want to learn how to code. 17 | 18 | This repository consists of all the 30 Days Of Code JAVA Solutions as of 10th April 2020 19 | --------------------------------------------------------------------------------