1,057 questions
2
votes
1
answer
117
views
Why does my Python solution for selecting 2 points from each interval give incorrect results for overlapping intervals?
I’m trying to solve the following Leetcode problem:
You are given a 2D integer array intervals where intervals[i] = > [starti, endi] represents all the integers from starti to endi
inclusively.
A ...
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 ...
1
vote
4
answers
394
views
How to solve a modified version of Leetcode Valid Parentheses?
I recently had an interview where I was asked to solve a modified version of this question on leetcode. Instead of checking if the string is valid you are supposed to count the minimum number of ...
13
votes
6
answers
420
views
How can I divide a list of electrical loads into 3 groups with near-equal total sum using Python?
I'm an electrician working toward becoming an electrical engineer. I have some basic knowledge of Python and am trying to automate a tedious process we often face in the field.
In 3-phase electrical ...
1
vote
1
answer
106
views
Anyone know the right algorithm? [closed]
Does anyone know any LeetCode, Codeforces or anything like the following programming problem?:
Imagine you have "n" slots, from 1 to "n" with "s" being your starting ...
1
vote
1
answer
230
views
Is this a greedy algorithm and if so, why?
I'm working through "Competitive Programming 4" by "Halim et al." and in the topic "Greedy algorithms", I was solving the following problem on Kattis: fridge.
The goal ...
4
votes
1
answer
278
views
Why does this greedy algorithm work for "Lexicographically Smallest Generated String" from LeetCode?
I am looking at solutions to the LeetCode problem 3474. Lexicographically Smallest Generated String:
You are given two strings, str1 and str2, of lengths n and m, respectively.
A string word of ...
-1
votes
2
answers
66
views
a alg problem can't be solved by normal greedy choice
Problem Description:
Xiaoming has n energy balls, which are arranged from left to right. Each energy ball has an energy value v_i. Now, Xiaoming can perform the following 4 types of operations on this ...
2
votes
1
answer
158
views
Maximum the sum of lengths of two nondecreasing subsequence of given array
It is a famous question which asked about finding longest nondecreasing subsequence from a given array. The question is well studied and have O(n log n) time complexity solutions.
I have encountered a ...
0
votes
1
answer
56
views
Is this the right greedy strategy for allocating seats?
I am attempting https://open.kattis.com/problems/distributingseats
This problem has been listed as a classical greedy problem in the Competitive Programming Book by Steven & Felix
https://cpbook....
0
votes
1
answer
277
views
Schedule k tasks with times to finish w(k) and N workers, without any tasks occurring out of order within a single worker
Suppose I have several tasks with uneven lengths. For example, let k=8 and w(k)=[4,5,3,10,1,1,1,3]. How would I assign these to N=3 workers such that any tasks assigned to a given worker are ...
3
votes
0
answers
58
views
Minimum dominating subgraph
A graph G(V,E) is defined by a set of vertices V and a set of edges E. Given W⊆V, find a connected subgraph G'(V',E') of G that satisfies the following conditions:
i) ∀p∈V,∃p'∈V' such that p′ is ...
2
votes
2
answers
129
views
How to optimize a greedy algorithm for maximizing items bought with coupons and limited money?
I am a beginner in algorithms and my native language is not English, so please forgive me if there are any cognitive errors or grammatical errors.
I am working on a problem where I need to maximize ...
2
votes
1
answer
67
views
Creating subgraphs from neighbors with max weight in R using igraph
I am trying to create subgraphs from pairs of edges in a graph a by following procedure:
library(igraph)
library(data.table)
dt <- data.table(from = c("A", "B", "C", &...
5
votes
2
answers
152
views
Algorithm to Minimize Time to Complete All Endings in a Multi-Branch Game with Limited Save Points
In a multi-branch game, there are 𝑛 possible endings. You can think of it as a directed tree with 𝑛 leaf nodes, where each edge has a weight of 1. Instead of playing through the entire game to reach ...