Find the Missing NumberGiven an array arr[] of size n-1 with distinct integers in the range of [1, n]. This array represents a permutation of the integers from 1 to n with one element missing. Find the missing element in the array.Examples: Input: arr[] = [8, 2, 4, 5, 3, 7, 1]Output: 6Explanation: All the numbers from 1 t
12 min read
Find the first repeating element in an array of integersGiven an array of integers arr[], The task is to find the index of first repeating element in it i.e. the element that occurs more than once and whose index of the first occurrence is the smallest. Examples: Input: arr[] = {10, 5, 3, 4, 3, 5, 6}Output: 5 Explanation: 5 is the first element that repe
8 min read
Missing and Repeating in an ArrayGiven an unsorted array of size n. Array elements are in the range of 1 to n. One number from set {1, 2, ...n} is missing and one number occurs twice in the array. The task is to find these two numbers.Examples: Input: arr[] = {3, 1, 3}Output: 3, 2Explanation: In the array, 2 is missing and 3 occurs
15+ min read
Count 1's in a sorted binary arrayGiven a binary array arr[] of size n, which is sorted in non-increasing order, count the number of 1's in it. Examples: Input: arr[] = [1, 1, 0, 0, 0, 0, 0]Output: 2Explanation: Count of the 1's in the given array is 2.Input: arr[] = [1, 1, 1, 1, 1, 1, 1]Output: 7Input: arr[] = [0, 0, 0, 0, 0, 0, 0]
7 min read
Pair with the given differenceGiven an unsorted array and an integer x, the task is to find if there exists a pair of elements in the array whose absolute difference is x. Examples: Input: arr[] = [5, 20, 3, 2, 50, 80], x = 78Output: YesExplanation: The pair is {2, 80}.Input: arr[] = [90, 70, 20, 80, 50], x = 45Output: NoExplana
14 min read
Kth smallest element in a row-wise and column-wise sorted 2D arrayGiven an n x n matrix, every row and column is sorted in non-decreasing order. Given a number K where K lies in the range [1, n*n], find the Kth smallest element in the given 2D matrix.Example:Input: mat =[[10, 20, 30, 40], [15, 25, 35, 45], [24, 29, 37, 48], [32, 33, 39, 50]]K = 3Output: 20Explanat
15+ min read
Ceiling in a sorted arrayGiven a sorted array and a value x, find index of the ceiling of x. The ceiling of x is the smallest element in an array greater than or equal to x. Note: In case of multiple occurrences of ceiling of x, return the index of the first occurrence.Examples : Input: arr[] = [1, 2, 8, 10, 10, 12, 19], x
13 min read
Floor in a Sorted ArrayGiven a sorted array and a value x, find the element of the floor of x. The floor of x is the largest element in the array smaller than or equal to x.Examples:Input: arr[] = [1, 2, 8, 10, 10, 12, 19], x = 5Output: 1Explanation: Largest number less than or equal to 5 is 2, whose index is 1Input: arr[
9 min read
Given Array of size n and a number k, find all elements that appear more than n/k timesGiven an array of size n and an integer k, find all elements in the array that appear more than n/k times. Examples:Input: arr[ ] = [3, 4, 2, 2, 1, 2, 3, 3], k = 4Output: [2, 3]Explanation: Here n/k is 8/4 = 2, therefore 2 appears 3 times in the array that is greater than 2 and 3 appears 3 times in
15+ min read