Category Archives: Data Structures

Smallest window in a String containing all characters of other String

Given two strings string1 and string2, the task is to find the smallest substring in string1 containing all characters of string2. Examples : Input: string = “Cplusplus is the best”, pattern = “pp” Output: Smallest window is : plusp Explanation: “plusp” contains all the characters of pattern. Input: string = “Cplusplus”, pattern = “Cpp” Output: Smallest window is… Read More »

Find Index of Unique element in Array with duplicate elements

Given an array of size N, print the index of the distinct element from the array, provided the array has only one distinct element and rest other elements are same. Examples: Input: Arr[]={10,10,10,10,20} Output: Distinct Element found at index : 4 Input: Arr[]={7,7,7,0,7,7,7,7} Output: Distinct Element found at index : 3 Approach: Linearly traverse through the array and… Read More »