Software Engineer / Developer Interview Questions
- 0of 0 votes
AnswersWrite an algorithm that uses the divide and conquer technique. Given an array V with n int elements the algorithm should calculate the number of times that two consecutive 0's appear. Example :If V = [3, 0, 0, 1, 0, 1, 3, 2, 0, 0, 0, 1, 2], the algorithm should return 3, Note that 0, 0, 0 corresponds to having 2 pairs of consecutive zeros.
- KH November 17, 2014 in United States
I was wondering if you guys can give me a step by step approach in solving these questions. I'm a recent grad and I want to know the best solutions to solve these problems. Thanks!| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm - 0of 0 votes
AnswersBuild a function that takes one string and one regex expression in inputs and output true if the string matches the regex expression.
- shankhs November 16, 2014 in United States
string: a-z
regex: a-z + * (where '*' matches 0 or more character and '+' matches one character)| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer - 0of 0 votes
Answerst's laundry day, and, as usual, you've been putting this off for quite some time. Also, unfortunately, you lacked the foresight to actually ensure all your dirty laundry stayed in your hamper whilst it accumulated (what? we can't ALL be underwear basketball pros!).
- xyz_coder November 15, 2014 in United States
Begrudgingly, you've gathered up all the clothing you could find and sent them through the wash. Now you have a disheveled pile of clean, albiet disorganized, accoutrements. You come to the realization that you probably lost some items in the fray, so now it's time to fold and figure out what's gone missing!
To get a good idea of the state of your wardrobe, count up the number of distinct shirts, pants, and underwear you have as you go through the laundry. Also pair up your socks, noting the number of pairs of each kind of sock and if there are any lonely souls (single (and ready to mingle) socks).
Input Specifications
Each article of clothing will have its own separate line. You have a penchant for hoarding, so there is no guarantee as to the number of pieces, but you can assure yourself that each article can be easily categorized by description (name).
Articles of clothing will be fed in as line-delimited list. See below for examples.
Output Specifications
Output should be an alphabetically (case-insensitive) sorted, line-delimited list of the articles of clothing along with their count. Each field (count, category) should be separated by a pipe (|). If you come across a sock without a soulmate, the count should be designated by a 0 (zero). Socks that are in pairs should be on separate lines from the socks of the same category without pairs, and should come before the pairless sock. See below for examples.
Sample Input/Output
INPUT
white shirt
polka dot sock
red sock
superhero shirt
torn jeans
polka dot sock
white shirt
polka dot sock
OUTPUT
1|polka dot sock
0|polka dot sock
0|red sock
1|superhero shirt
1|torn jeans
2|white shirt
EXPLANATION
As described above in the input and output specifications.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Algorithm - 0of 0 votes
AnswersIn gmail, while composing an email, upon adding a contact, related contacts are displayed. How would you implement that feature?
- pqrabcd November 14, 2014 in United States
- Write an algorithm for that.
- What data structure would you use to store the weights?
- In what format would you persist this data?| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 5of 5 votes
AnswersWe have words and there positions in a paragraph in sorted order. Write an algorithm to find the least distance for a given 3 words.
- pqrabcd November 14, 2014 in United States
eg. for 3 words
job: 5, 9 , 17
in: 4, 13, 18
google: 8, 19, 21
...
...
Answer: 17, 18, 19
Can you extend it to "n" words?
Context: In Google search results, the search terms are highlighted in the short paragraph that shows up. We need to find the shortest sentence that has all the words if we have word positions as mentioned above.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 3 votes
Answerswrite an algorithm to decide weather a string is a palindrome.
- shanik November 14, 2014 in Israel
Ignore any non-letter characters in the the string.
Ignore capital/lower case.
Space complexity O(1)
for example, the following should return true:
A man, a plan, a canal -- Panama!| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 0of 0 votes
AnswersGiven an arraylist of N integers,
- united November 13, 2014 in United States
(1) find a non-empty subset whose sum is a multiple of N.
(2) find a non-empty subset whose sum is a multiple of 2N.
Compare the solutions of the two questions.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a M * N matrix, if the element in thematrix is larger than other 8 elements who stay around it, then named thatelement be mountain point. Print all the mountain points.
- yylmaster November 13, 2014 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 0of 0 votes
AnswersIn basket ball game for a player to win a game
- Aspire November 13, 2014 in United States
challenge 1) 2 out of 3 throws should be basket
challenge 2) 4 out of 6 throws should be basket
which challenge should the player choose so that he might have better chance of winning the game?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 1of 1 vote
AnswersIn basket ball game for a player to win a game
- Aspire November 13, 2014 in United States
challenge 1) 2 out of 3 throws should be basket
challenge 2) 5 out of 8 throws should be basket
which challenge should the player choose so that he might have better chance of winning the game?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Probability - -6of 10 votes
AnswersSuppose we have array of N numbers. We will define N functions on this array. Each function will return the sum of all numbers in the array from Li to Ri ( Li is left index, Ri is right index). Now we have 2 types of queries:
- anotherandres November 12, 2014 in United States
Type1: 1 x y Change the xth element of the array to y
Type2: 2 l r Return the sum of all functions from m to n.
Input type:
First Line is the size of the array i.e. N
Next Line contains N space separated numbers Ai denoting the array
Next N line follows denoting Li and Ri for each functions.
Next Line contains an integer Q , number of queries to follow.
Next Q line follows , each line containing a query of Type 1 or Type 2
Here is an example:
Input:
5
1 2 3 4 5
1 2
3 4
1 4
1 5
3 5
5
1 1 5
2 2 4
2 1 3
1 4 5
2 1 5
Output:
40
28
63
Explanation:
Function 1 is sum of values from index 1 to index 2 = 1+2=3
So , F1=3
Similarly, F2=3+4=7
F3=1+2+3+4=10
F4=15
F5=12
Now when I query 1 1 5
means it is type 1 query, so we replace value at index 1 by 5.
So our new array is,
5 2 3 4 5
and
F1=7
F2=7(unchanged)
F3=14
F4=19
F5=12(unchanged)
Then next query is 2 2 4
means give sum of all functions from index 2 to 4.
So, ans= 7+14+19 =40 (output 1)
Similarly are other 2 outputs.
Index are 1 based in example.
Comment me if you are not clear with question.
Edit: I know one can do it with naive approach or using segment tree. But they wanted more faster way to do it.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a list of points, merge the intersecting points.
- bc November 11, 2014 in United States
Example:
{-10,-5}{-1,5}{2,4}{5,10}{20,35}{12,17}{17,21}
Should output:
{-10,-5}{-1,10}{12,35}
Nothing falls between the {-10,-5} so this point stays. The {-1,5}{2,4} and {5,10} points can all be merged as they have intersecting points. They are merged to {-1,10}. The {20,35}{12,17} and {17,21} points can all be merged as they have intersecting points. They are merged to {12,35}| Report Duplicate | Flag | PURGE
Big Fish Software Engineer / Developer Algorithm - -1of 5 votes
AnswersGoldman's conjecture - already posted,
- VB November 09, 2014 in United States
Well ordered numbers - already posted.| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 1of 1 vote
AnswersThe cows and bulls game, Player A chooses a word and player B guesses a word. You say bulls when a character in the player B's guess match with a character in player A's word and also it is in the corect position as in A's word. You say cows, when a character in the player B's word match the character in player A, but it is not in the correct position. The characters are case insensitive. Given two words player A's and player B's,Write a function that return the number of bulls and no of cows. For example,
- VB November 09, 2014 in United States
A - Picture B- Epic, bulls -0, cows - 4
A - forum B - four, bulls - 3 cows - 1| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 0of 2 votes
AnswersJumper Game: A NxN grid which contains either of 0-empty, 1 - player1, 2 - player 2. Given a position in the grid, find the longest jump path. For jump path, you can horizontally or vertically, you can jump on opponent cell and also the landing cell should be empty. No opponent cell can be jumped more than once. Write a function which takes grid and a specific position in the grid, and returns the longest possible number of jumps in the grid.
- VB November 09, 2014 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - -1of 1 vote
Answersyou are given an array or length 1million and rang of value from 0-m ... count the number of accurance of each number.
- vikaskupushkar November 08, 2014 in India for SRPG
#2 the same array as above. find out the distance between min and max.
#3 write a malloc function.
and some theoretical Qs on routing Table.
There was one stupid guys who asked me given a binary tree and a depth of the tree print all the nodes in that tree on that depth.
when i used inserted a NULL node in my code he said it wont work as the value of NULL is 0 its not a pointer.... bla boa.... i was shocked that a guy who has code to take 3rd round of interview is saying these kind of thing :D..... there was one more thing that he said that in 'C' u cant declare a variable after the initial declaration in func tion body I said yes we should not but Now a days c compilers like gcc etc allows it ... god know he ever used gcc or not but he denied it 3 time..... really bad experience| Report Duplicate | Flag | PURGE
Alcatel Lucent Software Engineer / Developer Algorithm - 0of 0 votes
AnswersWrite a program to read file of following data structure: Name: favcolor=blue Find out which color is favorite by most people (print the color and number of people)
- KH November 06, 2014 in United States| Report Duplicate | Flag | PURGE
Software Engineer / Developer Java - 0of 0 votes
AnswersYou have a binary tree where each node knows the number of nodes in its sub-tree (including itself).
- mikewhity November 06, 2014 in United States
Given a node n and an int k,
write a function to return the kth
node in an in order traversal.
Can you do this non recursively| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
Answers/* Write a function to compute the maximum length palindromic sub-sequence of an array.
- qik21 November 06, 2014 in United States
A palindrome is a sequence which is equal to its reverse.
A sub-sequence of an array is a sequence which can be constructed by removing elements of the array.
Ex: Given [4,1,2,3,4,5,6,5,4,3,4,4,4,4,4,4,4] should return 10 (all 4's) */
class Interview {
public static int maxLengthPalindrome(int[] values) {
//ur implementation here
}| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 1of 1 vote
Answers/**
- qik21 November 06, 2014 in United States
* Given a nested list of integers, returns the sum of all integers in the list weighted by their depth
* For example, given the list {{1,1},2,{1,1}} the function should return 10 (four 1's at depth 2, one 2 at depth 1)
* Given the list {1,{4,{6}}} the function should return 27 (one 1 at depth 1, one 4 at depth 2, and one 6 at depth 3)
*/
public int depthSum (List<NestedInteger> input)
{ // ur implementation here}
**
* This is the interface that represents nested lists.
* You should not implement it, or speculate about its implementation.
*/
public interface NestedInteger
{
/** @return true if this NestedInteger holds a single integer, rather than a nested list */
boolean isInteger();
/** @return the single integer that this NestedInteger holds, if it holds a single integer
* Return null if this NestedInteger holds a nested list */
Integer getInteger();
/** @return the nested list that this NestedInteger holds, if it holds a nested list
* Return null if this NestedInteger holds a single integer */
List<NestedInteger> getList();
}| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 4of 4 votes
AnswersGiven the relative positions (S, W, N, E, SW, NW, SE, NE) of some pairs of points on a 2D plane, determine whether it is possible. No two points have the same coordinates.
- united November 02, 2014 in United States
e.g., if the input is "p1 SE p2, p2 SE p3, p3 SE p1", output "impossible".| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array of integer, find the number of un-ordered pairs in that array, say given {1, 3, 2}, the answer is 1 because {3, 2} is un-ordered, and for array {3, 2, 1}, the answer is 3 because {3, 2}, {3, 1}, {2, 1}.
- lsdtc1225 November 02, 2014 in United States
Obviously, this can be solved by brute force with O(n^2) running time, or permute all possible pairs then eliminate those invalid pairs.
My question is does any body have any better solution and how would you do it because it seems like a dynamic programming problem. A snippet of code would be helpful| 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 - 0of 0 votes
AnswersSolve the above problem for N number of input arrays. Find the intersection of N-integer arrays.
- abkr990 October 31, 2014 in United States| Report Duplicate | Flag | PURGE
Lab126 Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven two integer arrays, find the intersection of the two.
- abkr990 October 31, 2014 in United States
eg: arr1 = {1, 3,6,10}, arr2 = {2,3,5,6} , the function should return {3,6}.| Report Duplicate | Flag | PURGE
Lab126 Software Engineer / Developer Algorithm - 5of 5 votes
AnswersGiven two strings, return boolean True/False, if they are only one edit apart.Edit can be insert/delete/update of only one character in the string. Eg:
- abkr990 October 31, 2014 in United States
-True
xyz,xz
xyz, xyk
xy, xyz
-False
xyz, xyz
xyz,xzy
x, xyz| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersThe third question is a brain teaser: if 1000 couples are to give birth to male and female babies(50% change each), and they would keep giving birth until they have a girl, what's the boy to girl ratio in 20 years
- fenghanlu October 30, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
AnswersWe have two strings A and B with the same super set of characters. We need to change these strings to obtain two equal strings. In each move we can perform one of the following operations:
- harshit.knit October 29, 2014 in India
1. swap two consecutive characters of a string
2. swap the first and the last characters of a string
A move can be performed on either string.
What is the minimum number of moves that we need in order to obtain two equal strings?| Report Duplicate | Flag | PURGE
Trilogy Software Engineer / Developer Algorithm - 2of 2 votes
Answersgiven n > 0 fair dice with m > 0 "sides", write an function that returns a histogram of the frequency of the result of dice rolls. For example, for two dice, each with three sides, the results are:
- Aurelius October 29, 2014 in United States for BVal
(1, 1) -> 2
(1, 2) -> 3
(1, 3) -> 4
(2, 1) -> 3
(2, 2) -> 4
(2, 3) -> 5
(3, 1) -> 4
(3, 2) -> 5
(3, 3) -> 6
And the function should return:
2: 1
3: 2
4: 3
5: 2
6: 1| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Coding