Category Archives: Arrays

Questions regarding Arrays

Count passing car pairs

A non-empty binary array A consisting of size N is given where, 0 represents a car traveling east, 1 represents a car traveling west. The goal is to count passing cars. We say that a pair of cars (P, Q), where 0

Find floor and ceil in an unsorted array

Given an unsorted array arr[] and an element x, find floor and ceiling of x in arr[0..n-1]. Floor of x is the largest element which is smaller than or equal to x. Floor of x doesn’t exist if x is smaller than smallest element of arr[]. Ceil of x is the smallest element which is… Read More »

Type of array and its maximum element

Given an array, it can be of 4 types (a) Ascending (b) Descending (c) Ascending Rotated (d) Descending Rotated Find out which kind of array it is and return the maximum of that array. Examples: Input : arr[] = { 2, 1, 5, 4, 3} Output : Descending rotated with maximum element 5 Input :… Read More »