My generalized c++ version for k > 0


  • 0

    O(nlog(k)) time and O(k) space

    bool increasingTriplet(vector<int>& nums, int k = 3) {
        vector<int> inc(k - 1, INT_MAX);
        for (int i : nums) {
            auto p = lower_bound(inc.begin(), inc.end(), i);
            if (p == inc.end())
                return true;
            *p = i;
        }
        return false;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.