๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.55K subscribers
5.58K photos
3 videos
95 files
9.91K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
sender_size = int(input())
senders = list(map(int, input().split()))
receiver_size = int(input())
receivers = list(map(int, input().split()))

n = sender_size
m = receiver_size

# Initialize a DP table with (n+1) rows and (m+1) columns
dp = [[0] * (m + 1) for _ in range(n + 1)]

for i in range(1, n + 1):
    for j in range(1, m + 1):
        if senders[i-1] == receivers[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

print(dp[n][m])

Flipkart โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    int k;
    cin >> k;

    bool all_positive = true;
    for (int x : arr) {
        if (x < 0) {
            all_positive = false;
            break;
        }
    }
    if (all_positive) {
        cout << endl;
        return 0;
    }

    vector<int> steps;
    vector<int> tmp = arr;

    for (int i = 0; i < n - 1; ++i) {
        if (tmp[i] < 0) {
            tmp[i] *= -1;
            tmp[i + 1] *= -1;
            steps.push_back(i + 1); // Convert to 1-based index
        }
    }

    if (tmp.back() < 0) {
        tmp.back() *= -1;
        steps.push_back(n);
    }

    if (steps.size() > k) {
        cout << -1 << endl;
    } else {
        for (size_t i = 0; i < steps.size(); ++i) {
            if (i > 0) cout << " ";
            cout << steps[i];
        }
        cout << endl;
    }

    return 0;
}
Flipkart โœ…
๐Ÿ‘2