Data Structures & AlgorithmsHardTCS NQT · Accenture
The 0/1 grid [[1,1,0],[0,1,0],[1,0,1]] is given. Two 1-cells belong to the same island if they are adjacent horizontally or vertically. How many islands are there?
- A. 4
- B. 5
- C. 7
- D. 3
Correct answer: D. 3
The cells (0,0), (0,1) and (1,1) form one island, (2,0) is another, and (2,2) is a third. Diagonal neighbours are not connected.
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
- Two numbers are stored as linked lists of digits, least significant digit first: 9 -> 9 -> 9 and 1. Their sum is added digit by digit with…
- How many index pairs i < j in [3, 4, 2, 6, 1, 2, 12, 1] have a[i] a[j] = 12?
- How many distinct strings of length 3 are palindromes that occur as subsequences of abcab (of the form x y x with y different from x)?
- What is the length of the longest palindromic subsequence of the string leetcode?
- How many contiguous non-empty substrings of aaabbbaa consist of a single repeated letter?
- What is the sum of the distinct prime divisors of 2310?