#recursive problem..

1 messages · Page 1 of 1 (latest)

cloud tinselBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

crystal flicker
obsidian burrow
#

*get every possible combination of num sums, if num sums is == target, return true

wdym by every possible combination of num sums?

crystal flicker
#

Learn how to use Dynamic Programming in this course for beginners. It can help you solve complex programming problems, such as those often seen in programming interview questions about data structures and algorithms.

This course was developed by Alvin Zablan from Coderbyte. Coderbyte is one of the top websites for technical interview prep and c...

▶ Play video
#

the how sum one

crystal flicker
#

come on competitive chad, thats your thing

obsidian burrow
#

ah alr

#

i'll try

#

what is memo btw?

crystal flicker
#

memoization

#

[by this index][]

obsidian burrow
#

ah alr

obsidian burrow
crystal flicker
#

idk

#

no

#

bruh i dont even know what i am doing rn

#

try to do without it

obsidian burrow
crystal flicker
#

but then good luck copying elements from previous stacks return

#

i hate recursion with vector return values

obsidian burrow
#

@crystal flicker

#
std::vector<int> HowSum(int t, std::vector<int> v)
{
    std::vector<int>return_vec;
    sort(v.begin(), v.end());
    if (t < v[0])
        return return_vec;
    while (t!=0)
    {
        if (v.size() == 0)return std::vector<int>{};
        for (int i = v.size() - 1; i >= 0; i--)
        {
            if (v[i] <= t) 
            {
                t -= v[i];
                return_vec.push_back(v[i]);
                break;
            }
            else
                v.erase(v.begin() + i);
        }
    }
    return return_vec;
}
#

i think i did it

crystal flicker
#

what

#

you actually did

#

no way

obsidian burrow
#

i think so

#

i have tested 2 cases

crystal flicker
#

oh

#

no you didnt

obsidian burrow
crystal flicker
#

there are no all the combinations

#

it might skip something

#

its only solvable with recursion

obsidian burrow
crystal flicker
#

all

#

all

obsidian burrow
#

then it shouldn't return a vector right?

crystal flicker
#

it should

obsidian burrow
#

oh wait nvm ik why

#

memo should contain all the solutions

crystal flicker
#

nah nah nah

#

just return the vector which sums up to target

#

thing is your once might skip some combinations that possibly can be an answer

#

oh wait

#

sry

obsidian burrow
#

so memo should contain all the vectors of solutions right?

crystal flicker
#

no

#

forget about it

obsidian burrow
crystal flicker
#

[2,3,5,6] target = 11

#

may return 2,3,6

#

or 5,6

obsidian burrow
#

but how can you do that in a vector<int>

#

you need to put all the solutions in a vector<vector<int>>

#

isn't this exactly what i wrote?

#

i don't get what is wrong

cloud tinselBOT
#

@crystal flicker

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. You can use !solved to close a post and mark it as solved.

crystal flicker
#

!solved