Number of Islands

In this tutorial, I am going to discuss a very famous interview problem. How to count the number of islands.

Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.

You may assume all four edges of the grid are surrounded by water.

Find All Duplicates in an Array

How to find all duplicates in an array without using extra space?

Given an array of integers, the integers are in the range of 1 ≤ a[i] ≤ n (n = size of array). In this Array, some elements appear twice and others appear once.

Find all the elements that appear twice in this array.

We have to solve this problem without using extra space and in O(n) time complexity.

For Example:

Input: [4, 3, 2, 7, 8, 2, 3, 1]

Output: [2, 3]

Valid Palindrome

Valid palindrome.

Given an input string. We have to write a code to check if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For this problem, consider the empty string as a valid palindrome.

For Example –

Example 1:

Input: “A man, a plan, a canal: Panama”
Output: true

Explanation: After removing non-alphanumeric characters, the string is amanaplanacanalpanama. So, it’s a palindrome

Example 2:

Input: “race a car”
Output: false