121,490 questions
Advice
0
votes
2
replies
47
views
Making a palindrome out of a string of random letters (or any given value type inputs)
Found this code exercise on W3R. Been trying to figure out the relationship between the outer and inner loop (i and j), but can't seem to wrap my head around it. If anyone could walk me through this ...
2
votes
1
answer
99
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 ...
Advice
1
vote
3
replies
68
views
Python library recommendation for the implementation of a neural network modification algorithm
I want to implement in python some algorithms from a paper that allow for a pre-trained neural network to be modified (adding or removing neurons or layers) conserving (theoretically) the outputs of ...
Advice
0
votes
1
replies
70
views
I need a different approach to solve problems
As a student in an IT school, i need to solve problems every days, but I don't believe that I am doing it the right way.
When I try to solve a problem, I am fastly thinging of what is the problem and ...
0
votes
2
answers
70
views
(Shell Sorting) Applying Ciura's gap sequence (or some other optimal sequence formula)
I've been trying to teach myself various sort methods just for the sake of being able to use them in the future and right now I've been teaching myself about shell sorts. I understand the way shell ...
Advice
0
votes
3
replies
65
views
Is there a Julian date algorithm without any restriction on the date?
The context is implementing conversion functions between Gregorian calendar dates and Julian dates.
Most (nearly all?) such implementations have restrictions on the dates - typically requiring that ...
2
votes
1
answer
190
views
Accurate computation of the inverse gamma function with the standard C math library
The inverse of the gamma function over the reals is multivalued with an infinite number of branches. This self-answered question is about the principal
inverse of the gamma function, Γ0-1(x), whose ...
2
votes
1
answer
158
views
Minimum number of sign flips for prefix sum positivity
Problem:
We are given a list of integers of length n. What is the minimum number of elements whose sign you need to flip such that every prefix sum is non-negative? (A prefix sum is the sum of the ...
1
vote
1
answer
305
views
Trouble implementing the Cooper–Harvey–Kennedy algorithm for finding immediate postdominators in C++
I'm trying to implement the Cooper–Harvey–Kennedy algorithm from this paper in C++. The original is used to find dominators, however in my case I need to find the postdominators. For this, I am aware ...
-2
votes
1
answer
176
views
Why does my Quick Sort implementation sometimes cause stack overflow on large arrays with duplicates? [closed]
I’m trying to implement an in-place Quick Sort in Python. I have two slightly different versions of my partitioning logic, and I’m confused because both seem correct on small arrays, but the second ...
2
votes
1
answer
134
views
How to find minimum number of days for a schedule according to a preference via graph?
I am tasked with a question as follows:
We have n players and we want to hold a wrestling tournament with exactly n * (n - 1) / 2 matches. In each day a player can only play at most one match. However,...
2
votes
1
answer
120
views
Fast vectorized maximal independent set greedy algorithm [closed]
I need a really fast vectorized maximal independent set algorithm implemented in pytorch, so I can use it for tasks with thousands of nodes in reasonable time.
I cannot use networkx, it is way too ...
3
votes
3
answers
188
views
Swapping corresponding negative and positive elements in an array while keeping constant order in their respective groups
The problem:
Given an array in which the number of negative elements is equal to the number of positive elements (arranged in arbitrary order). Swap the first negative and the first positive, then ...
7
votes
3
answers
245
views
Swapping two array elements with two other specific array elements without using an if-statement
I have an array x of n >= 4 elements, at indices 0..n-1. I want to swap the elements at indices j and k, where 0 <= k < j < n with the elements at indices 0 and 1 (it doesn't matter ...
2
votes
1
answer
124
views
Calculating a light volume that comes in through a window
I have a room that is a box. There is a single rectangular window on one of the walls of the room. A directional light source is shining into the room through the window. The light source has a ...
5
votes
3
answers
221
views
Efficient ways to check if two binary trees are the same
I implemented a recursive solution in Python to check if two binary trees are identical, which traverses nodes recursively and compares values and structure. The time complexity is O(n), space O(h).
...
3
votes
2
answers
496
views
Find employees with overlapping wortktime hours
Given StartTime and endTime for N employees, an employee can form a team if his working hour overlaps with other employees' (both startTime and endTime inclusive).
Find the maximum team size.
Example:
...
0
votes
0
answers
93
views
Data structure indexing data by key value pairs
I have a bunch of data which is indexed by key/value pairs. For example I might have x=1, y=2, z=3 => data="1,2,3" and x=1,y=2 => data="1,2" etc.
The operations I need to ...
7
votes
3
answers
295
views
How to find the longest elementary path in a graph?
The problem is to find the longest sequence of numbers from 1 to 100 such that each number is either multiple or divisor or the previous, and with no repetition. For example, 50 25 5 35 7 63 21 is a ...
1
vote
1
answer
110
views
Why is my sliding window algorithm not showing results?
The current problem I'm having is that when the code runs it shows me "None" in the terminal.
/usr/local/bin/python3.12/Users/jaredmccarthy/Desktop/2025/ejercicios_leetcode.py
None
Process ...
2
votes
0
answers
114
views
JIRA Lexorank in depth
I'm researching about maintaining order in a list like JIRA, and I come across Jira Lexorank. I've already understood it's core concept, but there are 2 questions that I struggle to find the in depth ...
-2
votes
2
answers
150
views
Performance of frequently reordering a short list [closed]
I have an application where I have a Rule object that has a list of Filter predicates. I will be comparing many Events to the predicates, and want to know if they all match. Most Events will not match ...
-2
votes
3
answers
856
views
Solve CSES Mountain Range efficiently
This is CSES Mountain Range problem: https://cses.fi/problemset/task/3314/
There are n mountains in a row, each with a specific height. You begin your hang gliding route from some mountain. You can ...
3
votes
2
answers
199
views
Max subArray => IllegalArgumentException: 6 > 5
The method is working as intended, but while I was trying multiple cases, I got this weird issue, so hopefully someone can understand why and explain it to me, since 6 > 5 looks logically sound to ...
5
votes
3
answers
156
views
Why the second letter is being ignored when using my Typewriter component?
I'm currently building my portfolio and im making a typewriter effect for some text :
"use client"
import { useEffect, useState } from "react"
type Typewriter = {
textToWrite: ...