Step by Step
https://www.interviewbit.com/old/problems/step-by-step/
https://www.interviewbit.com/old/problems/step-by-step/
- int Solution::solve(int N) {
- N = abs(N);
- int i = 1 ;
- int s = 0 ;
- while( s< N || (s-N) % 2 != 0 )s+=i++ ; //while the sum is less than the no and if the
- //difference between sum and no is odd then we need to increment i
- return i-1 ;
- }
Comments
Post a Comment