Last active
July 9, 2021 15:21
-
-
Save zaidw21/5e35fc16ef9fc52959c5befb85bf64be to your computer and use it in GitHub Desktop.
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
public static int maxPresentations(List<Integer> scheduleStart, List<Integer> scheduleEnd) { | |
if (scheduleStart.size() != scheduleEnd.size()) { | |
return 0; | |
} | |
int size = scheduleStart.size(); | |
int[][] events = new int[2][size]; | |
for (int x = 0; x < size; x++) { | |
events[0][x] = scheduleStart.get(x); | |
events[1][x] = scheduleEnd.get(x); | |
} | |
Arrays.sort(events, (a, b) -> a[0] - b[0]); | |
PriorityQueue<Integer> queue = new PriorityQueue<>(); | |
int count = 0; | |
int index = 0; | |
for (int i = 1; i <= 100000; i++) { | |
while (!queue.isEmpty() && queue.peek() < i) | |
queue.poll(); | |
while (index < events.length && events[index][0] == i) | |
queue.offer(events[index++][1]); | |
if (!queue.isEmpty()) { | |
queue.poll(); | |
count++; | |
} | |
} | |
return count+1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set combos = new HashSet<>();
int l, r;
Collections.sort(stockProfit);
int size = stockProfit.size();
l = 0;
r = size - 1;
while (l < r) {
if (stockProfit.get(l) + stockProfit.get(r) == target)
combos.add(String.valueOf(stockProfit.get(l)) + String.valueOf(stockProfit.get(r)));
else if (stockProfit.get(l) + stockProfit.get(r) < target)
l++;
else
r--;
}
return combos.size();