-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af8c296
commit 3a6797a
Showing
43 changed files
with
2,823 additions
and
598 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
30 Days of Code/Day 23 - BST Level-Order Traversal/Solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Author: Rodney Shaghoulian | ||
// Github: github.com/rshaghoulian | ||
// HackerRank: hackerrank.com/rshaghoulian | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class Node { | ||
Node left,right; | ||
int data; | ||
Node(int data) { | ||
this.data = data; | ||
left = right = null; | ||
} | ||
} | ||
|
||
class Solution { | ||
static void levelOrder(Node root){ | ||
Queue<Node> 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); | ||
} | ||
} | ||
} | ||
|
||
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 sc = new Scanner(System.in); | ||
int T = sc.nextInt(); | ||
Node root = null; | ||
while (T-- > 0) { | ||
int data = sc.nextInt(); | ||
root = insert(root, data); | ||
} | ||
levelOrder(root); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Author: Rodney Shaghoulian | ||
// Github: github.com/rshaghoulian | ||
// HackerRank: hackerrank.com/rshaghoulian | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class Node { | ||
int data; | ||
Node next; | ||
Node(int d) { | ||
data = d; | ||
next = null; | ||
} | ||
} | ||
|
||
class Solution { | ||
public static Node removeDuplicates(Node head) { | ||
if (head == null) { | ||
return null; | ||
} | ||
Node n = head; | ||
while (n.next != null) { | ||
if (n.data == n.next.data) { | ||
n.next = n.next.next; | ||
} else { | ||
n = n.next; | ||
} | ||
} | ||
return head; | ||
} | ||
|
||
public static Node insert(Node head,int data) { | ||
Node p = new Node(data); | ||
if (head == null) | ||
head = p; | ||
else if (head.next == null) | ||
head.next = p; | ||
else { | ||
Node start = head; | ||
while (start.next != null) | ||
start = start.next; | ||
start.next = p; | ||
} | ||
return head; | ||
} | ||
|
||
public static void display(Node head) { | ||
Node start = head; | ||
while (start != null) { | ||
System.out.print(start.data + " "); | ||
start = start.next; | ||
} | ||
} | ||
|
||
public static void main(String args[]) { | ||
Scanner sc = new Scanner(System.in); | ||
Node head = null; | ||
int T = sc.nextInt(); | ||
while (T-- > 0) { | ||
int ele = sc.nextInt(); | ||
head = insert(head, ele); | ||
} | ||
head = removeDuplicates(head); | ||
display(head); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
30 Days of Code/Day 25 - Running Time and Complexity/Solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Author: Rodney Shaghoulian | ||
// Github: github.com/rshaghoulian | ||
// HackerRank: hackerrank.com/rshaghoulian | ||
|
||
import java.util.Scanner; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
Scanner scan = new Scanner(System.in); | ||
int p = scan.nextInt(); | ||
for (int a0 = 0; a0 < p; a0++) { | ||
int n = scan.nextInt(); | ||
System.out.println(isPrime(n) ? "Prime" : "Not prime"); | ||
} | ||
scan.close(); | ||
} | ||
|
||
public static boolean isPrime (int n) { | ||
if (n < 2) { | ||
return false; | ||
} | ||
int sqrt = (int) Math.sqrt(n); | ||
for (int i = 2; i <= sqrt; i++) { | ||
if (n % i == 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Author: Rodney Shaghoulian | ||
// Github: github.com/rshaghoulian | ||
// HackerRank: hackerrank.com/rshaghoulian | ||
|
||
import java.util.Scanner; | ||
import java.time.LocalDate; | ||
|
||
public class Solution { | ||
public static void main(String[] args) { | ||
/* Read and save input as LocalDates */ | ||
Scanner scan = new Scanner(System.in); | ||
LocalDate returnDate = readDate(scan); | ||
LocalDate expectDate = readDate(scan); | ||
scan.close(); | ||
|
||
/* Calculate fine */ | ||
int fine; | ||
if (returnDate.isEqual(expectDate) || returnDate.isBefore(expectDate)) { | ||
fine = 0; | ||
} else if (returnDate.getMonth() == expectDate.getMonth() && returnDate.getYear() == expectDate.getYear()) { | ||
fine = 15 * (returnDate.getDayOfMonth() - expectDate.getDayOfMonth()); | ||
} else if (returnDate.getYear() == expectDate.getYear()) { | ||
fine = 500 * (returnDate.getMonthValue() - expectDate.getMonthValue()); | ||
} else { | ||
fine = 10000; | ||
} | ||
System.out.println(fine); | ||
} | ||
|
||
private static LocalDate readDate(Scanner scan) { | ||
int day = scan.nextInt(); | ||
int month = scan.nextInt(); | ||
int year = scan.nextInt(); | ||
return LocalDate.of(year, month, day); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Author: Rodney Shaghoulian | ||
// Github: github.com/rshaghoulian | ||
// HackerRank: hackerrank.com/rshaghoulian | ||
|
||
public class Solution { | ||
public static void main(String[] args) { | ||
System.out.println(5); | ||
|
||
System.out.println("4 3"); | ||
System.out.println("-1 0 1 2"); | ||
|
||
System.out.println("3 1"); | ||
System.out.println("-1 0 1"); | ||
|
||
System.out.println("5 4"); | ||
System.out.println("-1 0 1 2 3"); | ||
|
||
System.out.println("6 1"); | ||
System.out.println("-1 0 1 2 3 4"); | ||
|
||
System.out.println("7 6"); | ||
System.out.println("-1 0 1 2 3 4 5"); | ||
} | ||
} |
Oops, something went wrong.