Computer Science, asked by varnalatha, 5 months ago

Function F(K) is defined for non-negative integers as follows:
• F(K) = 0 when K = 0
• F(K) = F(K-1) + K when K> 0
Write a function:
class Solution { public int solution(int N); }
that, given a non-negative integer N, returns the largest non-
negative integer L such that F(L) SN.
For example, given N = 17 the function should return 5, because
F(5) = 15, and F(K) > 17 for all integers K greater than 5.
Write an efficient algorithm for the following assumptions:
• Nis an integer within the range (0..1,000,000,000).
Copyright 2009-2020 by Codility Limited. All Rights Reserved. Unauthorized
copying, publication or disclosure prohibited.​

Answers

Answered by cyberdon333
8

Answer:

class Solutions {

public int solutions(int N)

{

if(N==0)return 0;

int sum=0;

for(int i=1;i<n/2;i++)

{

sum+=i;

if(sum>N)

return i-1;

}

}

}

Explanation:

Similar questions