## Recent Interview Questions

More Questions »- 0of 0 votes
Given a array of positive integers, find all possible triangle triplets that can be formed from this array.

eg: 9 8 10 7

ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10

Note : array not sorted, there is no limit on the array length

- 0of 0 votes
Integer V lies strictly between integers U and W if U < V < W or if U > V > W.

A non-empty zero-indexed array A consisting of N integers is given. A pair of indices (P, Q), where 0 = P < Q < N, is said to have adjacent values if no value in the array lies strictly between values A[P] and A[Q], and in addition A[P] ? A[Q].

For example, in array A such that:

A[0] = 0

A[1] = 3

A[2] = 3

A[3] = 7

A[4] = 5

A[5] = 3

A[6] = 11

A[7] = 1

the following pairs of indices have adjacent values:

(0, 7), (1, 4), (1, 7),

(2, 4), (2, 7), (3, 4),

(3, 6), (4, 5), (5, 7).

For example, indices 4 and 5 have adjacent values because the values A[4] = 5 and A[5] = 3 are different, and there is no value in array A that lies strictly between them - the only such value could be the number 4, which is not present in the array.

Given two indices P and Q, their distance is defined as abs(P-Q), where abs(X) = X for X = 0, and abs(X) = -X for X < 0. For example, the distance between indices 4 and 5 is 1 because abs(4 - 5) = (5 - 4) = 1.

Write a function:

int solution(int A[], int N);

that, given a non-empty zero-indexed array A consisting of N integers, returns the maximum distance between indices of this array that have adjacent values. The function should return -1 if no adjacent indices exist.

For example, given array A such that:

A[0] = 1

A[1] = 4

A[2] = 7

A[3] = 3

A[4] = 3

A[5] = 5

the function should return 4 because:

indices 0 and 4 are adjacent because A[0] ? A[4] and the array does not contain any value that lies strictly between A[0] = 1 and A[4] = 3;

the distance between these indices is abs(0 - 4) = 4;

no other pair of adjacent indices that has a larger distance exists.

Assume that:

N is an integer within the range [1..40,000];

each element of array A is an integer within the range [-2,147,483,648..2,147,483,647].

Complexity:

expected worst-case time complexity is O(N*log(N));

expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).

Elements of input arrays can be modified.

- 1of 1 vote
Given an array of type:-

1. Increasing

2. Decreasing.

3. Increase-Decrease

4. Decrease-Increase

Find:- 1. Type of array in minimum steps ?

2. Maximum element from array in min steps?

- 1of 1 vote
Question was "Given a pattern and a string input - find if the string follows the same pattern and return 0 or 1.

Examples:

1) Pattern : "abba", input: "redblueredblue" should return 1.

2) Pattern: "aaaa", input: "asdasdasdasd" should return 1.

3) Pattern: "aabb", input: "xyzabcxzyabc" should return 0.

I can think of a brute-force solution for this question where we add the character in the pattern and n length of the string to a hashmap and recurse over the pattern array and string. But is there anything more efficient? This was a pretty difficult question in my opinion.

- 0of 0 votes
Given an array of integers when the difference between every two neighbored elements is either -1 or +1 or 0.

Write an efficient search algorithm to find a given number of x in the array.