Skip to main content
Filter by
Sorted by
Tagged with
-3 votes
0 answers
58 views

Suppose we have an 𝑚*𝑛 grid, let 𝑖=0,...,𝑚−1 and 𝑗=0,...,𝑛−1. For each grid point we have an array 𝑆𝑖𝑗 of size 𝑁 that serves as local score function. We want to to find a way that assigns ...
Peter Wu's user avatar
  • 279
-3 votes
0 answers
59 views

You are given a N×NN×N 2D grid representing possible quantum states, where each cell contains a 32-bit unsigned integer. Your task is to find a continuous path from the top-left (0,0) to bottom-right (...
SaujasByt's user avatar
6 votes
2 answers
303 views

I'm working on a problem where I need to count, for each possible common difference D, the number of contiguous subarrays whose elements can be rearranged to form an arithmetic progression with common ...
YAR's user avatar
  • 63
0 votes
0 answers
74 views

Problem Statement There are N items, numbered 1, 2, …, N. For each item i (1 ≤ i ≤ N): It has a weight w[i] It has a value v[i] Taro wants to choose some of these N items and carry them home in a ...
Plague's user avatar
  • 1
2 votes
1 answer
194 views

I do not know when to use backward or forward computation for tabulation in solving a dynamic programming problem. I would like to know the thinking process to decide which one to use or which one ...
user avatar
-4 votes
1 answer
280 views

I'm working on a combinatorics problem where I need to compute how many ways the set {1, 2, ..., n} can be divided into two subsets with equal sum, such that every number from 1 to n is in exactly one ...
Nam Dương VND18 Vũ's user avatar
0 votes
1 answer
113 views

I'm looking at one of the solutions to the programming problem: Partition a Set into Two Subsets of Equal Sum. The programming problem: Given an array arr[], the task is to check if it can be ...
charactersum's user avatar
1 vote
1 answer
106 views

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 ...
Casper Kejser's user avatar
9 votes
2 answers
264 views

A valid shuffle of two strings A and B is when their characters are mixed together to form a bigger string and all characters are used and the string is such that the order of characters in A and B is ...
Inclatable's user avatar
-1 votes
1 answer
69 views

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....
RomanGirin's user avatar
0 votes
1 answer
89 views

class Solution { public: int change(int amount, vector<int>& coins) { vector<unsigned int > dp(amount+1, 0); dp[0]=1; for (int value: coins){ ...
OXEN's user avatar
  • 13
5 votes
2 answers
133 views

In the classic subset sum problem, there are a set S and a target t, and the goal is to find a subset of S whose sum is t. This variant has a pseudo-polynomial time solution. In a variant of the ...
Samuel Bismuth's user avatar
6 votes
1 answer
178 views

Problem description: A mailbox manufacturer wants to test a new mailbox prototype's durability based on how many fire crackers it can withstand. Given k identical mailboxes (each holding up to m ...
Karma's user avatar
  • 77
0 votes
0 answers
44 views

I have a table like below create table public.test_dynamic_data_tbl(col1 int,col2 character varying,col3 double precision); insert into public.test_dynamic_data_tbl values(1,'test1',12) insert into ...
Amar's user avatar
  • 1
0 votes
0 answers
55 views

How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution? The code is working but I want to improve it. The challenge I am facing is ...
Elias El hachem's user avatar
4 votes
2 answers
118 views

I'm implementing an A* search algorithm for a maze solver in Python. Initially, I maintained the open set as a plain set and selected the node with the lowest f-score using: current = min(open_set, ...
Tao's user avatar
  • 51
3 votes
2 answers
128 views

Originally I faced a problem: I had three arrays of the same length (say, a, b, c), and I needed to choose indexes i, j, k distinct from each other that the sum a_i + b_j + c_k would be minimal. I ...
horart's user avatar
  • 73
1 vote
2 answers
110 views

I was solving a test on an online platform and the problem statement was similar to this. Stuart has to go from one place to other (A-> B) and he can jump either 1 step, 2 step or 3 steps at a time....
ABGR's user avatar
  • 5,263
2 votes
1 answer
158 views

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 ...
tsh's user avatar
  • 4,838
4 votes
2 answers
129 views

How can I optimize this code for better performance while maintaining the correctness of dynamic updates? Is there a way to restructure the nested loop or use a different approach to reduce the time ...
Akash Selvadoss N's user avatar
2 votes
4 answers
236 views

Given a and b relating to a list of substrings in c: a = "how are you ?" b = "wie gehst's es dir?" c = [ ("how", "wie"), ("are", "gehst's&...
alvas's user avatar
  • 123k
0 votes
1 answer
107 views

I was just starting out with dynamic programming and tried solving factorial problem using the same, i used binary tree for underlying data structure, but when i thought of comparing it with normal ...
Vishwas MIshra's user avatar
-1 votes
1 answer
335 views

everyone! While I was solving the problems from cses.fi I came across the one that I totally couldn't understand. I searched the Internet and found the solution with DP along subsets, but still wasn't ...
Ivan_Striker's user avatar
-1 votes
3 answers
174 views

I am trying to find the value of a Fibonacci sequence given an integer N, representing the nth term using an ArrayList (my logic is that because ArrayList are dynamic and can resize no matter what ...
websterweb40's user avatar
3 votes
0 answers
58 views

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 ...
Sword fish's user avatar
-5 votes
2 answers
114 views

Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After the cutting each ribbon piece should have length a, b or c. After the ...
Артем's user avatar
0 votes
1 answer
105 views

Just by using the commented code instead of making the recursive calls inside the max function, leads to incorrect result particularly with the following test case int main() { Solution obj = ...
Mohamed Samir's user avatar
0 votes
1 answer
127 views

I'm trying to use dynamic programming to solve a knapsack variation, where you are given an array of containers, each of them having a weight, a resistance and an id, I need to find the tallest pile ...
Nombre de Usuario Genérico's user avatar
1 vote
2 answers
164 views

Problem: Given an array that sums to 0, find the maximum number of partitions of it such that all of them sum up to 0 individually. Example: input: [-2, 4, -3, 5, -4] output: 2 (which are [[5, -2, -3]...
figs_and_nuts's user avatar
3 votes
4 answers
187 views

I’m trying to solve the Maximum Product Subarray problem, which is described as follows: Given an array of integers (positive, negative, or zero), find the maximum product of any contiguous subarray. ...
Rishal kumar's user avatar
1 vote
1 answer
117 views

Question: Given an undirected tree with N nodes ( 2 <= N <= 100,000 ) and N-1 edges, how can I find two non-intersecting paths with maximum product? Example: 6 1-2 2-3 2-4 5-4 6-4 Answer: 4 ...
Aibar's user avatar
  • 11
1 vote
4 answers
426 views

https://leetcode.com/problems/minimum-array-sum/ You are given an integer array nums and three integers k, op1, and op2. You can perform the following operations on nums: Operation 1: Choose an ...
snehith oddula's user avatar
0 votes
1 answer
155 views

I was solving LeetCode problem 3290. Maximum Multiplication Score: You are given an integer array a of size 4 and another integer array b of size at least 4. You need to choose 4 indices i0, i1, i2, ...
souparno majumder's user avatar
1 vote
1 answer
67 views

I'm struggling with understanding a concept of minimum supersequence of two given strings. I understand how to print this supersequence from 2D dp table that we get after solving LCS problem for two ...
myfakeaccount's user avatar
2 votes
1 answer
56 views

I'm trying to simulate the level of a tank that has two inlet flows and one outlet. The idea is that after this will be used in a control problem. However, I can't get it to work with gekko but it did ...
iarima's user avatar
  • 45
5 votes
2 answers
152 views

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 ...
SuohTheBest L's user avatar
-2 votes
1 answer
49 views

You are given an array containing n elements, where n is odd. In one operation, you can select an index i, such that 1 ≤ i < n and remove ai and ai+1 from the array and concatenate the remaining ...
20BCS029-Ishtiyak Ahmad Khan's user avatar
1 vote
2 answers
124 views

Question: Is it possible to compute the nth Fibonacci number using forward recursion with memoization? If so, how? If not, why not? Context: Most learning resources and books (e.g., CLRS, DPV, etc.) ...
Daniel W. Farlow's user avatar
1 vote
1 answer
179 views

How can you find the maximum possible sum of values by optimally placing tiles in a matrix rxc where each cell has an integer value? The goal is to maximize the sum by covering cells with 1x2 or 2x1 ...
bigtree's user avatar
  • 13
5 votes
1 answer
212 views

I'm trying to optimize an algorithm that counts permutations with specific constraints. Given integers n, t, a, b where: n is the length of permutation (1 to n) t is the required number of fixed ...
Peter Thomas's user avatar
4 votes
1 answer
286 views

A good follow up question asked in one of the interview post 'valid parentheses' problem. Given an imbalanced parentheses string, return the result string(any one of multiple solutions) with balanced ...
Shailendra's user avatar
0 votes
4 answers
364 views

I have an array. Each iteration, I take an element from the array and add it to a running sum. Then, the first and last element are discarded. I cannot pick an element in the same initial index twice. ...
isuf's user avatar
  • 51
0 votes
1 answer
58 views

class Solution { public: int countNeighborhoods(const vector<int>& houses) { int neighborhoods = 0; int m = houses.size(); for (int i = 0; i < m; i++) { ...
Shreshth Sharma's user avatar
1 vote
0 answers
145 views

I have two strings, s1 and s2, and I need to find the length of the longest substring that appears in both strings. The substring must be contiguous in both s1 and s2. For example: If s1 = "...
nikhil pachange's user avatar
0 votes
0 answers
76 views

Given an array of arrays, with each sub-array contains unique elements, but among different sub-arrays, there might be the same element. Select the top K sub-arrays, that the union of all elements ...
Shane's user avatar
  • 3
0 votes
0 answers
246 views

I try to implement ZigZag Indicator in TypeScript. My ZigZagCalculation function accepts as a parameters: Bar[] bar, deviation: number And returns array with all the zig-zag points. My bar array has a ...
Dan B.N.'s user avatar
1 vote
1 answer
269 views

Here is a problem that was in a past exam for Advanced algorithms in my studies,it's on 5 points over 3 hours so should take approximately 1H but I am struggling to find the solution for the first ...
Solal Peiffer-Smadja's user avatar
0 votes
1 answer
157 views

So I personally favor coding dynamic programming solutions using a top-down approach. Especially in python because it lends itself to a rather easy recursive implementation using the cache decorator, ...
BBenyani's user avatar
  • 123
0 votes
0 answers
19 views

I'm working on a dynamic programming problem related to counting the number of ways to partition an array into two subsets such that the absolute difference between their sums is equal to a given ...
Siddhant Jugran's user avatar
-1 votes
2 answers
150 views

I am looking at a particular solution that was given for LeetCode problem 322. Coin Change : You are given an integer array coins representing coins of different denominations and an integer amount ...
figs_and_nuts's user avatar

1
2 3 4 5
115