Count occurrences of a number in a sorted array with duplicates
Given a sorted integer array containing duplicates, count occurrences of a given number. If the element is not found in the array, report that as well.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a sorted integer array containing duplicates, count occurrences of a given number. If the element is not found in the array, report that as well.
Given a circularly sorted integer array, search an element in it. Assume there are no duplicates in the array, and the rotation is in the anti-clockwise direction.
Given a sorted array of distinct positive integers, print all triplets that forms an arithmetic progression with an integral common difference.
Given a sorted array of distinct positive integers, print all triplets that forms a geometric progression with an integral common ratio.
Write a program to in-place remove all extra spaces from a string. There maybe leading spaces, trailing spaces, or consecutive spaces between words of the string.
Given an N × N matrix, find the maximum sum submatrix present in it.
Given an M × N matrix and two coordinates (p, q) and (r, s) representing top-left and bottom-right coordinates of a submatrix of it, calculate the sum of all elements present in the submatrix.
Given an M × N matrix, which is row-wise and column-wise sorted (with all strictly increasing elements in any row or column), report all occurrences of a given element in it in linear time.
An island is in the form of a square matrix, and a person is standing inside the matrix. The person can move one step in any direction (right, left, top, down) in the matrix. Calculate the probability that the person is alive after walking n steps on the island, provided that he dies if he steps outside the matrix.
Given an M × N binary matrix, replace all occurrences of 0’s by 1’s, which are not completely surrounded by 1’s from all sides (top, left, bottom, right, top-left, top-right, bottom-left, and bottom-right).
Given an M × N matrix, find all paths from the first cell to the last cell. We can only move down or to the right from the current cell.
Given an M × N matrix, print all its diagonal elements having a positive slope… The idea is to start from each cell of the first column of the matrix to print / diagonal for the matrix’s upper-left half.