diff --git a/Hackerrank/PyramidPattern.java b/Hackerrank/PyramidPattern.java new file mode 100644 index 00000000..7406b3c1 --- /dev/null +++ b/Hackerrank/PyramidPattern.java @@ -0,0 +1,23 @@ +package ProblemSolvingBasic; + +/*Right Pyramid*/ + +public class PyramidPattern { + public static void main(String[] args) { + System.out.println("Pyramid Pattern!"); + + int n = 5; + + for (int i = n; i > 0; i--) { + int space = i - 1; + for (int j = 0; j < n; j++) { + if (j < space) { + System.out.print(" "); + } else { + System.out.print("#"); + } + } + System.out.println(); + } + } +} \ No newline at end of file diff --git a/Hackerrank/UnexpectedDemand.java b/Hackerrank/UnexpectedDemand.java new file mode 100644 index 00000000..a5de60a8 --- /dev/null +++ b/Hackerrank/UnexpectedDemand.java @@ -0,0 +1,34 @@ +package ProblemSolvingBasic; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/*A widget manufacturer is facing unexpectedly high demand for its new product. +They would like to satisfy as many customers as possible. Given a number of widgets + available and a list of customer orders, what is the maximum number of orders the + manufacturer can fulfill in full?*/ + +public class UnexpectedDemand { + public static void main(String[] args) { + System.out.println("Unexpected Demand!"); + + List orders = Arrays.asList(5, 2, 4); + + Collections.sort(orders); + + int widgets = 3; + int counter = 0; + + for (Integer order : orders) { + if (order <= widgets) { + widgets -= order; + counter++; + } else { + break; + } + } + + System.out.println("Successful Filled Orders ---> " + counter); + } +} \ No newline at end of file