121,483 questions
3votes
2answers
88views
find maximum length of subsequence with adjancent diff less than 2
Problem Statement: You are given an array of integers arr of size n. Select a subsequence of integers and rearrange them to form a circular sequence such that the absolute difference between any two ...
1vote
1answer
64views
3D Morton code computation utilizing carry-less multiplication
This question arose specifically in the context of exploratory work for RISC-V platforms which may optionally support a carry-less multiplication instruction CLMUL. It would equally apply to other ...
0votes
0answers
27views
Is a symbol table a data type or a data structure
It confuses me whether a symbol table is a data type or data structure. This book site defines a symbol table is a data type that we use to associate values with keys. However, in Algorithms (by the ...
0votes
2answers
59views
Remake color mixing function to find color to mix with given color to get the given result color
My question looks very strange, but I'll try my best to explain it. I got this function def combine_hex_values(d): d_items = sorted(d) tot_weight = 2 red = int(sum([int(k[:2], 16) for k in ...
-7votes
0answers
68views
Why is my create_spend_chart output not matching the required format?
I’m trying to solve a project where I build a Category class and a create_spend_chart function to create a text-based spend chart. My Category class methods (deposit, withdraw, transfer) seem to work ...
3votes
1answer
85views
How to create a layout that only has all even or all odd row size, and changes by only 2?
I have been iterating with both Claude 3.7 Sonnet, and ChatGPT 4o, for days and days, trying to get this to be exactly how I want it, but it keeps making mistakes in the algorithm, and on an on in ...
-1votes
0answers
54views
Deadlock Issue in Multithreaded Resource Allocation System with Dynamic Task Dependencies [closed]
I'm developing a multithreaded application in C++ that manages a resource allocation system for tasks with dynamic dependencies. Each task requires a subset of resources (e.g., CPU cores, memory ...
-2votes
0answers
78views
Efficient way to win points in chocolate bowl game [closed]
I'm working on an optimization problem involving a turn-based chocolate-sharing game, and I need help optimizing my current brute-force solution. Problem Description: You and your friend take turns ...
1vote
1answer
72views
Efficient algorithm to create ordered union of lists with unknown true ordering
I have a bunch of lists I need to combine. Each of these lists has an ordering, and each ordering is consistent with the ordering of an original list. (By consistent, I mean that each list can be ...
-1votes
0answers
38views
Optimizing synchronized pathfinding for two mazes with shared instruction sequence and "reset" pits (A* or BFS) [closed]
I'm working on a problem that involves synchronized pathfinding through two mazes. Here's the setup: Two mazes of equal size (n × m). Two agents start at position (0,0) in their respective maze. They ...
4votes
1answer
107views
How to optimize subarray transformation for large inputs?
I have a problem where I need to select a contiguous subarray from a list of integers and add any integer z (positive or negative) to all elements in the subarray, such that the frequency of a target ...
5votes
1answer
242views
efficient check whether unsigned integer value belongs to either of two compile-time constant intervals
In various contexts I have faced the issue of determining whether a given unsigned integer value belongs to either one of two non-overlapping intervals, and not infrequently these checks introduce ...
1vote
1answer
66views
Round-robin tournament algorithm with drop-outs?
I'm trying to code a round-robin algorithm for a match-making program. The requirements are as follows: If there are an even number of people, everyone must have a match every round (if there's an ...
0votes
0answers
29views
Custom Implementation of cosine similarity metric in k-means algorithm [closed]
Is there any way in the existing k-means algorithm implementations to use as distance metric a cosine similarity instead of euclidian distance ?
-1votes
1answer
37views
What is correct path tracking in Floyd-Warshall algorithm?
There are several descriptions of the Floyd-Warshall algorithm, including the one in Wikipedia where path tracking logic described like in the pseudo-code below (copy from Wikipedia https://en....