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
Problem: Ninja And His Old Friends
Problem Link: https://www.codingninjas.com/codestudio/problems/ninja-and-his-old-friends_1214934
Approach:
Traversed through the given list of happiness values.
For ith happiness value, if K matches then double the K.
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;
}