Queue Solutions
Queue Solutions
[email protected]
Solution 1 :
import java.util.LinkedList;
import java.util.Queue;
Solution 2 :
import java.util.*;
class Solution{
static int minCost(int arr[], int n){
PriorityQueue<Integer> pq
[email protected]
= new PriorityQueue<Integer>();
int res = 0;
while (pq.size() > 1) {
int first = pq.poll();
int second = pq.poll();
res += first + second;
pq.add(first + second);
}
return res;
}
Solution 3 :
import java.util.*;
class Solution {
static class Job {
char job_id;
int deadline;
int profit;
Job(char job_id, int deadline, int profit){
this.deadline = deadline;
this.job_id = job_id;
[email protected]
this.profit = profit;
}
}
[email protected]
public static void main(String[] args){
ArrayList<Job> arr = new ArrayList<Job>();
Solution 4 :
import java.io.*;
import java.util.*;
import java.util.*;
class Solution {
[email protected]
static boolean isInside(int x, int y, int N){
if (x >= 1 && x <= N && y >= 1 && y <= N)
return true;
return false;
}
[email protected]
minStepToReachTarget(
knightPos, targetPos, N));
}
}
Solution 5 :
import java.util.Deque;
import java.util.LinkedList;
[email protected]
int k = 3;
printMax(arr, arr.length, k);
}
}