121,464 questions
Best practices
0
votes
2
replies
37
views
How to suggest movies that the user didn't see already in real time?
I am building a simple school project, and the idea is that users form a group together, then an activity (for example movie activity), and then in that activity the app suggests movies for every ...
Best practices
1
vote
7
replies
140
views
How to use better OOP for a Huffman Compressor
So I refactored my Huffman program for better OOP practices. Now, I need to make an array of coded objects that represent a character and its
// C++ program to implement huffman coding
#include <...
0
votes
1
answer
185
views
Why does my approach for "Maximum Subarray Sum After at Most K Swaps" fail on some test cases?
I am solving the following problem:
Maximum Subarray Sum After at Most K Swaps - Leetcode #3962
You are given an integer array nums and an integer k.
You are allowed to perform at most k swap ...
Advice
0
votes
3
replies
91
views
Can a transformation pattern be inferred from example input/output pairs?
I'm experimenting with a small tool that receives:
an input string A
an expected output string B
Example:
Input:
{'name':'John','email':'john@email'}
Output:
insert into users (name,email)
values ('...
Best practices
0
votes
7
replies
178
views
How to actually compress a .txt file after obtaining a Huffman encoding
So I have this program that takes an unordered map of chars and integers as a frequency counter and returns the Huffman encoding as a map.
#include <iostream>
#include <queue>
#include <...
Advice
0
votes
3
replies
171
views
How to determine if a point is inside a triangle?
How to determine if a point is inside a triangle? I need to create a method bool inTriangle(Point p, Point tr1, Point tr2, Point tr3) that returns 1 (true) if point p is inside or on the boundary of ...
Advice
0
votes
4
replies
150
views
The fastest algorithm for the problem "Cheapest flight within k stops"?
I am doing a coursework on algorithms and complexity. The problem is just what is stated in the title, that is to find the fastest algorithm for the problem "Cheapest flight within k stops".
...
Advice
0
votes
5
replies
79
views
The number of edges present in the forest generated by the DFS traversal of an undirected graph G with N vertices is K. No of connected component
I am learned algorithm of dfs and everything but still I have a doubt when this question came up. Even I know how to do it. But I didn't able to solve.
I know the solution but I need someone to teach ...
Advice
0
votes
4
replies
114
views
Could the L1 Cache Save Computation Time?
The CPU cache unit is used to store the next few instructions so that the (expensive) process of reading and writing the RAM is bypassed to save execution time. Has anyone thought about using the L1 ...
Advice
2
votes
7
replies
110
views
Spatial decomposition on non-uniform grid
I am not sure Stack Overflow is the right place for this question but I'm shooting my shot.
I have a 2D field sampled on a global longitude-latitude structured curvilinear grid and I would like to ...
Advice
3
votes
11
replies
295
views
Modulus of Very large Number
You are given a very large number N (which goes upto 1e10000)
and a 64 bit integer P.
How do i find N % P?
for example:
N= 8290826691135830692772803 , P = 95972011
modulus (N % P) = 60316167
obviously ...
-5
votes
2
answers
203
views
Exhaustive Combination with Python [closed]
Suppose I have 3 lists:
list1 = a, b, c
list2 = 1, 2, 3
list3 = A, B, C
I want a result like:
combination 1: [(a, 1, A), (b, 2, B), (c, 3, C)]
combination 2: [(a, 1, A), (b, 2, C), (c, 3, B)]
...
Advice
0
votes
4
replies
52
views
What is the pattern for the layer heights of a deterministic skip list?
Before working on single-element insertion or deletion, I’m wondering if the initial list values can be inserted better than starting with an empty list then inserting N times.
The constraint on the ...
-1
votes
3
answers
191
views
Why does my Java stack-based bracket validator fail with nested expressions?
I am implementing a simple bracket validator in Java using a stack. The goal is to verify whether an expression contains balanced parentheses, brackets, and braces. The validator works correctly for ...
0
votes
2
answers
100
views
Backtracking current.remove executes twice [closed]
I have a number of questions about the backtracking concept in programming but mainly why current.remove is executing twice. So I am practicing a leetcode problem where you have to find all the ...