Skip to content

Feature/delf mar1 #186

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

Open
wants to merge 5 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
22 changes: 22 additions & 0 deletions src/delf/hackerrank/GreedyFlorist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hackerrank;

import java.util.Arrays;

/**
* Greedy Florist
* https://www.hackerrank.com/challenges/greedy-florist/problem
*/
public class GreedyFlorist {
public static void main(String[] args) {
System.out.println(getMinimumCost(3, new int[]{1, 3, 5, 7, 9}));
}

static int getMinimumCost(int k, int[] c) {
Arrays.sort(c);
int answer = 0;
for (int i = c.length - 1; i >= 0; i--) {
answer += (((c.length - (i + 1)) / k) + 1) * c[i];
}
return answer;
}
}
48 changes: 48 additions & 0 deletions src/delf/hackerrank/IceCreamParlor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package hackerrank;

import java.util.*;

/**
* Hash Tables: Ice Cream Parlor
* https://www.hackerrank.com/challenges/ctci-ice-cream-parlor/problem
*/
public class IceCreamParlor {
public static void main(String[] args) {
whatFlavors(new int[]{2, 2, 4, 3}, 4);
}

static void whatFlavors(int[] cost, int money) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < cost.length; i++) {
if (cost[i] > money) {
continue;
}
if (map.containsKey(cost[i])) {
if (cost[i] * 2 == money) {
System.out.println((map.get(cost[i]) + 1) + " " + (i + 1));
return;
}
}
map.put(cost[i], i);
}

for (int c : map.keySet()) {
if (map.containsKey(money - c)) {
int one = map.get(c) + 1;
int another = map.get(money - c) + 1;
System.out.println(Math.min(one, another) + " " + Math.max(one, another));
return;
}
}

/*for (int i = 1; i < money; i++) {
int m = map.get(i);
if (map.containsKey(i) && map.containsKey(money - i)) {
int one = map.get(i) + 1;
int another = map.get(money - i) + 1;
System.out.println(Math.min(one, another) + " " + Math.max(one, another));
return;
}
}*/
}
}
33 changes: 33 additions & 0 deletions src/delf/programmers/skillcheck/SkillCheck0302.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package programmers.skillcheck;

import java.util.Arrays;

public class SkillCheck0302 {
public int[] solution(int n, int s) {
int div = s / n;
int rest = s % n;

if (div == 0) {
return new int[]{-1};
}

int[] answer = new int[n];
Arrays.fill(answer, div);

if (rest == 0) {
return answer;
}

int cursor = 0;
for (int i = 0; i < rest; i++, cursor %= n) {
answer[cursor++]++;
}
Arrays.sort(answer);
return answer;
}

public static void main(String[] args) {
System.out.println(Arrays.toString(new SkillCheck0302().solution(2, 9)));

}
}