Arrays Interview Questions
- 1of 1 vote
AnswersFor the given array count the partitions such that absolute deferrence between any two elements from partition is less then or equal to k order of elements in partition array is is independent and elements is not get repeated in portion.
- Rising star January 23, 2022 in India
Quetion: A[] = { 1, 2,3,10, 5,4}, K = 3.
There are two Possible partitions are {1,2,3}, {5, 4} or {1,2}, {3, 5, 4} or {2,3,5,}, {1,4} there are two partion such that absolute deferrence between any two elements is less then K
So the Output is 2| Report Duplicate | Flag | PURGE
Cisco Systems Backend Developer Algorithm Arrays C++ Data Structures - 3of 3 votes
AnswersAsked in Google - 2020, Goldman Sachs - 2020
- Gaurav Sohaliya August 22, 2020 in India
Given two Array.
A = [1,3,4,2,5,6] B = [3,4,6,5,7]
we have to remove 3,1,2,6 and Insert 6,7 to make A equal to B.
we can delete and insert any element at anywhere from first array and make that array same as second array. Output is Minimum Number of elements required to be insert in first array.
constraints:
1 <= First Array Size <= 10^5
1<= Second Array SIze <= 10^5
1 <= firstarray[i] <= 10^9
1 <= secondarray <= 10^9
second array consist of distinct element.
Note : it is same as edit distance but here our constraints are 10^5.| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Arrays - 0of 0 votes
AnswersQ.1 Rather than separate T[1…m] into two half size arrays for the purpose of merge sorting, we
- ninjaaarashi May 23, 2020 in United States
might choose to separate it into three arrays of size x%3, (x+1)%3, and (x+2)%3, to sort each of
these recursively, and them to merge the three sorted arrays. Give a more formal description of
this algorithm and analyze its execution time. Justify your answer with example.| Report Duplicate | Flag | PURGE
Algorithm Arrays Data Structures Programming Skills - 1of 1 vote
Answersfind the maximum length subarray condition 2 * min > max
- samayragoyal990 March 16, 2020 in India| Report Duplicate | Flag | PURGE
Adobe Backend Developer Arrays Coding - 1of 1 vote
AnswersFind the two elements that have the smallest difference in a given array.
- si October 23, 2019 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Intern Arrays - 0of 0 votes
AnswersGiven an array of positive and negative integers {-1,6,9,-4,-10,-9,8,8,4} (repetition allowed) sort the array in a way such that the starting from a positive number, the elements should be arranged as one positive and one negative element maintaining insertion order. First element should be starting from positive integer and the resultant array should look like {6,-1,9,-4,8,-10,8,-9,4}
- sameerasusmitha October 21, 2019 in India| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - 2of 2 votes
AnswersWrite a code to return a value 'True' if the number '1' throughout the array appears consecutively. Ex: S = {1,1,1,0,0,3,4}.
- hadeebataj May 10, 2019 in India
Else, return 'False' if the array does not have the given number (char = '1' in this case) in the consecutive order. Ex: S = {1,1,0,0,1,3,4}| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - -6of 6 votes
AnswersFind a pair that equals to the given target from the list of given two lists.
- sarunreddy82 January 07, 2019 in United States
example:
input:
target = 7
list1= [[1,2],[2,4[,[3,6]]
list2 = [[1,2]]
Output:[[2,1]]
Explanation: There are only three combinations [1,1],[2,1] and [3,1], which use a total of 4,6, 8 respectively. Since 6 is the largest use that does not exceed 7, [2,1] is the only optimal pair.
Example 2:
Input :
target = 10
list1 = [[1,3],[2,5],[3,7],[4,10]]
list2 = [[1,2],[2,3],[3,4],[4,5]]
Output;
[[2,4],[3,2]]| Report Duplicate | Flag | PURGE
Amazon Arrays - 1of 1 vote
Answersk=2, l=[1,2,3,4,5,6]
- nikhil19kekan December 04, 2018 in United States for Community Operations
output: l=[5,6,1,2,3,4]
In place O(1) space complexity| Report Duplicate | Flag | PURGE
Facebook Software Developer Arrays - 0of 0 votes
AnswersI/P [8, 3, 2, [5, 6, [9]], 6]
- Seetha November 11, 2018 in United States
O/P 8+3+2+2*(5+6+3*(9))+6 => 95| Report Duplicate | Flag | PURGE
Facebook Software Developer Arrays - 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 - 10of 10 votes
AnswersGiven 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 Indiaclass 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 - 2of 2 votes
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