multiverseweb / CodeIt

CodeIt is a software solution tool designed to streamline and enhance the coding experience for developers. It addresses several common challenges faced when working with coding platforms, such as LeetCode, and offers a range of features to improve code management, security, and performance analysis.
https://codeittool.netlify.app
MIT License
44 stars 77 forks source link

Wrong TimeComplexity Analyser #197

Open eeshwar369 opened 6 hours ago

eeshwar369 commented 6 hours ago

include

using namespace std;

class Solution { public: int findgpd(int a, int b) { int ans = 0; for (int i = b; i > 1; --i) { if (a % i == 0) { ans = i; break; } } return ans; }

int minOperations(vector<int>& a) {
    int n = a.size();
    int res = 0;
    int p = a[n - 1]; // Start with the last element

    for (int i = n - 2; i >= 0; --i) {
        if (a[i] > p) {
            res++;
            int t = findgpd(a[i], a[i + 1]);
            if (t == 0) return -1;
            a[i] = t;
            if (a[i] == 1) break;
            p = a[i]; // Update p
        } else {
            p = a[i]; // Update p
        }
    }

    // Check if the array is non-decreasing
    for (int i = 1; i < n; ++i) {
        if (a[i] < a[i - 1]) return -1;
    }

    return res;
}

};

Expecting O(n) time complexity due to single loop but is it so? Issue

eeshwar369 commented 6 hours ago

Wrong Time Complexity Analyser

github-actions[bot] commented 6 hours ago

👋 Thank you for raising an issue! We appreciate your effort in helping us improve. Our CodeIt team will review it shortly. Stay tuned!

multiverseweb commented 4 hours ago

Hey @eeshwar369, I understand that the Time Complexity Analyser is noy accurate. But the time complexity of the code in you issue is o(n) and that's what the Analyser is showing? 😕

Would you like to work on this issue? (increasing the accuracy of analyser)

eeshwar369 commented 4 hours ago

The Issue here is that the time complexity is being analysed only with the loops but the time complexity of functions in it are not getting analysed and yes,I would work to improve the accuracy of this .