Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down, left, right) all exist and are also 1. How many pluses are in the matrix?
- A. 0
- B. 1
- C. 2
- D. 3
Correct answer: A. 0
Test each interior cell whose four neighbours exist. Border cells can never be plus centres, since one neighbour lies outside the matrix.
More Coding Interview Problems questions
- Problem: Two heaps are maintained over the stream 5, 15, 1, 3, 8, 7, 9, 10, 6, 11 to report the median after each element (lower median…
- Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that…
- Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a…
- Problem: The string "xyyxzzyx" is examined for palindromic substrings of length 4 or more. How many such palindromic substrings are there…
- Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?
- Problem: A process list is [3, 7, 2, 9] with priorities; the CPU always runs the largest value next and runs it for its full value, then…