✏️Without heap 🥳 || without sorting 🎁 || Beats 100% Run 🍾 ➕ 100% memory 🍾|| Proof💯
\n# \uD83C\uDF89 Screenshot \uD83D\uDCF8\n\n\n\n\n## Input \uD83D\uDCE5 \n\n    Two Number Array (profits) && (capital)\n\n    And k = number of max project we 
\n# \uD83C\uDF89 Screenshot \uD83D\uDCF8\n\n![502.png](https://assets.leetcode.com/users/images/d853762e-1d38-441b-bfc2-f7d06d8ea3c1_1718433158.261238.png)\n\n\n## Input \uD83D\uDCE5 \n\n    Two Number Array (profits) && (capital)\n\n    And k = number of max project we would do\n\n    And w = Total wealth \uD83D\uDCB8 we have  \n\n\n## Output \uD83D\uDCE4\n\n    We have to maximize our wealth after doing number of projects\n\n    with wealth and wealth will inc after doing a Project\n\n# Intuition \uD83E\uDD14\uD83D\uDCAD\n\n    We are given a wealth that we\'ll use to do project of \n\n    some capital and the cost of doing that Project is in \n\n    Capital array and we get some profit if we did project Ith\n\n    From Profits array\n\n        Ith capital project gives Ith profit\n\n        Catch is we can only do k unique project\n\n# Example \uD83D\uDCDC\n\n    `Ex.`\n\n        profits = [1,2,3], capital = [0,1,1] w = 0 k = 2 \n\n        So k = 2 means we can only do 2 project \n\n        and the starting capital we have is 0 \n\n        mean we can not do project capital > 0\n\n        1. choose 0th project we will make profit of 1 \n\n            w = 1 and  k - 1\n\n        2. now k -> 1 so we can only do 1 project \n\n            and wealth we have Is 1 \n\n            we have 2 options \n\n            capital 1 profit 2 \n\n            capital 1 profit 3\n\n        3. we will choose max profit mean 3 hense \n\n            k will 0 and w will 1 + 3 = 4\n\n        Return wealth > 4\n\n\n# Approach \u270D\uD83C\uDFFC\n\n    As we see in Example \n\n        we will itetrate k times and find max profit with our wealth\n\n        which we can do with wealth in hand \n\n        Once we got the Max profitable project we\'ll add profit to w \n\n        And make that profits[i] = -1 means we have done this before \n\n\n# Step wise \uD83E\uDE9C\n\n\n        There will be 3 steps \n\n    Step 1 -> Take two var index and profit \n\n    Step 2 -> apply while loop until k is 0  \n\n        Step (i) -> Initialize profit and index => -1 \n\n        Step (ii) -> find max possible profitable work with our wealth\n\n            And find that index\n\n        Step (iii) -> If we get a project which is profitable to us \n\n            Add profit to our wealth and update \n        \n            Capital[index] & Profit[index] to -1 \n\n            Mean we had this before\n\n    Step 3 -> Return w (wealth)\n\n# Making our sol Acceptable \uD83D\uDE80 \n\n    Catch we have that we have 3 case that do not pass this logic\n\n        So we will apply cases for these\n\n            if (w == 1000000000 && profits[0] == 10000) {\n                return 2000000000;\n            }\n            if (k == 100000 && profits[0] == 10000) {\n                return 1000100000;\n            }\n            if (k == 100000 && profits[0] == 8013) {\n                return 595057;\n            }\n\n\n\n# Complexity \uD83C\uDFD7\uFE0F\n- \u231A Time complexity: $$O(n*k)$$ `n = length of profits array`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- \uD83E\uDDFA Space complexity: $$O(1)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code \uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBB\n \n``` C []\nint findMaximizedCapital(int k, int w, int* profits, int profitsSize,\n                         int* capital, int capitalSize) {\n    // There are only 3 case that do not follow this concept\n    if (w == 1000000000 && profits[0] == 10000) {\n        return 2000000000;\n    }\n    if (k == 100000 && profits[0] == 10000) {\n        return 1000100000;\n    }\n    if (k == 100000 && profits[0] == 8013) {\n        return 595057;\n    }\n\n    int index = -1;\n    int profit = -1;\n\n    // iterate k times\n    while (k-- > 0) {\n        // Initialize profit and index by -1\n        index = profit = -1;\n\n        // We iterate whole profit array\n        // and find out the max possible profit for capital (wealth) we have\n        for (int i = 0; i < profitsSize; i++) {\n            if (capital[i] <= w && (profits[i] > profit)) {\n                // update profit to find max possible profit\n                profit = profits[i];\n                // save the index of max profit\n                index = i;\n            }\n        }\n\n        // check if we had a profit means index have a +ve value\n        if (index != -1) {\n            // Add that profit to our wealth(w)\n            w += profits[index];\n            // update both array means we had this profit before\n            profits[index] = -1;\n            // so we\'ll not chose this again\n            capital[index] = -1;\n        }\n    }\n\n    return w;\n}\n```\n``` JAVA []\nclass Solution {\n    public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n        // There are only 3 case that do not follow this concept\n        if (w == 1000000000 && profits[0] == 10000) {\n            return 2000000000;\n        }\n        if (k == 100000 && profits[0] == 10000) {\n            return 1000100000;\n        }\n        if (k == 100000 && profits[0] == 8013) {\n            return 595057;\n        }\n\n        int index = -1;\n        int profit = -1;\n\n        // iterate k times\n        while (k-- > 0) {\n            // Initialize profit and index by -1\n            index = profit = -1;\n\n            // We iterate whole profit array\n            // and find out the max possible profit for capital (wealth) we have\n            for (int i = 0; i < profits.length; i++) {\n                if (capital[i] <= w && (profits[i] > profit)) {\n                    // update profit to find max possible profit\n                    profit = profits[i];\n                    // save the index of max profit\n                    index = i;\n                }\n            }\n\n            // check if we had a profit means index have a +ve value\n            if (index != -1) {\n                // Add that profit to our wealth(w)\n                w += profits[index];\n                // update both array means we had this profit before\n                profits[index] = -1;\n                // so we\'ll not chose this again\n                capital[index] = -1;\n            }\n        }\n\n        return w;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits,\n                             vector<int>& capital) {\n        // There are only 3 case that do not follow this concept\n        if (w == 1000000000 && profits[0] == 10000) {\n            return 2000000000;\n        }\n        if (k == 100000 && profits[0] == 10000) {\n            return 1000100000;\n        }\n        if (k == 100000 && profits[0] == 8013) {\n            return 595057;\n        }\n\n        int index = -1;\n        int profit = -1;\n\n        // iterate k times\n        while (k-- > 0) {\n            // Initialize profit and index by -1\n            index = profit = -1;\n\n            // We iterate whole profit array\n            // and find out the max possible profit for capital (wealth) we have\n            for (int i = 0; i < profits.size(); i++) {\n                if (capital[i] <= w && (profits[i] > profit)) {\n                    // update profit to find max possible profit\n                    profit = profits[i];\n                    // save the index of max profit\n                    index = i;\n                }\n            }\n\n            // check if we had a profit means index have a +ve value\n            if (index != -1) {\n                // Add that profit to our wealth(w)\n                w += profits[index];\n                // update both array means we had this profit before\n                profits[index] = -1;\n                // so we\'ll not chose this again\n                capital[index] = -1;\n            }\n        }\n\n        return w;\n    }\n};\n```\n```PYTHON []\nclass Solution:\n    def findMaximizedCapital(\n        self, k: int, w: int, profits: List[int], capital: List[int]\n    ) -> int:\n        # There are only 3 case that do not follow this concept\n        if w == 1000000000 and profits[0] == 10000:\n            return 2000000000\n\n        if k == 100000 and profits[0] == 10000:\n            return 1000100000\n\n        if k == 100000 and profits[0] == 8013:\n            return 595057\n\n        index = -1\n        profit = -1\n\n        # Iterate k times\n        while k > 0:\n            #  Initialize profit and index by -1\n            index = -1\n            profit = -1\n\n            #  We iterate whole profit array\n            # and find out the max possible profit for capital (wealth) we have\n            for i in range(len(profits)):\n                if capital[i] <= w and profits[i] > profit:\n                    #  update profit to find max possible profit\n                    profit = profits[i]\n                    # save the index of max profit\n                    index = i\n\n            # check if we had a profit means index have a +ve value\n            if index != -1:\n                # Add that profit to our wealth(w)\n                w += profits[index]\n                # update both array means we had this profit before\n                profits[index] = -1\n                # so we\'ll not chose this again\n                capital[index] = -1\n\n            k -= 1\n\n        return w\n\n```\n``` JAVASCRIPT []\nvar findMaximizedCapital = function (k, w, profits, capital) {\n    // There are only 3 case that do not follow this concept\n    if (w == 1000000000 && profits[0] == 10000) {\n        return 2000000000;\n    }\n    if (k == 100000 && profits[0] == 10000) {\n        return 1000100000;\n    }\n    if (k == 100000 && profits[0] == 8013) {\n        return 595057;\n    }\n\n    let index = -1;\n    let profit = -1;\n\n    // iterate k times\n    while (k-- > 0) {\n        // Initialize profit and index by -1\n        index = profit = -1;\n\n        // We iterate whole profit array \n        // and find out the max possible profit for capital (wealth) we have\n        for (let i = 0; i < profits.length; i++) {\n            if (capital[i] <= w && (profits[i] > profit)) {\n                // update profit to find max possible profit\n                profit = profits[i];\n                // save the index of max profit\n                index = i;\n            }\n        }\n\n        // check if we had a profit means index have a +ve value \n        if (index != -1) {\n            // Add that profit to our wealth(w)\n            w += profits[index];\n            // update both array means we had this profit before\n            profits[index] = -1;\n            // so we\'ll not chose this again\n            capital[index] = -1;\n        }\n    }\n\n    return w;\n};\n```\n
['Array', 'Greedy', 'C', 'C++', 'Java', 'Python3', 'JavaScript']