hi, let Avik connect you.


** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.

** You can check all the posts on the Posts page.

** More about me in the About Me section.

Ninja And His Old Friends


  • Approach:

    1. Traversed through the given list of happiness values.

    2. For ith happiness value, if K matches then double the K.

    3. Return K after completion of traversal.


  • Time and Space Complexity:

      • Time Complexity: O(N)

      • Space Complexity: O(1)


Code [C++]

#include <bits/stdc++.h>

int shakeHands(vector<int> &friends ,int n, int k)

{

for(int i=0; i<n; i++){

if(friends[i] == k) k+=k;

}

return k;

}