From ff6167d56c31d4f50df5d61bebefb044b38b4d26 Mon Sep 17 00:00:00 2001 From: rshaghoulian <9rodney@gmail.com> Date: Tue, 21 Feb 2017 00:05:09 -0600 Subject: [PATCH] Added 17 solutions --- .../Arrays/Algorithmic Crush/Solution.java | 44 +++++++++++++ .../Arrays/Dynamic Array/Solution.java | 37 +++++++++++ .../Compare two linked lists/Solution.java | 29 +++++++++ .../Linked Lists/Delete a Node/Solution.java | 4 +- .../Solution.java | 38 +++++++++++ .../Linked Lists/Get Node Value/Solution.java | 33 ++++++++++ .../Solution.java | 2 - .../Solution.java | 47 ++++++++++++++ .../Solution.java | 55 ++++++++++++++++ .../Solution.java | 3 - .../Solution.java | 31 +++++++++ .../Reverse a linked list/Solution.java | 32 +++++++++ Data Structures/README.md | 34 +++++----- .../Stacks/Maximum Element/Solution.java | 42 ++++++++++++ .../Solution.java | 44 +++++++++++++ .../Solution.java | 65 +++++++++++++++++++ .../Tree - Inorder Traversal/Solution.java | 22 +++++++ .../Solution.java | 28 ++++++++ .../Tree - Postorder Traversal/Solution.java | 22 +++++++ .../Tree - Preorder Traversal/Solution.java | 22 +++++++ .../Trees/Tree - Top View/Solution.java | 32 +++++++++ .../Java Dequeue/Solution.java | 36 ++++------ .../Java Generics/Solution.java | 4 +- Java/Strings/Java String Tokens/Solution.java | 3 +- README.md | 36 +++++----- 25 files changed, 676 insertions(+), 69 deletions(-) create mode 100644 Data Structures/Arrays/Algorithmic Crush/Solution.java create mode 100644 Data Structures/Arrays/Dynamic Array/Solution.java create mode 100644 Data Structures/Linked Lists/Compare two linked lists/Solution.java create mode 100644 Data Structures/Linked Lists/Find Merge Point of Two Lists/Solution.java create mode 100644 Data Structures/Linked Lists/Get Node Value/Solution.java create mode 100644 Data Structures/Linked Lists/Inserting a Node Into a Sorted Doubly Linked List/Solution.java create mode 100644 Data Structures/Linked Lists/Merge two sorted linked lists/Solution.java create mode 100644 Data Structures/Linked Lists/Reverse a doubly linked list/Solution.java create mode 100644 Data Structures/Linked Lists/Reverse a linked list/Solution.java create mode 100644 Data Structures/Stacks/Maximum Element/Solution.java create mode 100644 Data Structures/Trees/Binary Search Tree - Insertion/Solution.java create mode 100644 Data Structures/Trees/Tree - Height of a Binary Tree/Solution.java create mode 100644 Data Structures/Trees/Tree - Inorder Traversal/Solution.java create mode 100644 Data Structures/Trees/Tree - Level Order Traversal/Solution.java create mode 100644 Data Structures/Trees/Tree - Postorder Traversal/Solution.java create mode 100644 Data Structures/Trees/Tree - Preorder Traversal/Solution.java create mode 100644 Data Structures/Trees/Tree - Top View/Solution.java diff --git a/Data Structures/Arrays/Algorithmic Crush/Solution.java b/Data Structures/Arrays/Algorithmic Crush/Solution.java new file mode 100644 index 0000000..2c737a0 --- /dev/null +++ b/Data Structures/Arrays/Algorithmic Crush/Solution.java @@ -0,0 +1,44 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +import java.util.Scanner; + +// Runtime: O(n + m) +// Space Complexity: O(n) +public class Solution { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int N = scan.nextInt(); + int M = scan.nextInt(); + + /* Save interval endpoint's "k" values in array */ + long [] array = new long[N + 1]; + for (int m = 0; m < M; m++) { + int a = scan.nextInt(); + int b = scan.nextInt(); + int k = scan.nextInt(); + array[a-1] += k; + array[b] -= k; + } + scan.close(); + + /* Find max value */ + long sum = 0; + long max = 0; + for (int i = 0; i < N; i++) { + sum += array[i]; + max = Math.max(max, sum); + } + + System.out.println(max); + } +} + +/* +For each of the "m" operations, we do not want to take O(n) time to process it. That's because our runtime will end up being O(nm). To get a O(n+m) runtime, we have to process each operation in O(1) time. To do so, we keep track of just the endpoints, which are just 2 numbers, instead of the O(n) numbers in between the endpoints. This is the main idea to decrease our runtime. + +For a value "k", we can mark its left endpoint "a" in the original array, along with its right endpoint "b" in the original array. To distinguish between "a" and "b" we can store "+k" for "a" and "-k" for "b". Now, we technically have stored all information that the "m" operations represent, into an array. Most importantly, we stored it in O(m) time. + +The next step is to actually find the maximum value based off of our unique representation of the data. We traverse our array from left to right. Whenever we reach a left endpoint "a" (which we represented with a positive number), we just add that to our sum. Whenever we reach a right endpoint "b" (which we represented with a negative number), we subtract that from our sum (well, technically we add a negative value). By doing so, the value "sum" represents the value that array[i] would have if we had applied all "m" operations to it. The maximum value of "sum" that we get while traversing the array is the value we return. If this algorithm is still unclear to you, try walking through HackerRank's Testcase 0 with the code above. +*/ diff --git a/Data Structures/Arrays/Dynamic Array/Solution.java b/Data Structures/Arrays/Dynamic Array/Solution.java new file mode 100644 index 0000000..966407f --- /dev/null +++ b/Data Structures/Arrays/Dynamic Array/Solution.java @@ -0,0 +1,37 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +import java.util.Scanner; +import java.util.ArrayList; + +public class Solution { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int N = scan.nextInt(); + int Q = scan.nextInt(); + int lastAns = 0; + + /* Create 2-D ArrayList */ + ArrayList> lists = new ArrayList<>(); + for (int i = 0; i < N; i++) { + lists.add(new ArrayList()); + } + + /* Perform Q Queries */ + for (int i = 0; i < Q; i++) { + int q = scan.nextInt(); + int x = scan.nextInt(); + int y = scan.nextInt(); + ArrayList seq = lists.get((x ^ lastAns) % N); + if (q == 1) { + seq.add(y); + } else if (q == 2) { + lastAns = seq.get(y % seq.size()); + System.out.println(lastAns); + } + } + + scan.close(); + } +} diff --git a/Data Structures/Linked Lists/Compare two linked lists/Solution.java b/Data Structures/Linked Lists/Compare two linked lists/Solution.java new file mode 100644 index 0000000..b5e2618 --- /dev/null +++ b/Data Structures/Linked Lists/Compare two linked lists/Solution.java @@ -0,0 +1,29 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Compare two linked lists A and B + Return 1 if they are identical and 0 if they are not. + Node is defined as + class Node { + int data; + Node next; + } +*/ + +// Runtime: O(n) +// Space Complexity: O(1) +int CompareLists(Node n1, Node n2) { + if (n1 == null && n2 == null) { + return 1; + } + while (n1 != null && n2 != null) { + if (n1.data != n2.data) { + return 0; + } + n1 = n1.next; + n2 = n2.next; + } + return (n1 == null && n2 == null) ? 1 : 0; +} diff --git a/Data Structures/Linked Lists/Delete a Node/Solution.java b/Data Structures/Linked Lists/Delete a Node/Solution.java index d187643..d9241dd 100644 --- a/Data Structures/Linked Lists/Delete a Node/Solution.java +++ b/Data Structures/Linked Lists/Delete a Node/Solution.java @@ -10,9 +10,7 @@ int data; Node next; } -*/ - // This is a "method-only" submission. - // You only need to complete this method. +*/ Node Delete(Node head, int position) { if (head == null) { diff --git a/Data Structures/Linked Lists/Find Merge Point of Two Lists/Solution.java b/Data Structures/Linked Lists/Find Merge Point of Two Lists/Solution.java new file mode 100644 index 0000000..49e0063 --- /dev/null +++ b/Data Structures/Linked Lists/Find Merge Point of Two Lists/Solution.java @@ -0,0 +1,38 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Node is defined as + class Node { + int data; + Node next; + } +*/ + +// Create a pointer that iterates through a list. When it's at the end +// of the list, have it jump to the beginning of the other list. Create +// 2 of these pointers, pointing to 2 different list heads. The pointers +// will collide at the merge point after 1 or 2 passes. +// +// Runtime: O(n) +// Space Complexity: O(1) +int FindMergeNode(Node headA, Node headB) { + Node currA = headA; + Node currB = headB; + + while (currA != currB) { + if (currA.next == null) { + currA = headB; + } else { + currA = currA.next; + } + + if (currB.next == null) { + currB = headA; + } else { + currB = currB.next; + } + } + return currA.data; +} \ No newline at end of file diff --git a/Data Structures/Linked Lists/Get Node Value/Solution.java b/Data Structures/Linked Lists/Get Node Value/Solution.java new file mode 100644 index 0000000..d74ae71 --- /dev/null +++ b/Data Structures/Linked Lists/Get Node Value/Solution.java @@ -0,0 +1,33 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Get Nth element from the end in a linked list of integers + Number of elements in the list will always be greater than N. + Node is defined as + class Node { + int data; + Node next; + } +*/ + +// Runtime: O(n) +// Space Complexity: O(1) +int GetNode(Node head, int k) { + Node curr = head; + Node runner = head; + + /* Move runner into the list by k elements */ + for (int i = 0; i < k; i++) { + runner = runner.next; + } + + /* Move both pointers */ + while (runner.next != null) { + curr = curr.next; + runner = runner.next; + } + + return curr.data; +} diff --git a/Data Structures/Linked Lists/Insert a node at the head of a linked list/Solution.java b/Data Structures/Linked Lists/Insert a node at the head of a linked list/Solution.java index b80073b..4b73f31 100644 --- a/Data Structures/Linked Lists/Insert a node at the head of a linked list/Solution.java +++ b/Data Structures/Linked Lists/Insert a node at the head of a linked list/Solution.java @@ -11,8 +11,6 @@ Node next; } */ -// This is a "method-only" submission. -// You only need to complete this method. Node Insert(Node head, int x) { Node n = new Node(); diff --git a/Data Structures/Linked Lists/Inserting a Node Into a Sorted Doubly Linked List/Solution.java b/Data Structures/Linked Lists/Inserting a Node Into a Sorted Doubly Linked List/Solution.java new file mode 100644 index 0000000..8439929 --- /dev/null +++ b/Data Structures/Linked Lists/Inserting a Node Into a Sorted Doubly Linked List/Solution.java @@ -0,0 +1,47 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Node is defined as + class Node { + int data; + Node next; + Node prev; + } +*/ + +// Runtime: O(n) +// Space Complexity: O(1) +Node SortedInsert(Node head, int data) { + /* Create Node to insert */ + Node newNode = new Node(); + newNode.data = data; + + if (head == null) { // insert in empty list + return newNode; + } else if (data < head.data) { // insert in front of list + newNode.next = head; + head.prev = newNode; + return newNode; + } else { + /* Walk list with 2 pointers */ + Node n1 = null; + Node n2 = head; + while (n2 != null && n2.data < data) { + n1 = n2; + n2 = n2.next; + } + + if (n2 == null) { // insert at end of list + n1.next = newNode; + newNode.prev = n1; + } else { // insert in empty list + n1.next = newNode; + n2.prev = newNode; + newNode.prev = n1; + newNode.next = n2; + } + return head; + } +} diff --git a/Data Structures/Linked Lists/Merge two sorted linked lists/Solution.java b/Data Structures/Linked Lists/Merge two sorted linked lists/Solution.java new file mode 100644 index 0000000..ab33b69 --- /dev/null +++ b/Data Structures/Linked Lists/Merge two sorted linked lists/Solution.java @@ -0,0 +1,55 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Merge two linked lists + head pointer input could be NULL as well for empty list + Node is defined as + class Node { + int data; + Node next; + } +*/ + +// Runtime: O(n) +// Space Complexity: O(1) +Node MergeLists(Node currA, Node currB) { + if (currA == null) { + return currB; + } else if (currB == null) { + return currA; + } + + /* Find new head pointer */ + Node head = null; + if (currA.data < currB.data) { + head = currA; + currA = currA.next; + } else { + head = currB; + currB = currB.next; + } + + /* Build rest of list */ + Node n = head; + while (currA != null && currB != null) { + if (currA.data < currB.data) { + n.next = currA; + currA = currA.next; + } else { + n.next = currB; + currB = currB.next; + } + n = n.next; + } + + /* Attach the remaining elements */ + if (currA == null) { + n.next = currB; + } else { + n.next = currA; + } + + return head; +} diff --git a/Data Structures/Linked Lists/Print the Elements of a Linked List/Solution.java b/Data Structures/Linked Lists/Print the Elements of a Linked List/Solution.java index ef01264..99017e6 100644 --- a/Data Structures/Linked Lists/Print the Elements of a Linked List/Solution.java +++ b/Data Structures/Linked Lists/Print the Elements of a Linked List/Solution.java @@ -12,9 +12,6 @@ } */ -// This is a "method-only" submission. -// You only need to complete this method. - void Print(Node head) { Node n = head; while (n != null) { diff --git a/Data Structures/Linked Lists/Reverse a doubly linked list/Solution.java b/Data Structures/Linked Lists/Reverse a doubly linked list/Solution.java new file mode 100644 index 0000000..0ce7781 --- /dev/null +++ b/Data Structures/Linked Lists/Reverse a doubly linked list/Solution.java @@ -0,0 +1,31 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Node is defined as + class Node { + int data; + Node next; + Node prev; + } +*/ + +// Runtime: O(n) +// Space Complexity: O(1) +Node Reverse(Node head) { + if (head == null && head.next == null) { + return head; + } + Node prev = null; + Node curr = head; + Node next = null; + while (curr != null) { + next = curr.next; + curr.next = prev; + curr.prev = next; + prev = curr; + curr = next; + } + return prev; +} diff --git a/Data Structures/Linked Lists/Reverse a linked list/Solution.java b/Data Structures/Linked Lists/Reverse a linked list/Solution.java new file mode 100644 index 0000000..d73a79e --- /dev/null +++ b/Data Structures/Linked Lists/Reverse a linked list/Solution.java @@ -0,0 +1,32 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + Reverse a linked list and return pointer to the head + The input list will have at least one element + Node is defined as + class Node { + int data; + Node next; + } +*/ + +// Iterative Solution using 3 pointers +// Runtime: O(n) +// Space Complexity: O(1) +Node Reverse(Node head) { + if (head == null && head.next == null) { + return head; + } + Node prev = null; + Node curr = head; + Node next = null; + while (curr != null) { + next = curr.next; + curr.next = prev; // changes arrow direction + prev = curr; + curr = next; + } + return prev; +} diff --git a/Data Structures/README.md b/Data Structures/README.md index 2716966..915d447 100644 --- a/Data Structures/README.md +++ b/Data Structures/README.md @@ -4,32 +4,32 @@ |:---------------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | Data Structures | Arrays | [Arrays - DS](https://www.hackerrank.com/challenges/arrays-ds) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Arrays%20-%20DS/Solution.java) | | Data Structures | Arrays | [2D Array - DS](https://www.hackerrank.com/challenges/2d-array) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/2D%20Array%20-%20DS/Solution.java) | -| Data Structures | Arrays | [Dynamic Array](https://www.hackerrank.com/challenges/dynamic-array) | Easy | Coming Soon! | +| Data Structures | Arrays | [Dynamic Array](https://www.hackerrank.com/challenges/dynamic-array) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Dynamic%20Array/Solution.java) | | Data Structures | Arrays | [Left Rotation](https://www.hackerrank.com/challenges/array-left-rotation) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Left%20Rotation/Solution.java) | | Data Structures | Arrays | [Sparse Arrays](https://www.hackerrank.com/challenges/sparse-arrays) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Sparse%20Arrays/Solution.java) | -| Data Structures | Arrays | [Algorithmic Crush](https://www.hackerrank.com/challenges/crush) | Hard | Coming Soon! | +| Data Structures | Arrays | [Algorithmic Crush](https://www.hackerrank.com/challenges/crush) | Hard | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Algorithmic%20Crush/Solution.java) | | Data Structures | Linked List | [Print the Elements of a Linked List](https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Print%20the%20Elements%20of%20a%20Linked%20List/Solution.java) | | Data Structures | Linked List | [Insert a Node at the Tail of a Linked List](https://www.hackerrank.com/challenges/insert-a-node-at-the-tail-of-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Insert%20a%20Node%20at%20the%20Tail%20of%20a%20Linked%20List/Solution.java) | | Data Structures | Linked List | [Insert a node at the head of a linked list](https://www.hackerrank.com/challenges/insert-a-node-at-the-head-of-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Insert%20a%20node%20at%20the%20head%20of%20a%20linked%20list/Solution.java) | | Data Structures | Linked List | [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) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Insert%20a%20node%20at%20a%20specific%20position%20in%20a%20linked%20list/Solution.java) | | Data Structures | Linked List | [Delete a Node](https://www.hackerrank.com/challenges/delete-a-node-from-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Delete%20a%20Node/Solution.java) | | Data Structures | Linked List | [Print in Reverse](https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list-in-reverse) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Print%20in%20Reverse/Solution.java) | -| Data Structures | Linked List | [Reverse a linked list](https://www.hackerrank.com/challenges/reverse-a-linked-list) | Easy | Coming Soon! | -| Data Structures | Linked List | [Compare two linked lists](https://www.hackerrank.com/challenges/compare-two-linked-lists) | Easy | Coming Soon! | -| Data Structures | Linked List | [Merge two sorted linked lists](https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists) | Easy | Coming Soon! | -| Data Structures | Linked List | [Get Node Value](https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail) | Easy | Coming Soon! | +| Data Structures | Linked List | [Reverse a linked list](https://www.hackerrank.com/challenges/reverse-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Reverse%20a%20linked%20list/Solution.java) | +| Data Structures | Linked List | [Compare two linked lists](https://www.hackerrank.com/challenges/compare-two-linked-lists) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Compare%20two%20linked%20lists/Solution.java) | +| Data Structures | Linked List | [Merge two sorted linked lists](https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Merge%20two%20sorted%20linked%20lists/Solution.java) | +| Data Structures | Linked List | [Get Node Value](https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Get%20Node%20Value/Solution.java) | | Data Structures | Linked List | [Delete duplicate-value nodes from a sorted linked list](https://www.hackerrank.com/challenges/delete-duplicate-value-nodes-from-a-sorted-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Delete%20duplicate-value%20nodes%20from%20a%20sorted%20linked%20list/Solution.java) | | Data Structures | Linked List | [Cycle Detection](https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Cycle%20Detection/Solution.java) | -| Data Structures | Linked List | [Find Merge Point of Two Lists](https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists) | Easy | Coming Soon! | -| Data Structures | Linked List | [Inserting a Node Into a Sorted Doubly Linked List](https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-linked-list) | Easy | Coming Soon! | -| Data Structures | Linked List | [Reverse a doubly linked list](https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Preorder Traversal](https://www.hackerrank.com/challenges/tree-preorder-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Postorder Traversal](https://www.hackerrank.com/challenges/tree-postorder-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Inorder Traversal](https://www.hackerrank.com/challenges/tree-inorder-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Height of a Binary Tree](https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Top View](https://www.hackerrank.com/challenges/tree-top-view) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Level Order Traversal](https://www.hackerrank.com/challenges/tree-level-order-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Binary Search Tree: Insertion](https://www.hackerrank.com/challenges/binary-search-tree-insertion) | Easy | Coming Soon! | +| Data Structures | Linked List | [Find Merge Point of Two Lists](https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Find%20Merge%20Point%20of%20Two%20Lists/Solution.java) | +| Data Structures | Linked List | [Inserting a Node Into a Sorted Doubly Linked List](https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Inserting%20a%20Node%20Into%20a%20Sorted%20Doubly%20Linked%20List/Solution.java) | +| Data Structures | Linked List | [Reverse a doubly linked list](https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Reverse%20a%20doubly%20linked%20list/Solution.java) | +| Data Structures | Trees | [Tree: Preorder Traversal](https://www.hackerrank.com/challenges/tree-preorder-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Preorder%20Traversal/Solution.java) | +| Data Structures | Trees | [Tree: Postorder Traversal](https://www.hackerrank.com/challenges/tree-postorder-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Postorder%20Traversal/Solution.java) | +| Data Structures | Trees | [Tree: Inorder Traversal](https://www.hackerrank.com/challenges/tree-inorder-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Inorder%20Traversal/Solution.java) | +| Data Structures | Trees | [Tree: Height of a Binary Tree](https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Height%20of%20a%20Binary%20Tree/Solution.java) | +| Data Structures | Trees | [Tree: Top View](https://www.hackerrank.com/challenges/tree-top-view) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Top%20View/Solution.java) | +| Data Structures | Trees | [Tree: Level Order Traversal](https://www.hackerrank.com/challenges/tree-level-order-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Level%20Order%20Traversal/Solution.java) | +| Data Structures | Trees | [Binary Search Tree: Insertion](https://www.hackerrank.com/challenges/binary-search-tree-insertion) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Binary%20Search%20Tree%20-%20Insertion/Solution.java) | | Data Structures | Trees | [Tree: Huffman Decoding](https://www.hackerrank.com/challenges/tree-huffman-decoding) | Medium | Coming Soon! | | Data Structures | Trees | [Binary Search Tree: Lowest Common Ancestor](https://www.hackerrank.com/challenges/binary-search-tree-lowest-common-ancestor) | Easy | Coming Soon! | | Data Structures | Trees | [Swap Nodes [Algo]](https://www.hackerrank.com/challenges/swap-nodes-algo) | Medium | Coming Soon! | @@ -39,7 +39,7 @@ | Data Structures | Balanced Trees | [Self Balancing Tree](https://www.hackerrank.com/challenges/self-balancing-tree) | Medium | Coming Soon! | | Data Structures | Balanced Trees | [Array and simple queries](https://www.hackerrank.com/challenges/array-and-simple-queries) | Hard | Coming Soon! | | Data Structures | Balanced Trees | [Median Updates](https://www.hackerrank.com/challenges/median) | Hard | Coming Soon! | -| Data Structures | Stacks | [Maximum Element](https://www.hackerrank.com/challenges/maximum-element) | Easy | Coming Soon! | +| Data Structures | Stacks | [Maximum Element](https://www.hackerrank.com/challenges/maximum-element) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Stacks/Maximum%20Element/Solution.java) | | Data Structures | Stacks | [Balanced Brackets](https://www.hackerrank.com/challenges/balanced-brackets) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Stacks/Balanced%20Brackets/Solution.java) | | Data Structures | Stacks | [Largest Rectangle](https://www.hackerrank.com/challenges/largest-rectangle) | Hard | Coming Soon! | | Data Structures | Stacks | [Simple Text Editor](https://www.hackerrank.com/challenges/simple-text-editor) | Medium | Coming Soon! | diff --git a/Data Structures/Stacks/Maximum Element/Solution.java b/Data Structures/Stacks/Maximum Element/Solution.java new file mode 100644 index 0000000..b9896e7 --- /dev/null +++ b/Data Structures/Stacks/Maximum Element/Solution.java @@ -0,0 +1,42 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +import java.util.Scanner; +import java.util.Stack; + +// All 3 queries (1:push, 2:delete, 3:print max) are all O(1) runtime +public class Solution { + public static void main(String[] args) { + Stack stack = new Stack(); + Stack maxStack = new Stack(); // keeps track of maximums + + Scanner scan = new Scanner(System.in); + int N = scan.nextInt(); + + for (int i = 0; i < N; i++) { + int query = scan.nextInt(); + switch (query) { + case 1: + int x = scan.nextInt(); + stack.push(x); + if (maxStack.isEmpty() || x >= maxStack.peek()) { + maxStack.push(x); + } + break; + case 2: + int poppedValue = stack.pop(); + if (poppedValue == maxStack.peek()) { + maxStack.pop(); + } + break; + case 3: + System.out.println(maxStack.peek()); + break; + default: + break; + } + } + scan.close(); + } +} diff --git a/Data Structures/Trees/Binary Search Tree - Insertion/Solution.java b/Data Structures/Trees/Binary Search Tree - Insertion/Solution.java new file mode 100644 index 0000000..f9e20a8 --- /dev/null +++ b/Data Structures/Trees/Binary Search Tree - Insertion/Solution.java @@ -0,0 +1,44 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* Node is defined as : + class Node { + int data; + Node left; + Node right; + } +*/ + +// Runtime: O(log n) on a balanced tree. +// Space Complexity: O(1) +static Node Insert(Node root, int value) { + /* Create new Node */ + Node newNode = new Node(); + newNode.data = value; + + /* Special case: empty tree */ + if (root == null) { + return newNode; + } + + /* Iteratively walk tree and insert new Node */ + Node curr = root; + while (true) { + if (value <= curr.data) { + if (curr.left == null) { + curr.left = newNode; + return root; + } else { + curr = curr.left; + } + } else { + if (curr.right == null) { + curr.right = newNode; + return root; + } else { + curr = curr.right; + } + } + } +} diff --git a/Data Structures/Trees/Tree - Height of a Binary Tree/Solution.java b/Data Structures/Trees/Tree - Height of a Binary Tree/Solution.java new file mode 100644 index 0000000..4feeb54 --- /dev/null +++ b/Data Structures/Trees/Tree - Height of a Binary Tree/Solution.java @@ -0,0 +1,65 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +import java.util.*; +import java.io.*; +class Node { + Node left; + Node right; + int data; + + Node(int data) { + this.data = data; + left = null; + right = null; + } +} + +class Solution { + /* + class Node + int data; + Node left; + Node right; + */ + + /* We define a 1-Node tree to have height of 0 */ + static int height(Node root) { + if (root == null) { + return -1; + } else { + return 1 + Math.max(height(root.left), height(root.right)); + } + } + + public static Node insert(Node root, int data) { + if(root == null){ + return new Node(data); + } + else { + Node cur; + if(data <= root.data){ + cur = insert(root.left, data); + root.left = cur; + } + else{ + cur = insert(root.right, data); + root.right = cur; + } + return root; + } + } + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int t = scan.nextInt(); + Node root = null; + while(t-- > 0){ + int data = scan.nextInt(); + root = insert(root, data); + } + scan.close(); + int height = height(root); + System.out.println(height); + } +} diff --git a/Data Structures/Trees/Tree - Inorder Traversal/Solution.java b/Data Structures/Trees/Tree - Inorder Traversal/Solution.java new file mode 100644 index 0000000..ab7946f --- /dev/null +++ b/Data Structures/Trees/Tree - Inorder Traversal/Solution.java @@ -0,0 +1,22 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* you only have to complete the function given below. +Node is defined as + +class Node { + int data; + Node left; + Node right; +} + +*/ + +void inOrder(Node root) { + if (root != null) { + inOrder(root.left); + System.out.print(root.data + " "); + inOrder(root.right); + } +} diff --git a/Data Structures/Trees/Tree - Level Order Traversal/Solution.java b/Data Structures/Trees/Tree - Level Order Traversal/Solution.java new file mode 100644 index 0000000..8bd5882 --- /dev/null +++ b/Data Structures/Trees/Tree - Level Order Traversal/Solution.java @@ -0,0 +1,28 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + class Node { + int data; + Node left; + Node right; + } +*/ + +void LevelOrder(Node root) { + Queue queue = new LinkedList<>(); + if (root != null) { + queue.add(root); + } + while ( ! queue.isEmpty()) { + Node n = queue.remove(); + System.out.print(n.data + " "); + if (n.left != null) { + queue.add(n.left); + } + if (n.right != null) { + queue.add(n.right); + } + } +} diff --git a/Data Structures/Trees/Tree - Postorder Traversal/Solution.java b/Data Structures/Trees/Tree - Postorder Traversal/Solution.java new file mode 100644 index 0000000..d106021 --- /dev/null +++ b/Data Structures/Trees/Tree - Postorder Traversal/Solution.java @@ -0,0 +1,22 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* you only have to complete the function given below. +Node is defined as + +class Node { + int data; + Node left; + Node right; +} + +*/ + +void postOrder(Node root) { + if (root != null) { + postOrder(root.left); + postOrder(root.right); + System.out.print(root.data + " "); + } +} diff --git a/Data Structures/Trees/Tree - Preorder Traversal/Solution.java b/Data Structures/Trees/Tree - Preorder Traversal/Solution.java new file mode 100644 index 0000000..3bb1d21 --- /dev/null +++ b/Data Structures/Trees/Tree - Preorder Traversal/Solution.java @@ -0,0 +1,22 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* you only have to complete the function given below. +Node is defined as + +class Node { + int data; + Node left; + Node right; +} + +*/ + +void preOrder(Node root) { + if (root != null) { + System.out.print(root.data + " "); + preOrder(root.left); + preOrder(root.right); + } +} diff --git a/Data Structures/Trees/Tree - Top View/Solution.java b/Data Structures/Trees/Tree - Top View/Solution.java new file mode 100644 index 0000000..a638ad0 --- /dev/null +++ b/Data Structures/Trees/Tree - Top View/Solution.java @@ -0,0 +1,32 @@ +// Author: Rodney Shaghoulian +// Github: github.com/rshaghoulian +// HackerRank: hackerrank.com/rshaghoulian + +/* + class Node + int data; + Node left; + Node right; +*/ + +void top_view(Node root) { + if (root != null) { + printLeft(root.left); + System.out.print(root.data + " "); + printRight(root.right); + } +} + +void printLeft(Node n) { + if (n != null) { + printLeft(n.left); + System.out.print(n.data + " "); + } +} + +void printRight(Node n) { + if (n != null) { + System.out.print(n.data + " "); + printRight(n.right); + } +} diff --git a/Java/Data Structures/Java Dequeue/Solution.java b/Java/Data Structures/Java Dequeue/Solution.java index e10ebd3..0c44235 100644 --- a/Java/Data Structures/Java Dequeue/Solution.java +++ b/Java/Data Structures/Java Dequeue/Solution.java @@ -11,33 +11,23 @@ import java.util.HashMap; // O(n) space complexity public class test { public static void main(String[] args) { - /* Create our data structures */ - Deque deque = new ArrayDeque<>(); HashMap map = new HashMap<>(); + Deque deque = new ArrayDeque<>(); - /* Save first m entries */ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); - int m = scan.nextInt(); - for (int i = 0; i < m; i++) { - int num = scan.nextInt(); - deque.add(num); - if (map.containsKey(num)) { - map.put(num, map.get(num) + 1); - } else { - map.put(num, 1); - } - } - - /* Loop through remaining n-m entries */ + int m = scan.nextInt(); int max = map.size(); - for (int i = m; i < n; i++) { - /* Remove old value */ - int old = deque.remove(); - if (map.get(old) == 1) { - map.remove(old); - } else { - map.put(old, map.get(old) - 1); + + for (int i = 0; i < n; i++) { + /* Remove old value (if necessary) */ + if (i >= m) { + int old = deque.remove(); + if (map.get(old) == 1) { + map.remove(old); + } else { + map.put(old, map.get(old) - 1); + } } /* Add new value */ int num = scan.nextInt(); @@ -50,6 +40,8 @@ public class test { max = Math.max(max, map.size()); } + + scan.close(); System.out.println(max); } } diff --git a/Java/Data Structures/Java Generics/Solution.java b/Java/Data Structures/Java Generics/Solution.java index e862a1d..e70ade9 100644 --- a/Java/Data Structures/Java Generics/Solution.java +++ b/Java/Data Structures/Java Generics/Solution.java @@ -5,8 +5,8 @@ import java.io.IOException; import java.lang.reflect.Method; -class Printer { - void printArray(T[] array) { +class Printer { + public void printArray(T[] array) { for (T item : array) { System.out.println(item); } diff --git a/Java/Strings/Java String Tokens/Solution.java b/Java/Strings/Java String Tokens/Solution.java index fcef4ed..abf8bf9 100644 --- a/Java/Strings/Java String Tokens/Solution.java +++ b/Java/Strings/Java String Tokens/Solution.java @@ -5,14 +5,13 @@ import java.util.Scanner; public class Solution { - public static void main(String[] args) { /* Read input */ Scanner scan = new Scanner(System.in); String s = scan.nextLine(); scan.close(); - s = s.trim(); // needed to pass test cases + s = s.trim(); // so that .split() works properly /* Check special cases */ if (s.length() == 0) { diff --git a/README.md b/README.md index 263f87b..b06e814 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # HackerRank-solutions -My Java solutions to [HackerRank](https://www.hackerrank.com/) challenges +Efficient Java solutions to [HackerRank](https://www.hackerrank.com/) problems ## Java @@ -177,32 +177,32 @@ My Java solutions to [HackerRank](https://www.hackerrank.com/) challenges |:---------------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | Data Structures | Arrays | [Arrays - DS](https://www.hackerrank.com/challenges/arrays-ds) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Arrays%20-%20DS/Solution.java) | | Data Structures | Arrays | [2D Array - DS](https://www.hackerrank.com/challenges/2d-array) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/2D%20Array%20-%20DS/Solution.java) | -| Data Structures | Arrays | [Dynamic Array](https://www.hackerrank.com/challenges/dynamic-array) | Easy | Coming Soon! | +| Data Structures | Arrays | [Dynamic Array](https://www.hackerrank.com/challenges/dynamic-array) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Dynamic%20Array/Solution.java) | | Data Structures | Arrays | [Left Rotation](https://www.hackerrank.com/challenges/array-left-rotation) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Left%20Rotation/Solution.java) | | Data Structures | Arrays | [Sparse Arrays](https://www.hackerrank.com/challenges/sparse-arrays) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Sparse%20Arrays/Solution.java) | -| Data Structures | Arrays | [Algorithmic Crush](https://www.hackerrank.com/challenges/crush) | Hard | Coming Soon! | +| Data Structures | Arrays | [Algorithmic Crush](https://www.hackerrank.com/challenges/crush) | Hard | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Arrays/Algorithmic%20Crush/Solution.java) | | Data Structures | Linked List | [Print the Elements of a Linked List](https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Print%20the%20Elements%20of%20a%20Linked%20List/Solution.java) | | Data Structures | Linked List | [Insert a Node at the Tail of a Linked List](https://www.hackerrank.com/challenges/insert-a-node-at-the-tail-of-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Insert%20a%20Node%20at%20the%20Tail%20of%20a%20Linked%20List/Solution.java) | | Data Structures | Linked List | [Insert a node at the head of a linked list](https://www.hackerrank.com/challenges/insert-a-node-at-the-head-of-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Insert%20a%20node%20at%20the%20head%20of%20a%20linked%20list/Solution.java) | | Data Structures | Linked List | [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) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Insert%20a%20node%20at%20a%20specific%20position%20in%20a%20linked%20list/Solution.java) | | Data Structures | Linked List | [Delete a Node](https://www.hackerrank.com/challenges/delete-a-node-from-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Delete%20a%20Node/Solution.java) | | Data Structures | Linked List | [Print in Reverse](https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list-in-reverse) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Print%20in%20Reverse/Solution.java) | -| Data Structures | Linked List | [Reverse a linked list](https://www.hackerrank.com/challenges/reverse-a-linked-list) | Easy | Coming Soon! | -| Data Structures | Linked List | [Compare two linked lists](https://www.hackerrank.com/challenges/compare-two-linked-lists) | Easy | Coming Soon! | -| Data Structures | Linked List | [Merge two sorted linked lists](https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists) | Easy | Coming Soon! | -| Data Structures | Linked List | [Get Node Value](https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail) | Easy | Coming Soon! | +| Data Structures | Linked List | [Reverse a linked list](https://www.hackerrank.com/challenges/reverse-a-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Reverse%20a%20linked%20list/Solution.java) | +| Data Structures | Linked List | [Compare two linked lists](https://www.hackerrank.com/challenges/compare-two-linked-lists) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Compare%20two%20linked%20lists/Solution.java) | +| Data Structures | Linked List | [Merge two sorted linked lists](https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Merge%20two%20sorted%20linked%20lists/Solution.java) | +| Data Structures | Linked List | [Get Node Value](https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Get%20Node%20Value/Solution.java) | | Data Structures | Linked List | [Delete duplicate-value nodes from a sorted linked list](https://www.hackerrank.com/challenges/delete-duplicate-value-nodes-from-a-sorted-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Delete%20duplicate-value%20nodes%20from%20a%20sorted%20linked%20list/Solution.java) | | Data Structures | Linked List | [Cycle Detection](https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Cycle%20Detection/Solution.java) | -| Data Structures | Linked List | [Find Merge Point of Two Lists](https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists) | Easy | Coming Soon! | -| Data Structures | Linked List | [Inserting a Node Into a Sorted Doubly Linked List](https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-linked-list) | Easy | Coming Soon! | -| Data Structures | Linked List | [Reverse a doubly linked list](https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Preorder Traversal](https://www.hackerrank.com/challenges/tree-preorder-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Postorder Traversal](https://www.hackerrank.com/challenges/tree-postorder-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Inorder Traversal](https://www.hackerrank.com/challenges/tree-inorder-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Height of a Binary Tree](https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Top View](https://www.hackerrank.com/challenges/tree-top-view) | Easy | Coming Soon! | -| Data Structures | Trees | [Tree: Level Order Traversal](https://www.hackerrank.com/challenges/tree-level-order-traversal) | Easy | Coming Soon! | -| Data Structures | Trees | [Binary Search Tree: Insertion](https://www.hackerrank.com/challenges/binary-search-tree-insertion) | Easy | Coming Soon! | +| Data Structures | Linked List | [Find Merge Point of Two Lists](https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Find%20Merge%20Point%20of%20Two%20Lists/Solution.java) | +| Data Structures | Linked List | [Inserting a Node Into a Sorted Doubly Linked List](https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Inserting%20a%20Node%20Into%20a%20Sorted%20Doubly%20Linked%20List/Solution.java) | +| Data Structures | Linked List | [Reverse a doubly linked list](https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Linked%20Lists/Reverse%20a%20doubly%20linked%20list/Solution.java) | +| Data Structures | Trees | [Tree: Preorder Traversal](https://www.hackerrank.com/challenges/tree-preorder-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Preorder%20Traversal/Solution.java) | +| Data Structures | Trees | [Tree: Postorder Traversal](https://www.hackerrank.com/challenges/tree-postorder-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Postorder%20Traversal/Solution.java) | +| Data Structures | Trees | [Tree: Inorder Traversal](https://www.hackerrank.com/challenges/tree-inorder-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Inorder%20Traversal/Solution.java) | +| Data Structures | Trees | [Tree: Height of a Binary Tree](https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Height%20of%20a%20Binary%20Tree/Solution.java) | +| Data Structures | Trees | [Tree: Top View](https://www.hackerrank.com/challenges/tree-top-view) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Top%20View/Solution.java) | +| Data Structures | Trees | [Tree: Level Order Traversal](https://www.hackerrank.com/challenges/tree-level-order-traversal) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Tree%20-%20Level%20Order%20Traversal/Solution.java) | +| Data Structures | Trees | [Binary Search Tree: Insertion](https://www.hackerrank.com/challenges/binary-search-tree-insertion) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trees/Binary%20Search%20Tree%20-%20Insertion/Solution.java) | | Data Structures | Trees | [Tree: Huffman Decoding](https://www.hackerrank.com/challenges/tree-huffman-decoding) | Medium | Coming Soon! | | Data Structures | Trees | [Binary Search Tree: Lowest Common Ancestor](https://www.hackerrank.com/challenges/binary-search-tree-lowest-common-ancestor) | Easy | Coming Soon! | | Data Structures | Trees | [Swap Nodes [Algo]](https://www.hackerrank.com/challenges/swap-nodes-algo) | Medium | Coming Soon! | @@ -212,7 +212,7 @@ My Java solutions to [HackerRank](https://www.hackerrank.com/) challenges | Data Structures | Balanced Trees | [Self Balancing Tree](https://www.hackerrank.com/challenges/self-balancing-tree) | Medium | Coming Soon! | | Data Structures | Balanced Trees | [Array and simple queries](https://www.hackerrank.com/challenges/array-and-simple-queries) | Hard | Coming Soon! | | Data Structures | Balanced Trees | [Median Updates](https://www.hackerrank.com/challenges/median) | Hard | Coming Soon! | -| Data Structures | Stacks | [Maximum Element](https://www.hackerrank.com/challenges/maximum-element) | Easy | Coming Soon! | +| Data Structures | Stacks | [Maximum Element](https://www.hackerrank.com/challenges/maximum-element) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Stacks/Maximum%20Element/Solution.java) | | Data Structures | Stacks | [Balanced Brackets](https://www.hackerrank.com/challenges/balanced-brackets) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Stacks/Balanced%20Brackets/Solution.java) | | Data Structures | Stacks | [Largest Rectangle](https://www.hackerrank.com/challenges/largest-rectangle) | Hard | Coming Soon! | | Data Structures | Stacks | [Simple Text Editor](https://www.hackerrank.com/challenges/simple-text-editor) | Medium | Coming Soon! |