Close

Check if a string is a double string

Given a string, we need to check if a string is a double string possibly by deleting a character. A double string is a repetition of two strings affixed together. For example the following strings are double strings “aa”, “meme”, “abbabb” Where as the follwing are not double strings “ab”, “abc”, “acbab” However “acbab” can…

Maximum increasing sub array

Given an array of numbers, how to find the maximum length of increasing (non-decreasing) continuous sub-sequence? For example consider the array [7, 9, 1, 3, 5, 8, 2], the maximum length is 4. Similarly for [23, 10, 18, 18, 6], it is 3. This is a straight forward implementation problem (appeared on Codeforces). Following is…

Decreasing string

Given a number K, Find the shortest and smallest string  which has K positions in it, such that the character at that position is alphabetically greater than the character immediately after it. Only the lower case alphabets [a-z] are allowed. For example consider K = 1 “ba” is the shortest and smallest string possible. There…

Up down array

Given an array of numbers A[N], how do we arrange them in the following order. A[0] <= A[1] >= A[2] <= A[3]…A[N-1] For example consider the array A =[6, 9, 36, 24, 42] The answer can be [6, 36, 9, 42, 24]. There can be multiple answers also like [6, 42, 9, 36, 24]. We…

Linear search

Given an array of numbers, how do we search for a given number? For example, given an array [6, 50, 24, 36, 42], the number 36 is present at the index 3 starting with 0. The number 17 is not present any where. The simplest algorithm to solve this problem is to check each element…