You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Mock Test/1.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,35 @@ function cellCompete(states, days)
27
27
28
28
}
29
29
```
30
+
```
31
+
// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
32
+
// SOME FUNCTIONALITY WITHIN A PACKAGE MAY BE RESTRICTED
33
+
// DEFINE ANY FUNCTION NEEDED
34
+
// FUNCTION SIGNATURE BEGINS, THIS FUNCTION IS REQUIRED
35
+
function cellCompete(states, days)
36
+
{
37
+
let c=0;
38
+
while(days--){
39
+
for(var i=0;i<states.length;i++){
40
+
if(i===0){
41
+
a=0;
42
+
}else{
43
+
a=c;
44
+
}
45
+
if(i===states.length -1){
46
+
b=0;
47
+
}else{
48
+
b=states[i+1];
49
+
}
50
+
c = states[i];
51
+
states[i] = a ^ b;
52
+
}
53
+
}
54
+
return states;
55
+
56
+
}
57
+
// FUNCTION SIGNATURE ENDS
58
+
```
30
59
// Eight houses, represented as cells, are arranged in a straight line. Each day every cell competes with its adjacent cells (neighbors). An integer value of 1 represents an active cell and a value of 0 represents an inactive cell. If the neighbors on both the sides of a cell are either active or inactive, the cell becomes inactive on the next day; otherwise the cell becomes active. The two cells on each end have a single adjacent cell, so assume that the unoccupied space on the opposite side is an inactive cell. Even after updating the cell state, consider its previous state when updating the state of other cells. The state information of all cells should be updated simultaneously.
0 commit comments