Corona Virus is really strange.
A strange species of Corona virus spreads as follows :-
- It spreads linearly and only in positive direction.
- Every second it does one of the two things -
- Jump exactly units taking 1 second thus increasing its position by units.
- Do not move at all.
Example: If it takes a jump at time sec then it's position will increase by units.
At time , Corona starts spreading from the position and Tango is sleeping at position .You have to tell if Corona can reach to Tango or not. If minimize the total time it takes and tell all such time instances at which corona jumps.
Example:
Input: n = 3
Output:
YES 2 0 1
Approach:
C++
#include <bits/stdc++.h>using namespace std;int main(){int n = 3;cout << "YES" << endl;cout << __builtin_popcount(n) << endl;int a[32] = {0};int i = 0;while (n > 0){a[i] = n % 2;n /= 2;i++;}for (int j = 0; j < i; j++){if (a[j] == 1)cout << j << " ";}return 0;}
No comments:
Post a Comment