Recent Interview Questions
- 5of 0 votes
Answersfind max number of repetitions in an array.like {2,3,4,5,2,3,2} max repeat is 2. optimize it for space then in time.
- newguy September 01, 2008| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Coding - 5of 0 votes
AnswersFind the largest prime factor of a number
- Aryan September 30, 2008| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer - 4of 14 votes
AnswersGiven two aligned sequences `a` and `b`. Write a function "findCommon", that finds the longest substring of the longer sequence that align to the smaller sequence in such a way that the alignment length (matching length) can be maximized. Sequences initially were of different lengths but the smaller one is padded with hyphen ('-') after alignment to make it equal to the longer sequence. The length of longer sequence is known in advance (m, which is same for the smaller padded sequence). The output is always the subsequence of the longer string.
- mary.kindall November 19, 2013 in United States
The total number of such operations to be done is in billions.
findCommon(a, b, m)
Example 1:
a = ------bixg--
b = xxxxxxbi-gzz
m = 12
output: big
Example 2:
a = xxxxxxbxigxx
b = ------b-ig--
m = 12
output = bxig
Example 3:
a = bigxxxxxxxxx
b = bi-x--------
m = 12
output = bigx| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 10 votes
AnswersSuppose we are given a set L of n line segments in the plane, where the endpoints of each
- polo November 01, 2014 in United States
segment lie on the unit circle x^2 + y^2 = 1, and all 2n endpoints are distinct. Describe
and analyze an algorithm to compute the largest subset of L in which no pair of segments
intersects.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 10 votes
AnswersA man goes to a hardware shop and asks for price of an item. The shop keeper replies that the item is "one for $1".
- careercupuser May 19, 2014 in United States
The man gives the shop keeper "$3 for 600". What did the man buy for his newly painted house?| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Brain Teasers - 4of 8 votes
AnswersDesign an algorithm that, given a list of n elements in an array, finds all the elements that appear more than n/3 times in the list. The algorithm should run in linear time ( n >=0 )
- Aashish June 27, 2012 in India
You are expected to use comparisons and achieve linear time. No hashing/excessive space/ and don't use standard linear time deterministic selection algo| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 8 votes
AnswersGiven a set top box:
- Guy January 18, 2014 in United States
a, b, c, d, e,
f, g, h, i, j,
k, l, m, n, o
p, q, r, s, t
u, v, w, x, y
z
Write code to give the character sequence given a word, For example, if the word is "CON", the function will print this:
Right//now we're at B
Right//now we're at C
OK//to select C
Down
DOwn
Right
Right
OK//to select O
Left//now at N
OK//to select N
note: Be careful when you're at Z. if you go to the right, you will get stuck.
Afterwards, the interviewer adds a space to the right of 'Z' to test the code.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 8 votes
AnswersGiven a matrix with only 1s and 0s now find and PRINT SUB MATRIX WITH EQUAL NUMBER OF 0s AND 1s.
- codechamp March 29, 2014 in United States for Search| Report Duplicate | Flag | PURGE
A9 Software Engineer / Developer - 4of 6 votes
Answersgiven an int array with no duplicate numbers, write a function to return number of ways to calculate a target number.
- cooldog March 15, 2013 in United States
example: given {2,4,6,8} Target = 12
2 + 4 + 6 = 12,
4 + 8 = 12,
6 + 8 - 2 = 12,
2 - 4 + 6 + 8 = 12,
return 4| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Software Engineer in Test - 4of 6 votes
AnswersGive you two sequences of length N, how to find the max window of matching
- Code2Win June 08, 2013 in India
patterns. The patterns can be mutated.
For example, seq1 = “ABCDEFG”, seq2 = “DBCAPFG”, then the max window is 4. (
ABCD from seq1 and DBCA from seq2).| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer String Manipulation - 4of 6 votes
AnswersArrange the numbers in an array in alternating order.
- codefreak November 16, 2013 in United States
For example if the array is [a1, a2, a3, a4.. ]arrange the array such that b1<=b2>=b3<=b4 and so on.
Sampe Input: 3 5 7 8 4 9
Sample Output: 3 < 5 > 4 < 8 >7 < 9| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 4of 6 votes
AnswersGiven a server that has requests coming in. Design a data structure such that you can fetch the count of the number requests in the last second, minute and hour.
- AVK June 15, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Data Structures - 4of 6 votes
AnswersYou have two integer arrays. Treat these arrays as if they were big numbers, with one digit in each slot. Perform addition on these two arrays and store the results in a new array.
- Aasen October 24, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm - 4of 6 votes
AnswersFind the nearest leaf node from given node in binary tree.
- Vin September 08, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 4of 6 votes
AnswersWrite a program to implement Double Linked List from Stack with min. complexity.
- Purushotham Kumar October 20, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Data Structures Java Linked Lists Stacks - 4of 6 votes
AnswersYou are given a sequence of black and white horses, and a set of k stables numbered 1 to k. You have to accommodate the horses into the stables in such a way that the following conditions are satisfied:
- nishu May 21, 2014 in India
a. You fill the horses into the stables preserving the order of horses. For instance, you cannot put for horse 1 into stable 2 and horse 2 into stable 1. You have to preserve the ordering of horses.
b. No stable should be empty and No horse should be left unaccommodated.
c. Take the product (number of white horses * number of black horses) for each stable and take the sum of all these products. This value should be the minimum among all possible accommodation arrangements.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 4of 6 votes
AnswersHow to find duplicates in an array
- shivam sharma January 06, 2014 in United States| Report Duplicate | Flag | PURGE
Algorithm - 4of 6 votes
AnswerGiven six digits, find the earliest valid time that can be displayed on a digital clock (in 24-hour format) using those digits.
- translink604 May 01, 2018
For example, given digits 1, 8, 3, 2, 6, 4 the earliest valid time is "12:36:48". Note that "12 : 34 : 68" is not a valid time.
Write a java method:
class Solution {
public String solution(int A, int B, int C, int D, int E, int F);
}
that, given six integers A, B, C, D, E and F, returns the earliest valid time in "HIT :mm: ss" string format, or "NOT POSSIBLE" if it is not possible to display a valid time using all six integers.
For example, given 1, 8, 3, 2, 6, 4 the function should return "12:36:48".
Given 0, 0, 0, 0, 0, 0, the function should return "00 : 00 : oo". Given 0, 0, 0, 7, 8, 9, the function should return "07:08:09".
Given 2, 4, 5, 9, 5, 9, the function should return "NOT POSSIBLE".
Assume that: • A, B, C, D, E and F are integers within the range [0..9].
Correct answer 1 point
Efficient solution 2 points| Report Duplicate | Flag | PURGE
- 4of 4 votes
AnswersIf [a1,a2,a3...,an,b1,b2...bn] is given input change this to [a1,b1,a2,b2.....an,bn] , solution should be in-place
- Anonymous February 05, 2011| Report Duplicate | Flag | PURGE
Amazon Microsoft Developer Program Engineer Software Engineer / Developer Algorithm Arrays - 4of 4 votes
AnswersYou are given a string S and a set of n substrings. You are supposed to remove every instance of those n substrings from S so that S is of the minimum length and output this minimum length.
- pnkapadia6 June 08, 2014 in India
Eg:
S- ccdaabcdbb
n=2 - substrings-- ab, cd
Output: 2
Explanation:
ccdaabcdbb -> ccdacdbb -> cabb -> cb (length=2)
Can someone help me with the algo?| Report Duplicate | Flag | PURGE
Hackerrank Software Engineer Intern String Manipulation - 4of 4 votes
AnswersWe have an array of objects A and an array of indexes B. Reorder objects in array A with given indexes in array B. Do not change array A's length.
example:
- u-11i24223 October 26, 2015 in United Statesvar A = [C, D, E, F, G]; var B = [3, 0, 4, 1, 2]; sort(A, B); // A is now [D, F, G, C, E];
| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer Front End Web Development - 4of 4 votes
AnswersGiven a Start Node and an End Node in a graph report if they are “necessarily connected”. This means that all paths from the start node lead to the end node. Report true all paths from start node lead to end node and false if at least one path does not lead to the end node. This is a directed graph which can have cycles
- nikki December 31, 2018 in United States
Does anyone know how to solve this? I had it in my interview at Google in CA and I still cant solve it| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 4of 4 votes
AnswersGiven a string S, you are allowed to convert it to a palindrome by adding 0 or more characters in front of it.
- xyz_coder November 20, 2014 in United States
Find the length of the shortest palindrome that you can create from S by applying the above transformation.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 4of 4 votes
AnswersGiven a large string T (up to 10M characters) and a large input stream of strings S(up to 1M strings), find for each Si in S if it is a subsequence of T.
- PrincessMaja November 17, 2013 in United States
String Si is a subsequence of T iff some letters from T can be omitted to obtain Si.
Example:
T - abbebcd
Si - bbcd
return true
T - abbeced
Si - bbbced
return false| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm - 4of 4 votes
AnswersYou are given a large set of integers, which are not sorted. Figure out a method to retrieve the largest 1000 elements, in O(n) run time
- varunumesh77 March 12, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm Data Structures - 4of 4 votes
AnswersGiven two (dictionary) words as Strings, determine if they are isomorphic. Two words are called isomorphic
- yashas.mavinkere November 07, 2013 in United States for Application
if the letters in one word can be remapped to get the second word. Remapping a letter means replacing all
occurrences of it with another letter while the ordering of the letters remains unchanged. No two letters
may map to the same letter, but a letter may map to itself.
Example:
given "foo", "app"; returns true
we can map 'f' -> 'a' and 'o' -> 'p'
given "bar", "foo"; returns false
we can't map both 'a' and 'r' to 'o'
given "turtle", "tletur"; returns true
we can map 't' -> 't', 'u' -> 'l', 'r' -> 'e', 'l' -> 'u', 'e' -'r'
given "ab", "ca"; returns true
we can map 'a' -> 'c', 'b'| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Data Structures - 4of 4 votes
AnswersGiven a array of size n. Divide the array in to two arrays of size n/2,n/2. such that average of two arrays is equal.
- gowthamganguri August 29, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 4of 4 votes
AnswersYou are given a set of unique characters and a string.
- francisvm February 04, 2015 in United States
Find the smallest substring of the string containing all the characters in the set.
ex:
Set : [a, b, c]
String : "abbcbcba"
Result: "cba"| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 4of 4 votes
AnswersGiven an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J-th disc and K-th disc intersect if J ≠ K and J-th and K-th discs have at least one common point.
- adam2008 February 22, 2013 in United States
Write a function:
int number_of_disc_intersections(int A[], int N);
that, given an array A describing N discs as explained above, returns the number of pairs of intersecting discs. For example, given N=6 and:
A[0] = 1 A[1] = 5 A[2] = 2
A[3] = 1 A[4] = 4 A[5] = 0
intersecting discs appear in eleven pairs of elements:
0 and 1,
0 and 2,
0 and 4,
1 and 2,
1 and 3,
1 and 4,
1 and 5,
2 and 3,
2 and 4,
3 and 4,
4 and 5.
so the function should return 11.
The function should return −1 if the number of intersecting pairs exceeds 10,000,000.
Assume that:
N is an integer within the range [0..10,000,000];
each element of array A is an integer within the range [0..2147483647].
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.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer