Skip to content

Instantly share code, notes, and snippets.

@midorikocak
Created November 17, 2017 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save midorikocak/76f6dddca41c85d4b0fb62a6c4839813 to your computer and use it in GitHub Desktop.
Save midorikocak/76f6dddca41c85d4b0fb62a6c4839813 to your computer and use it in GitHub Desktop.
Amazon Practice 1
// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
import java.util.*;
import java.util.Arrays;
import java.util.List;
// SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
// DEFINE ANY CLASS AND METHOD NEEDED
// CLASS BEGINS, THIS CLASS IS REQUIRED
public class Solution
{
// METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
public List<Integer> cellCompete(int[] states, int days)
{
for(int j=0; j<days; j++){
int[] nextDay = new int[states.length];
for(int i=0; i<states.length; i++){
int next;
int previous;
if(i==0){
previous = 0;
}
else{
previous = states[i-1];
}
if(i==states.length-1){
next = 0;
}
else{
next = states[i+1];
}
if(previous==next){
nextDay[i] = 0;
}
else{
nextDay[i] = 1;
}
}
states = nextDay;
}
return this.toList(states);
}
public List<Integer> toList(int[] ints)
{
List<Integer> intList = new ArrayList<Integer>();
for (int index = 0; index < ints.length; index++)
{
intList.add(ints[index]);
}
return intList;
}
// METHOD SIGNATURE ENDS
}
@oneclose-ankitabiswas
Copy link

Is the following code is being run at the running or compiling mode!

yes. You have to importthe class though

import java.util.ArrayList;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment