Sort by

recency

|

2032 Discussions

|

  • + 0 comments

    [https://ai-trader.ai/](is an advanced trading platform that combines AI-driven automation with human expertise to simplify financial market complexities. It provides intelligent tools and data-driven insights, enabling traders to make informed decisions with confidence. Designed for both beginners and professionals, AI-Trader enhances efficiency, minimizes risks, and optimizes trading strategies. With real-time analytics and automated solutions, it streamlines trading for maximum profitability. Experience the future of smart trading with AI-Trader—where innovation meets financial success.

  • + 0 comments

    Here is the solution of Dynamic array in C, C++, Java, Javascript, Python Click Here

  • + 0 comments

    Here's the C solution I came up with. Any feedback would be greatly appreciated!

    void append(int** pparr, int* psize, int pos, int ele) {
        int size = psize[pos] + 1;
        psize[pos] = size;
        pparr[pos] = (int*)realloc(pparr[pos], sizeof(int) * size);
        int* parr = pparr[pos];
        parr[size - 1] = ele;
    }
    
    int* dynamicArray(int n, int queries_rows, int queries_columns, int** queries, int* result_count) {
        int count = 0;
        int** pparr = (int**)malloc(sizeof(int*) * n);
        int* panswer = (int*)malloc(sizeof(int) * n);
        int* psize = (int*)malloc(sizeof(int) * n);
        for (int i = 0; i < n; i++) {
            psize[i] = 0;
            pparr[i] = NULL;
        }
    
        int lastAnswer = 0;
        int queryType, x, y, idx;
        for (int i = 0; i < queries_rows; i++) {
            queryType = queries[i][0];
            x = queries[i][1];
            y = queries[i][2];
            idx = (x ^ lastAnswer) % n;
            if (queryType == 1) {
                append(pparr, psize, idx, y);
            } else {
                lastAnswer = pparr[idx][y % psize[idx]];
                panswer[count] = lastAnswer;
                count++;
            }
        }
        for (int i = 0; i < n; i++)
            free(pparr[i]);
        free(psize);
        free(pparr);
        panswer = (int*)realloc(panswer, sizeof(int) * count);
        *result_count = count;
        return panswer;
    }
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/MYdQxgmJ4Sk

    vector<int> dynamicArray(int n, vector<vector<int>> queries) {
        int lastAnswer = 0;
        vector<int> result;
        vector<vector<int>> arr(n);
        for(auto query: queries) {
            int type = query[0], x = query[1], y = query[2];
            int idx = (x ^ lastAnswer) % n;
            if(type == 1) {
                arr[idx].push_back(y);
            }
            else {
               lastAnswer = arr[idx][y % arr[idx].size()];
               result.push_back(lastAnswer);
            }
        }
        return result;
    }
    
  • + 0 comments

    A little remind: You need to modulo the index with n to prevent out of bounds. Thanks me later xD