There can be one error . After by incrementing current time then also it does not match start time of other interval. In that case all the inputs wil not come in our answer.
Simplest Approach: class Solution { public: long long solve(vector& bt) { // code here int count = bt.size(); sort(bt.begin(), bt.end()); int waitTime = 0; int sum = 0; for(int i = 1; i < count; i++){ waitTime += bt[i - 1]; sum += waitTime; } return sum/count; } };
There can be one error . After by incrementing current time then also it does not match start time of other interval. In that case all the inputs wil not come in our answer.
Thank You So Much for this wonderful video............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
Simplest Approach:
class Solution {
public:
long long solve(vector& bt) {
// code here
int count = bt.size();
sort(bt.begin(), bt.end());
int waitTime = 0;
int sum = 0;
for(int i = 1; i < count; i++){
waitTime += bt[i - 1];
sum += waitTime;
}
return sum/count;
}
};
what if the arrival time of second job is less then current_time (IG we also need to increment current_time)
bhaiya plz operating system ki bhi ek series bana dijiye
theres a small bug
the code shown only works if the least arrival time is 0.
to fix this initialize current_time to the least arrival time
Also if least arrival time is not zero than the current tine will be the least time + it's execution time.
Nicee
Great video brother keep up the good work
Where did u learnt DSA?
Code library
Please make on k centres problem
bro you should improve you teaching experience i am not understand with u
yes i agree u total , what you say
@@jatinsachdeva7488 not could agree more
Video like i the 😂
Sjf revise ho gya
code for java users
public static class Pair implements Comparable {
int id;
int arvl;
int brst;
public Pair(int id, int arvl, int brst) {
this.id = id;
this.arvl = arvl;
this.brst = brst;
}
public int compareTo(Pair o) {
if (this.arvl < o.arvl) {
return 1;
}
if (this.arvl > o.arvl) {
return -1;
} else {
if (this.brst < o.brst) {
return 1;
}
if (this.brst > o.brst) {
return -1;
} else {
if (this.id < o.id) {
return 1;
}
if (this.id > o.id) {
return -1;
} else {
return 0;
}
}
}
}
}
public static class Pair1 implements Comparable {
int id;
int arvl;
int brst;
public Pair1(int id, int arvl, int brst) {
this.id = id;
this.arvl = arvl;
this.brst = brst;
}
public int compareTo(Pair1 o) {
if (this.brst < o.brst) {
return 1;
}
if (this.brst > o.brst) {
return -1;
} else {
if (this.arvl < o.arvl) {
return 1;
}
if (this.arvl > o.arvl) {
return -1;
} else {
if (this.id < o.id) {
return 1;
}
if (this.id > o.id) {
return -1;
} else {
return 0;
}
}
}
}
}
public static ArrayList solver(int id[], int arrival[], int burst[]) {
int time = 0;
ArrayList arr = new ArrayList();
PriorityQueue pq = new PriorityQueue(Collections.reverseOrder());
for (int i = 0; i < id.length; i++) {
pq.add(new Pair(id[i], arrival[i], burst[i]));
}
// while(!pq.isEmpty()){
// Pair p=pq.poll();
// System.out.println(p.id+" "+p.arvl+" "+p.brst);
// }
PriorityQueue p_q = new PriorityQueue(Collections.reverseOrder());
while (!pq.isEmpty()) {
while (!pq.isEmpty() && pq.peek().arvl