Skip to content

Instantly share code, notes, and snippets.

@zaidw21
Last active July 9, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaidw21/5e35fc16ef9fc52959c5befb85bf64be to your computer and use it in GitHub Desktop.
Save zaidw21/5e35fc16ef9fc52959c5befb85bf64be to your computer and use it in GitHub Desktop.
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;
}
@zaidw21
Copy link
Author

zaidw21 commented Jul 9, 2021

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment