Largest Pair Sum | GFG Problem of the Day | Arrays | gfg potd

Поделиться
HTML-код
  • Опубликовано: 7 окт 2024

Комментарии • 3

  • @codetips-byRochak
    @codetips-byRochak  21 час назад

    Let's Connect 🤝 :
    LinkedIn : www.linkedin.com/in/rochak-vyas17/
    Code :-
    class Solution {
    public:
    int pairsum(vector &arr) {
    int n=arr.size();
    int maxi=INT_MIN;
    for(int i=0;imaxi){
    maxi=arr[i];
    }
    }
    int secmaxi=INT_MIN;
    for(int i=0;isecmaxi&&arr[i]

  • @dhairyapandya5550
    @dhairyapandya5550 13 часов назад

    Instead of using O(2N).
    I have solved it in O(N), here is my approach
    class Solution {
    public:
    int pairsum(vector &arr) {
    // code here
    int greater1=arr[0];
    int greater2=arr[1];
    int n=arr.size();
    for(int i=2;i

    • @codetips-byRochak
      @codetips-byRochak  13 часов назад +1

      Yes, so instead of using two for loops, you have written multiple if else condition inside one for loop. So yeah that's great, and thanks for your kind words.😀