Skip to content

Instantly share code, notes, and snippets.

@meetkool
Last active October 8, 2025 13:04
Show Gist options
  • Save meetkool/aa95840ab57e9f4cb2f35cc68081faf6 to your computer and use it in GitHub Desktop.
Save meetkool/aa95840ab57e9f4cb2f35cc68081faf6 to your computer and use it in GitHub Desktop.
[BLOG] Untitled Post
title location images tags privacy createdAt updatedAt
Untitled Post
19.2145, 72.9604
blog
quick-post
public
2025-10-08 13:03:57 UTC
2025-10-08 13:04:41 UTC

https://simplecode.co.in/problems/195

#include <vector>
using namespace std;

class Solution {
public:
    vector<int> findMaxAndSecondMax(vector<int>& nums) {
        int max=INT_MIN;
        vector<int> rsl(2,INT_MIN);
        for(int i=0;i<nums.size();i++){
            if(max<nums[i]){
                rsl[1]=max;
                max=nums[i];
                rsl[0]=max;
            }else if (nums[i] > rsl[1] && nums[i] < max){
                rsl[1] = nums[i];
            }
        }

        if(rsl[1]==INT_MIN){
            rsl[1] = nums[0];
        }

        return rsl;
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment