-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_35.java
More file actions
66 lines (59 loc) · 1.7 KB
/
Copy pathDay_35.java
File metadata and controls
66 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Job Sequencing Problem
class Solution {
public ArrayList<Integer> jobSequencing(int[] deadline, int[] profit) {
int n = profit.length;
int[][] arr = new int[n][2];
for(int i=0;i<n;i++){
arr[i][0] = deadline[i];
arr[i][1] = profit[i];
}
Arrays.sort(arr,(a,b) -> a[0] - b[0]);
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int i=0;i<n;i++){
int[] job = arr[i];
if(job[0] > pq.size()) pq.offer(job[1]);
else if(!pq.isEmpty() && job[1] > pq.peek()){
pq.poll();
pq.offer(job[1]);
}
}
int p = 0, c = pq.size();
for(var it : pq){
p+=it;
}
return new ArrayList<>(Arrays.asList(c,p));
}
}
// Maximum Meetings in One Room
class Solution {
public ArrayList<Integer> maxMeetings(int[] s, int[] f) {
int n = s.length;
int[][] arr = new int[n][3];
for(int i=0;i<n;i++){
arr[i] = new int[]{s[i],f[i],i+1};
}
Arrays.sort(arr,(a,b) -> a[1] - b[1]);
ArrayList<Integer> list = new ArrayList<>();
int ed = arr[0][1];
list.add(arr[0][2]);
for(int i=1;i<n;i++){
if(arr[i][0] > ed){
list.add(arr[i][2]);
ed = arr[i][1];
}
}
Collections.sort(list);
return list;
}
}
// Jump Game
class Solution {
public boolean canJump(int[] nums) {
int n = nums.length,maxidx = 0;
for(int i=0;i<n;i++){
if(i>maxidx) return false;
maxidx = Math.max(maxidx,nums[i]+i);
}
return true;
}
}