Tle :(   What could be the reason for this?
class Solution {\npublic:\n    int getWinner(vector& arr, int k) {\n        int n = arr.size();\n        int maximum = INT_MIN;\n         for(int i=0;imaximum){
class Solution {\npublic:\n    int getWinner(vector<int>& arr, int k) {\n        int n = arr.size();\n        int maximum = INT_MIN;\n         for(int i=0;i<n;i++){\n             if(arr[i]>maximum){\n                 maximum = arr[i];\n             }\n         }\n        \n        if(k>=n-1){\n              return maximum;\n        }\n        \n        if(k==1){\n            return max(arr[0],arr[1]);\n        }\n        \n    int first = 0;\n        int second = 1;\n        int last = -1;\n        int count  = 0;\n        bool can = false;\n        int ans = -1;\n        while(can==false){\n            if((arr[first]==maximum) || (arr[second]==maximum)){\n                ans = maximum;\n                can = true;\n                break;\n            }\n            \n            if(arr[first]>arr[second]){\n                if(last!=-1 && last!=arr[first]){\n                    count = 0;\n                }\n                \n                count++;\n                last = arr[first];\n                second++;\n                if(count==k){\n                    can = true;\n                    ans = last;\n                    break;\n                }\n            }\n            \n                if(arr[second]>arr[first]){\n                if(last!=-1 && last!=arr[second]){\n                    count = 0;\n                }\n                \n                count++;\n                last = arr[second];\n                first = second + 1;\n                if(count==k){\n                    can = true;\n                    ans = last;\n                    break;\n                }\n            }\n            \n            \n        }\n        \n        return ans;\n        \n        \n    }\n};
[]