Seeking Help with Longest Increasing Subsequence in C++
#1
Hello everyone,

I've been trying to implement the Longest Increasing Subsequence in C++ algorithm after reading about Longest Increasing Subsequence C++.

I'm having some trouble with my code, and I was wondering if someone could help me out. Here's the C++ code I've written so far:
PHP Code:
#include <iostream>
#include <vector>

using namespace std;

int longestIncreasingSubsequence(vector<int>& nums) {
    int n nums.size();
    vector<intdp(n1);

    for (int i 1ni++) {
        for (int j 0ij++) {
            if (nums[i] > nums[j]) {
                dp[i] = max(dp[i], dp[j] + 1);
            }
        }
    }

    int maxLen 0;
    for (int i 0ni++) {
        maxLen max(maxLendp[i]);
    }

    return maxLen;
}

int main() {
    vector<intnums = {10229332150416080};
    int result longestIncreasingSubsequence(nums);
    cout << "The length of the longest increasing subsequence is: " << result << endl;
    return 0;

My code is close to the correct solution, but I'm not getting the expected output. Can someone please review my code and point out where I might be going wrong? Any help or suggestions would be greatly appreciated.
Reply
#2
I was wondering if someone could assist me since I'm experiencing some issues with my coding. This is the C++ code that I have so far written. phrazle
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with Longest Increasing Subsequence Algorithm Avantika_Sharmaa24 1 7,341 Sep 26, 2023, 07:15 am
Last Post: gulshan212



Users browsing this thread: 1 Guest(s)