## Arrays Interview Questions

- 1of 1 vote

AnswersGiven an array of Integers, find out how many combinations in the array, satisfy the equation x+y+z=w, where x,y,z and w belong to the array and idx(x)<idx(y)<idx(z)<idx(w). Elements are unique.

- kieth October 07, 2018 in United States| Report Duplicate | Flag | PURGE

Google SDE1 Arrays - 1of 1 vote

AnswerGiven an array, coin of size n, coin[i] denotes the no. of coins on the position i. Can move any number of coins from the position i to (i+1) or (i-1). What is the minimum no. of moves required to redistribute the coins, so that each position i has at least 1 coin ?

- 00pzz October 06, 2018 in India

Note: Summation of total coins on the array is exactly n.| Report Duplicate | Flag | PURGE

Amazon Software Developer Arrays - 0of 0 votes

AnswerGiven 3 unsorted arrays A, B and C you need to find all possible combinations such that A[i] + B[j] = B[k] + C[l].

- venkataratnamkumar7777 September 22, 2018 in United States| Report Duplicate | Flag | PURGE

Walmart Labs SDE1 Algorithm Arrays - 0of 0 votes

AnswersGiven a wall, which is made up of two types of bricks (Porus / opaque ). Porus bricks allow water pass through them. Opaque won't. Find whether water reaches to ground, if there is any rainfall.

- gopi.komanduri June 11, 2018 in India for Office

Water can flow from top to bottom, diagonally, horizontally as well. Only flowing from bottom to top is not possible.| Report Duplicate | Flag | PURGE

Microsoft SDE-3 Algorithm Arrays Brain Storming Coding Data Structures Dynamic Programming Problem Solving Programming Skills - 0of 0 votes

AnswersLanguage : java

- sarunreddy82 April 27, 2018 in United States

Find the length of the non repeated numbers in an array.

Input : 1,2,2,3,4,5,6,2,3| Report Duplicate | Flag | PURGE

xyz abc Arrays - 0of 0 votes

AnswersGiven an array of n strings, sentences, where each sentences, consists of most w space-separated words, we want to perform q queries given by an array of q strings named queries where each queries consists of at most k space-separated words. To answer query queriesj, we find all the indices in sentences that contain every word in queries and assemble them into an array of indices listed in ascending order. For example, if all the words in queries are only found in sentences4, sentences9 and sentences2 , then the answer to queriesj is the array[2,4,9].

- sarunreddy82 March 28, 2018 in United States

Input Format:

The first line contains an integer, n, denoting the number of Strings in sentences

Each line i of the n subsequent lines contains at most w space-separated words describing sentences

The next line contains an integer, q, denoting the number of strings in queries

Each line j of the q subsequent lines contains at most k space-separated words describing queries.

1) Sample I/P format:

3

jim likes mary

kate likes tom

tom does not like jim

2

jim tom

likes

O/P:

2

0 1

2) Sample I/P Format:

4

how it was done

are you how

it goes to it

goes done are it

2

done it

it

O/P:

0 3

0 2 2 3

Note: Solution in Java only

static void searchQueries(String[] sentences, String[] queries) {

}| Report Duplicate | Flag | PURGE

xyz Arrays - 0of 0 votes

AnswerGiven the below input and ouput.

- sarunreddy82 March 05, 2018 in United States

Input :

String[] input = {"hello", "world"};

output: (Higher count should come before and natural order)

hello : l=2, e=1,h=1,o=1

world: d=1,l=1,o=1,r=1,w=1| Report Duplicate | Flag | PURGE

xyz None Arrays - 0of 0 votes

AnswersGiven the below input and output and asked to write in Java.

- sarunreddy82 February 22, 2018 in United States

Example 1)

input : {1,2,3,4, &, 12,13,14,15}

output : {15,14,13,12,1,2,3,4}

Example 2 )

input : {33,34,&,55,63}

output : {63,55,33,34}

Assumption : '&' will always be in the middle.| Report Duplicate | Flag | PURGE

xyz Backend Developer Arrays - 0of 0 votes

AnswersIt was asked in Chargebee off campus interview. Needed solution for this problem in java

- psribalaji12 February 08, 2018 in India

Given a string say s and k denotes the number of commas and the output should be like when you insert the comma in the string at different places and find the maximum number.

Test case 1

say s = 999 and k = 1 so the choice would be 9,99 or 99,9 in either case the maximum number is 99

Test case 2

say s=999 and k =2 so the choice will be like 9,9,9 so output will be 9

Test case 3

say s = 857 and k = 1 the choice would be 85,7 or 8,57 so the output will be like 85| Report Duplicate | Flag | PURGE

StartUp Java Developer Arrays Brain Storming String Manipulation - 0of 0 votes

AnswersThe value obtained in the function is given back to main by using ________ keyword?

- si.connect2mba January 21, 2018 in India for Java

A. return B. Static C. new D. Volatile| Report Duplicate | Flag | PURGE

Surya Informatics Solutions Pvt. Ltd. Junior programmer Arrays - 0of 0 votes

AnswersYou have a non empty binary array with value 0 and 1. You can flip either 0 or 1 bit of array to make the consecutive element same.You have to return the count of consecutive number with same digit.

Input : [ 1,0,1,0,0,0]

Output : 4

if you flip the value of 1st index to 1, you have 2 consecutive 1 and 2 consecutive 0 so total 4.

input : [0,0,0,0]

output : 3

input : [0]

output 1

there is bug in below code which i couldn't find it.

- sandeepmnit35 January 09, 2018 in India`class Solution { int solution(int[] A) { int n = A.length; int result = 0; for (int i = 0; i < n - 1; i++) { if (A[i] == A[i + 1]) result = result + 1; } int r = 0; for (int i = 0; i < n; i++) { int count = 0; if (i > 0) { if (A[i - 1] != A[i]) count = count + 1; else count = count - 1; } if (i < n - 1) { if (A[i + 1] != A[i]) count = count + 1; else count = count - 1; } r = Math.max(r, count); } return result + r; } }`

| Report Duplicate | Flag | PURGE

Amdocs Android Engineer Arrays - 0of 0 votes

AnswersN different couple go to cinema with 2N different seats. They take their place randomly. You could make swap operations. Write a code for given input what is the minimum number of swap operations for sitting all couples with their partners? Additionally, be sure that no one swaps more than 2 times.

- new December 07, 2017 in United States| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm Arrays Coding Data Structures - 1of 1 vote

AnswersGiven an array of sorted integers and find the closest value to the given number. Array may contain duplicate values and negative numbers.

- Vijay November 17, 2017 in India

Example : Array : 2,5,6,7,8,8,9

Target number : 5

Output : 5

Target number : 11

Output : 9

Target Number : 4

Output : 5| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm Arrays Coding Data Structures - 0of 0 votes

AnswersHow to find three largest numbers in array?

- ia4nik.roma November 04, 2017 in United States| Report Duplicate | Flag | PURGE

Arrays - 0of 0 votes

AnswersWrite a logic to print the elements of 2D matrix in a spiral way?

- explorer August 25, 2017 in United States

for eg if int[][] matrix = {{1,2,3,4}{5.6,7,8}{9, 10, 11,12}};

The output should be 1 2 3 4 8 12 11 10 9 5 6 7

The interviewer asked me to implement a recursive algorithm.| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Arrays - 0of 0 votes

AnswersYou have a long string that contains of 0's and 1's, seprated with some delimiter (like "!"). the number of delimeters after each 0 or 1 is between 1 to 3.

- Patrick July 15, 2017 in United States

for example a string such as 0! 1!!! 0!! 1!! 0! 1! 0!!! 1!! 0!! (and so on...)

Take this long string and convert it to a 7 digits number by some porgramming algorythem,

(you can use every lanugage you want)| Report Duplicate | Flag | PURGE

A9 abc Arrays - 1of 3 votes

Answers - missing July 07, 2017 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Arrays - 0of 0 votes

AnswersCan multiple threads improve the time complexity to merge k sorted arrays? If so, how?

- ajay.raj May 18, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook SDE1 Arrays - 1of 1 vote

AnswersWrite a function that takes an array of positive and negative integers and a number. This function should return true if the array contains a contiguous sub array that sums up to the number (2nd input).

- JSDUDE May 09, 2017 in United States

He wanted an O(n) algorithm.| Report Duplicate | Flag | PURGE

Snap Inc Software Developer Arrays - 0of 0 votes

AnswersYou are given an array of nodes where each node consists of node name, isValid flag, and parent Node index. so, this array actually represents a tree(forest). where root node has -1 as its index for the parent node. rest all node have their parent's index value.

- sonesh May 08, 2017 in United States

You will be given this array and an index. You have to cut down the subtree from the index. Cutting down a tree means, making all the nodes of that subtree false(Isvalid flag).

He was expecting O(N) solution.| Report Duplicate | Flag | PURGE

Two Sigma Software Engineer / Developer Arrays Coding Trees and Graphs - 1of 1 vote

AnswersQ 1. You are given an array of integers, contains positive, negative and zeros. You have to written subarray whose sum is maximum in this array.

- sonesh April 28, 2017 in United States

Desired Complexity is O(N) + O(1)| Report Duplicate | Flag | PURGE

Hitachi Data Systems Software Engineer / Developer Algorithm Arrays - -1of 1 vote

AnswersYou are given an array of integers and a number K. You have to find the any continue sub-array whose elements sum is K. Please note that, the array may have positive, negative, and zeros as its element.

- sonesh April 22, 2017 in United States

The desired complexity is O(N).

Example:

Input: [7 0 9 -10 0 789], K = 0

Output: Array from index 1 to Index 1.

Input: [1 2 3 5 -10] K = 0

Output: Array from Index 1 to Index 4.

If K = -2, Output would have been SubArray from Index 2 to Index 4.| Report Duplicate | Flag | PURGE

Snap Inc Software Engineer / Developer Arrays - 0of 0 votes

AnswersYou are given an integer array. You have to return/print an array where kth element of this array is the multiplications of all the elements from 0 to k-1 and from k+1 to n-1.

- sonesh April 20, 2017 in United States

Example

input: [1 2 5 6]

output: [60 30 12 10]| Report Duplicate | Flag | PURGE

Coupang Software Engineer / Developer Arrays - 0of 0 votes

AnswersYou are given a rotated sorted array of size N. You have to search a given number into it.

- sonesh April 18, 2017 in United States

Example: [4,6,8,14,90,-9,-2,0,3], Search -2.| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Arrays Sorting - 0of 0 votes

AnswersWrite a program which takes input a sorted array and positive number and updates the array so that if x appears m times in array then it appears exactly min(2,m) times in array. the update should be performed in one pass with no additional memory

- ashishsaraswat.iips April 17, 2017 in India| Report Duplicate | Flag | PURGE

Amazon SDE-2 Arrays - 1of 1 vote

AnswersYou are given a vector of integers. You have to delete the odd numbers from it.

- sonesh April 13, 2017 in United States

Expected complexity is O(N) Time and O(1) space| Report Duplicate | Flag | PURGE

Bloomberg LP Software Engineer / Developer Arrays - 1of 3 votes

AnswersGiven array of length n, having element 0 to n-1.

- DATA April 11, 2017 in United States

you are allowed to swap adjacent element only if Absolute difference of two element is equal to 1.

Is it possible to sort array.

If yes print sorted output.| Report Duplicate | Flag | PURGE

Yahoo Backend Developer Arrays Data Structures Math & Computation Online Test - 0of 0 votes

AnswersGiven an array of unique numbers. Find the number of pairs that make up the difference. This must be solved in under O(N^2)

`function getPairs(int[] array, int k){ HashMap<Integer,Integer> values = new HashMap<Integer,Integer>(); for(int i = 0; i < array.length; i++){ if(!values.containsKey(array[i])){ values.put(array[i],1); } } int pairs = 0; for(int i = 0; i < array.length; i++){ int diff = array[i] - k; if(values.containsKey(diff)){ pairs++; } } return pairs; }`

This will give O(N) time. O(N) Space

- mcg1coding April 10, 2017 in United States| Report Duplicate | Flag | PURGE

Fidessa Software Developer Arrays - 0of 0 votes

AnswersOne question containing multiple questions

- sonesh April 07, 2017 in United States

1) Define the structure of a function which takes an array of size n as input and returns True or False.

2) Write a function which takes an array as input and returns a string containing all the elements separated by a comma.

Ex : [0, -45, 9, 10] => "0,-45,9,10";

3) Write a function which takes two arrays ass input, and returns minimum common element in them.

Ex : [0, -90, 45, 10, 4], [4, 8, 90, 45] => 4

4) Now let's say, the function takes an array of arrays, and each array is sorted. now, returns their first common element.

Ex : [0, -90, 45, 10, 4], [4, 8, 90, 45], [-1, -3, -5, -7, 10, 4], [24, 35, 78, -90, 56, 4] => 4| Report Duplicate | Flag | PURGE

Bloomberg LP Software Engineer / Developer Arrays

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window