2,636 questions
3
votes
1
answer
196
views
Where is the flaw in this greedy approach?
I am sitting on a LeetCode problem, specifically Minimum Time to Repair Cars.
You get a list of how many mechanics you have and how many cars you need to fix.
Each mechanic has a rank, and he takes ...
2
votes
4
answers
185
views
How can I efficiently maintain median in a dynamic data stream with support for deletions?
I'm working on a problem where I need to maintain the median of a data stream, but unlike typical implementations that only support insertions, I also need to support deletions of arbitrary values.
...
0
votes
0
answers
36
views
How do I proceed with the else branch of my Priority Queue insertion proof in Coq?
I am working on proving the correctness of a Priority Queue implementation in Coq.
I am getting stuck in the else branch of my insert theoreom. (I had to change my OG inductive hypothesis to better ...
0
votes
1
answer
251
views
Maximize efficiency for this LeetCode style problem [duplicate]
I found this LeetCode style problem in a previous assignment for my university.
Assume you have an online clothing store and you have products which come in variable sizes. Some products come in the ...
1
vote
0
answers
93
views
Implementing Correct Node Partnership in a Doubly-Ended Array-Based Priority Queue (DEAP)
I'm working on implementing a Double-Ended Priority Queue (DEAP) data structure in C++. I'm having trouble with establishing the correct implementation of node partnerships between the min and max ...
0
votes
1
answer
445
views
What is the recommended way to convert a PriorityQueue to an array in C#?
I'm really having a hard time with Microsoft's implementation of PriorityQueue because it's missing most of the extension methods that you'll find in other collections. There is no ToArray method, ...
-1
votes
1
answer
104
views
Error in Java : incompatible types: cannot infer type arguments for PriorityQueue<>
class Solution {
class City{
int city;
long time;
City(int c, long t){
city = c;
time = t;
}
}
public int countPaths(int n, int[][] ...
-1
votes
1
answer
246
views
Haskell, Python speed comparison (Heap // priority-queue)
I have a problem to solve. Details of it basically irrelevant & I have two valid solutions for it: in python and Haskell.
Python code:
import heapq
_, volume, *ppl = map(int, open("input.txt&...
0
votes
1
answer
100
views
AddressSanitizer Error When Using Static Member Function as Comparator in C++ Priority Queue
I'm working with a priority_queue in C++ and encountered a problem when using a static member function as a custom comparator within a class.
A reproducible example will be:
#include <bits/stdc++.h&...
1
vote
4
answers
288
views
Understanding PriorityQueue Comparator syntax in Java
Doing some leetcoding. Top K frequent elements.
I'm implementing my solution via Max Heap. Can someone please help me understand the PriorityQueue comparator syntax?
Map<Integer, Integer> map = ...
0
votes
1
answer
179
views
celery priority does not apply
i have this example code:
@router.post('/test')
def Test():
for i in range(0,10):
Testy.apply_async([i],priority=7)
return "done"
@app.task(bind=True)
def Testy(self,i):
...
0
votes
0
answers
273
views
How to use Celery as priority queue?
I use Celery to process background jobs that use a blocking API for a Django web app. Since the API can only process one job at a time, I also use a lock (implemented with Redis) to ensure that only ...
-1
votes
1
answer
51
views
Getting error Cannot convert Generic.Comparer<Pair> to Generic.IComparer<int> while comparing two objects in a priority queue in c# using lambda ex
I have a pair class.
public class Pair
{
public int freq;
public int coolTime;
public Pair(int freq, int coolTime)
{
this.freq = freq;
this.coolTime = coolTime;
...
-2
votes
1
answer
140
views
Custom sort for HashMap on Priority Queue [duplicate]
I want to get the sorted key value pair on value, and if the values are equal, I wanna sort on keys asc.
I tried using PriorityQueue like following but I am getting null pointer for some reason. ...
0
votes
1
answer
71
views
Issues with custom compare for std::priority_queue in c++98
I'm trying to create varaible of type 'std::priority_queue' like this:
struct
{
bool operator()(std::vector<int> v1, std::vector<int> v2){return (v1[2] + v1[3]) > (v2[2] + v2[3]);};
...
0
votes
2
answers
250
views
is there a way to implement priority queue with binary heap but the values are structs themselves?
I have an assignment that asks me to implement a priority queue with binary heap in c. I have a problem because basically, the input data that we get looks like this:
7 - number of occurences
3 4 0 5 ...
-1
votes
1
answer
50
views
Adding Objecting in Priority Queue With multiple comparison
I have a Priority Queue that containst an Object called it 'RouteInfo',
public class RouteInfo{
private double totalCost;
private double totalLeadTime;
private int numberOfLanes;
...
-2
votes
1
answer
89
views
Algorithm to extract elements from weighted queues
I'm trying to implement a kind of 'weighted queue extractor' to extract elements from different queues having different priorities. I just have to choose the queue I've to get an element from.
Let's ...
1
vote
1
answer
122
views
Providing a third argument to a priority_queue's compare function
I've been trying to figure out a way to provide some extra information to my priority queue's compare function. Let's assume I have the following:
class MyClass
{
class IntCompare
{
...
0
votes
0
answers
75
views
Exercise on queue in java
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
public class TestQueueTwo {
public static void main(String[] args) {
Random random = new Random();
...
0
votes
0
answers
32
views
How to check that insertThenNext returns the inserted value if it's less than everything else in the tree
i've tried a multitude of solutions including changing the way that insertThenNext deals with the numbers but all possible solutions i've tried end up making the code fail the other tests that it must ...
0
votes
0
answers
62
views
Modifying an item in a PriorityQueue in Java
Say I have a custom class as below
class Emp {
String name;
Integer id;
}
I decide to use a PriorityQueue in java to insert the elements of Emp and provide a custom comparator on id field of ...
-1
votes
1
answer
156
views
STL priority_queue using reinsertion for key decrease not working
I'm trying to implement an A*-like algorithm, and I am having trouble implementing key decrease using the STL priority_queue container. I am trying to reinsert elements into the queue when I decrease ...
0
votes
1
answer
139
views
python3 TypeError: '<' not supported error when try to implement A* algo use python heapq
I am trying to implement A* algorithm using pri_que by leveraging python library heapq. In general, all the state of will be stored as a Node instance
class Node:
def __init__(self, state, parent, ...
0
votes
0
answers
29
views
priority queue comparator not called for all the elements in the linked list
I'm working on merging K linked list using pq. But the comparator not working for all the elements in the Linked list. someone please shed the light why the comparator not working as expected.
This ...