Created
May 5, 2015 19:06
-
-
Save stephen-maina/951a339c964469e7894b to your computer and use it in GitHub Desktop.
O(N+M) out of memory error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
class Solution { | |
public int solution(int N, int M) { | |
// write your code in Java SE 8 | |
int index=0; | |
int count=0; | |
int [] test=IntStream.rangeClosed(0,N-1).toArray(); | |
while(test[index]!=-1){ | |
test[index]=-1; | |
count++; | |
index=(index+M)%N; | |
if(index>N-1){ | |
index=index-N-2; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment