Data Structures & AlgorithmsHardGATE CS · TCS NQT
A cellular automaton of 6 cells starts as [1, 0, 0, 0, 0, 0]. In each step every cell becomes the XOR of its two neighbours (cells outside the line count as 0). After 2 steps, what is the number of cells equal to 1?
- A. 3
- B. 4
- C. 6
- D. 2
Correct answer: D. 2
Step one turns on cell 1; step two turns on cells 0 and 2, so two cells are 1. Updating cells in place instead of simultaneously gives a different result.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum number of swaps of two (not necessarily adjacent) elements needed to sort the permutation [4, 2, 5, 1, 3] (0-based…
- Which quantity gives the minimum number of arbitrary swaps needed to sort a permutation, and why is it correct?
- Counting ways to pay each amount 0..9 with coins [1, 4, 6]: version A loops over amounts (outer) and coins (inner), counting ordered…
- For the array [4, 2, 5, 3, 1, 6, 0], a 'next greater element' routine returns for each index the value of the next strictly larger element…
- A routine builds a list t: for each x in a, it appends x to t only if x is larger than the last element of t (otherwise it skips x), and…
- Items as (weight, value) are [(2, 3), (3, 4), (1, 1)]. The 0/1 knapsack table dp[c] for capacities c = 0..6 is built correctly by scanning…