Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackerank/solutions #1254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Hackerrank/PyramidPattern.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
34 changes: 34 additions & 0 deletions Hackerrank/UnexpectedDemand.java
Original file line number Diff line number Diff line change
@@ -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<Integer> 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);
}
}