## Arrays Interview Questions

- -1of 1 vote
I was asked the following: Given integers N and A. Find how many integer sequences with elements between 1 and A have sum of all elements equals to N.

N, A <= 1000.

Sample input: 4 3 , sample output is 7.

In this moment, I realized I do not understand the question. If I have a sequence of 1,2,3, the only sub-sequence that sums 4 is 1,3. So the answer should be 1. What am I missing?

Thank you

- 0of 0 votes
Given an array of integers, design an algorithm that moves all non-zero integers to the end of the array. Minimize the number of writes or swaps.

- 1of 1 vote
You are given an array of integers(with all valid input) You have to write a function which will produce another array, where the value in each index of the array will be the product of all values in the given array accept that index.

Example

Array 1: 1 2 3 4 5

Array 2: 120 60 40 30 24.

Come up with a solution of O(n^2) can you improve it?

- 0of 0 votes
Given an array of random numbers, shuffle the numbers once again with the least possibility of it being same as previous configuration.

- 0of 0 votes
Q. Given an array of numbers. Print all the pairs (2) of numbers in the array if the sum of those numbers is also present in the array. Write in C

- 1of 1 vote
Return the pivot index of the given array of numbers. The pivot index is the index where the sum of the numbers on the left is equal to the sum of the numbers on the right. Input Array {1,2,3,4,0,6}

- 0of 0 votes
You are given an array of positive and negative integers. If a number n at an index is positive, then move forward n steps. Conversely, if it's negative, move backward n steps. Determine if there is a loop in this array.

For example, given the array [2, -1, 1, 2, 2], index 0 maps to index 2, 1 maps to 0, 2 maps to 3, and so on. There is a loop in this array because 0 maps to 2, 2 maps to 3, and 3 maps to 0 (use the modulo operator).

- 0of 0 votes
Given an array, move the smaller no to the left and the larger nos to the right. The relative positioning between the small no's and the relative positions between the large nos should not change.

The original ( ill formulated ) question can be found here :

question?id=5756583549075456.

Example :`a = [ 6 4 5 0 2 1 11 -1 ] after_a = [ 0 , 2, 1, -1, 6, 4, 5, 11 ]`

Note, for lack of good explanation, please do not laugh at the poster in the solutions. After all, they are trying to help or get help.

- 0of 0 votes
CAREERCUP is a boad game hat contains m x n on a board. The objective of the CAREERCUP game is to reach the bottom of he board (bottom right corner) from the top of the board (top left corner) while moving one grid at a ime in either the down, right or diagonally downwrd directions.

Write a method called CareerSolution that takes in two integers representing m and n, and returns the total number of ways a player can complete the game.

PS: Was later asked to optimize the solution.

int CareerSolution(int m, int n) {

}

- 1of 1 vote
Let's say I have a word "I love chicken", I can break the number of characters in each word, like so: [1] [4] [7]

[1,4] [4,7], [1,4,7].

Now let's say I have a max = 5. The phrases with equal or fever than 5 characters are "[I], [love], and [I, love]. The longest phrase is [I,love], which contains 2 words.

Complete the Length function given. It has 2 parameters:

1) An array of integers, named array

2) A maximum number, named max.

int Careercup( int [] array, int max) {

}

Example test case 1:

[3,1,2,3]

4

Output expected : 2

- 0of 0 votes
you have a array nums as input. For any i from 0 to length - 1. should print product of whole array except nums[i]

For example: nums = [2,3,1,4,3,2]

output:

72

48

144

36

48

72

- -2of 2 votes
Given an array of numbers, move small numbers to start and big numbers to end of array

- 1of 1 vote
Two friends Kohli and Dhoni want to test their friendship to check how compatible they are. Given a list of n movies numbered 1,2,3....n and asked both of them to rank the movies.

Design an algorithm to find compatibility difference between them.

Compatibility difference is the number of mis-matches in the relative rankings of the same movie given by them i.e. if Kohli ranks Movie 3 before Movie 2 and Dhoni ranks Movie 2 before Movie 3 then its a relative ranking mis-match Compatibility difference is the maximum number of mis-matches

Sample Input

5

31245

32415

Sample Output

2

Explanation

Movies are 1,2,3,4,5. Kohli ranks them 3,1,2,4,5, Dhoni ranks them 3,2,4,1,5. Compatibility difference is 2 because Kohli ranks movie 1 before 2,4 but Dhoni ranks it after.

- 2of 2 votes
Find the length of maximum number of consecutive numbers jumbled up in an array.

e.g.: 1, 94, 93, 1000, 2, 92, 1001 should return 3 for 92, 93, 94

- 0of 0 votes
A matrix is "Toepliz" if each descending diagonal from left to right is constant. Given an M x N matrix write the method isToepliz to determine if a matrix is Toepliz.

Example:

Input:

67892

46789

14678

01467

Output:

True

- 0of 0 votes
Print the element in anti spiral order

for example

Matrix

1 2 3

4 5 6

7 8 9

o/p

5 6 9 8 7 4 1 2 3

- 0of 2 votes
There are 2 arrays of integers.You have to add the those integers and keep it in 3rd array.there is one condition, if the sum is a 2 digit number, split that number into single digiit and other condition is if any of the array integer is left then print that number

I/P:

int[] a = {1,2,3,4,5,6}

int[] b = {2,3,4,5,6,7,8}

o/p:

{3,5,7,9,1,1,1,3,8}

- 0of 0 votes
Given a histogram chart with values say {5,4,3,6,0,1}. Get the total count required to completely melt the histogram. A column with value 5 has 5 blocks in it. Any block which has air on any of its side gets melted.

Sample 1

{5,4,3,6,0,1} - > {0,3,2,0,0,0}->{0,0,0,0,0,0} => count=2

Sample 2

{0,1,1,1,1,0} - > {0,0,0,0,0,0} => count=1

- 0of 0 votes
Allocate a 2-D array of size m*n using malloc(). The array should be accessible as a[i][j].

- 0of 0 votes
Given an array of stock values of a company. Find out the time when a user would have bought the stock and sold the sock. Basically find the maximum positive difference of any two given elements in an array?

- 0of 0 votes
We have a file path as like this:

wchar_t* pCompletePath = L"\\?\UNC\10.1.3.23\TOKEN$\0x464564564576\C\FileDrive\Testcase.doc";

Write a C++ function which will take input argument as above string and gives output as L”\\?\UNC\10.1.3.23\TOKEN$\C\FileDrive\Testcase.doc” (Removing one token after the TOKEN$)

Constraints: TOKEN$ will be there for all strings, so we can use that for search

- 1of 1 vote
WAP in java to find duplicate element in array in one scan.

- -2of 2 votes
write a method that takes in 2 int arrays of any size and returns an array that calculates the sum of both.

for example, [1,2,3] and [2,3,4] will return [3,5,7]

Or [1,2,3] and [2,3,5,5] will return [2,4,7,8]

however, if it's like [9,9,2] and [0,1,3] you need to carry the sum so it returns as [1,0,0,5]

** SINGLE DIGIT ONLY

- 0of 0 votes
Given an array of both positive and negative integers , find all pairs whose sum is equal to zero.

- 0of 0 votes
Find if the characters of the sample string is in the same order in the text string.. Give a simple algo..

Eg.. TextString: abcNjhgAhGjhfhAljhRkhgRbhjbevfhO

Sample string :NAGARRO

- 0of 0 votes
consider an array1={1,1,1,1,1,1,1,1,1,1}

if n=4 add first four elements and next four elements

result : array1={4,4,2}

if n=3 add first three elements and next three elements repeat process untill size of array <=n

result1:

array1={3,3,3,1}

result2 : array1={6,4}

- 0of 0 votes
Given a string and array of strings, find whether the array contains a string with one character difference from the given string. Array may contain string of different lengths.

Ex: Given string`banana`

and array is

`[bana, apple, banaba, bonanza, banamf]`

and the outpost should be true as banana and banaba are one character difference.

- 1of 1 vote
Integer Array Ques:

Given an integer array of variable length like so [9, 8, 8, 3] where each item in array could be 0 to 9, write a function that would take would interpret the array [9, 8, 8, 3] as a number 9883 and increment it by 1. The return of the function would be an integer array containing the addition like so [9,8,8,4]. No zeros in the first position like [0,1,2,3]. I initially suggested a possible solution of process to convert the integer array to String then convert to Integer or Long and then do the addition of 1 and then convert it back to integer array. That is not allowed when the interviewer change the ques. to not allow that.

- 0of 2 votes
A string contains a-z, A-Z and spaces. Sort the string so that all lower cases are at the beginning, spaces in the middle and upper cases at the end. Original order among lower and upper cases needs to remain the same. For example: a cBd LkmY becomes ackm BLY. Is there a way in O(n) without extra space?

- 0of 0 votes
Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows,

• To decide the amount of beverage they plan to consume, say X.

• Then order for a random number of different drinks, say {A, B, C, D, E, F} of quantities {a, b, c, d, e, f} respectively.

• If quantity of any three drinks add up to X then we'll have it else we'll return the order.

E.g. If a + d + f = X then True else False

Input Format:

1. First line contains number of bottles ordered denoted by N

2. Next N lines, contains a positive integer Ai, the size of the ith bottle

3. Last line contains the quantity they intend to consume denoted by X in text above

Output Format:

True, if combination is possible

False, if combination is not possible

Input:

6

1

4

45

6

10

8

22

Output:

True

Input:

4

1

3

12

output:

false