Category Archives: Hash

Find the first repeated character in a string

Given a string, find the first repeated character in it. We need to find the character that occurs more than once and whose index of first occurrence is smallest. Examples: Input: ch = “geeksforgeeks” Output: e e is the first element that repeats Input: str = “hello geeks” Output: l l is the first element… Read More »

Recaman’s sequence

Given an integer n. Print first n elements of Recaman’s sequence. Examples: Input : n = 6 Output : 0, 1, 3, 6, 2, 7 Input : n = 17 Output : 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8 It is basically a function with… Read More »

Group words with same set of characters

Given a list of words with lower cases. Implement a function to find all Words that have the same unique character set . Example: Input: words[] = { “may”, “student”, “students”, “dog”, “studentssess”, “god”, “cat”, “act”, “tab”, “bat”, “flow”, “wolf”, “lambs”, “amy”, “yam”, “balms”, “looped”, “poodle”}; Output : looped, poodle, lambs, balms, flow, wolf, tab,… Read More »

Check if two arrays are equal or not

Given two given arrays of equal length, the task is to find if given arrays are equal or not. Two arrays are said to be equal if both of them contain same set of elements, arrangements (or permutation) of elements may be different though. Note : If there are repetitions, then counts of repeated elements… Read More »

Range Queries for Frequencies of array elements

Given an array of n non-negative integers. The task is to find frequency of a particular element in the arbitrary range of array[]. The range is given as positions (not 0 based indexes) in array. There can be multiple queries of given type. For example:- Input : arr[] = {2, 8, 6, 9, 8, 6,… Read More »