Intern Interview Questions
- 0of 0 votes
AnswerGiven 3 strings "s" ssearch" and "sreplace", search string s for the substring ssearch and for every instance of ssearch you find, replace that part of the string with sreplace
- mh4wt@virginia.edu January 09, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java - 0of 0 votes
AnswersGiven an NxN Boolean matrix, find how many true regions there are in the matrixj
- mh4wt@virginia.edu January 09, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java - 0of 0 votes
AnswersCreate a basic minesweeper game that allows for board creation with custom height, width and number of mines. Create a <click> function that will take in a board location and return whether the user has won, lost, or the number of surrounding mines.
- mh4wt@virginia.edu January 09, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java - 0of 0 votes
AnswersGiven a string, print out all of the unique characters and the number of times it appeared in the string
- mh4wt@virginia.edu January 09, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java String Manipulation - 0of 0 votes
AnswersGiven a singly linked list of integers, write a function in java that returns true if the given list is palindrome, else returns false
- mh4wt@virginia.edu December 18, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java Linked Lists - -3of 3 votes
AnswersConvert an unordered tree to a binary tree
- mh4wt@virginia.edu December 18, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java Trees and Graphs - 1of 1 vote
Answersmerge two binary search trees
- mh4wt@virginia.edu December 18, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Java Trees and Graphs - 0of 0 votes
AnswersSort a stack using only one other stack and no recursion.
- mh4wt@virginia.edu December 18, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Intern Stacks - 3of 3 votes
AnswersWrite an algorithm that returns any duplicate in an array of integers. The algorithm must run in O(n) time and O(1) space. (hint: the integers in the array are not greater than the size of the array).
- davidgbadebo6 November 08, 2016 in United States| Report Duplicate | Flag | PURGE
Google Intern - 0of 0 votes
AnswersAdd a node to sorted circular linked list
- Blank October 29, 2016 in United States for Infrastructure| Report Duplicate | Flag | PURGE
Salesforce Intern Data Structures - 0of 0 votes
AnswersYou have a string aaabbdcccccf, transform it the following way => a3b2d1c5f1
- Blank October 29, 2016 in United States for Infrastructure
ie: aabbaa -> a2b2a2 not a4b2| Report Duplicate | Flag | PURGE
Salesforce Intern String Manipulation - 0of 0 votes
AnswersThere is a DNA Strand having values as A , T , C , G.
- saurabh.desi.bhatt October 11, 2016 in United States
All combinations are present in the the file.
Write a method which takes starting mutation string , ending mutation string and string bank and calculates the minimum mutation distance required. But the condition is that either of the start or end must be present in the bank.
Input:
AATTGGCC is starting and TTTTGGCA is ending then mutation distance will be 3.
AATTGGCC - TATTGGCC - TTTTGGCC - TTTTGGCA as it takes three mustaion for start to reach the end string and for this , all intermediate string and final string must be present in the bank.
static int findMutationDistance(String start, String end, String[] bank) {
}| Report Duplicate | Flag | PURGE
Twitter Intern Java - 0of 0 votes
AnswersYou have a string of phrases present. For your simplicity consider them to be integer length.
- saurabh.desi.bhatt October 11, 2016 in United States
String s= " I am Tom"
will be stored in an interger array as [1,2,3] where each represents length of each word in the string.
Write a method to compute the longest subsequence such that it is less than given k value.
Input:
3 //length of array
1 //a[0]
2 //a[1]
3 //a[2]
4 // value of k
Output:
2
Input:
4 //length of array
3
1
2
1
4 //value of k
Output:
3
static int maximumLength(int[] a, int k) {
}| Report Duplicate | Flag | PURGE
Twitter Intern Java - 0of 0 votes
AnswersCAREERCUP 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.
- J@sper October 11, 2016 in United States
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) {
}| Report Duplicate | Flag | PURGE
Amazon Intern Arrays - 0of 2 votes
AnswersWhat is RESTful design.
- coLiguanda October 08, 2016 in Cananda| Report Duplicate | Flag | PURGE
Yahoo Intern Web - 1of 1 vote
AnswersGiven two (binary) trees, return the first pair of non-matching leaves
- bobshanely October 03, 2016 in United States
Tree 1: A, B, C, D, E, null, null
Tree 2: A, D, B
Output: (E,B)| Report Duplicate | Flag | PURGE
Facebook Intern Trees and Graphs - 1of 1 vote
AnswersWrite a Junit test for the following 2 methods in the class which test for properties file as well:
- newbieJunit September 16, 2016 in India
public class Test{
private HashMap<String, String> aTCN;
private static final String alpha= "alpha.";
private static final String beta = "beta.";
private Properties exporterConfig;
private static final ADFLogger LOG = ADFLoggerFactory.getLogger("R",R.class);
public Map<String, String> getATCN() {
if (aTCN== null) {
aTCN= new HashMap<>();
Properties demo= new Properties();
try {
demo.load(ClassLoader.getSystemResourceAsStream("r1.properties"));
} catch (IOException e) {
LOG.emitError("", e.getMessage());
}
for (String columnName : demo.stringPropertyNames()) {
aTCN.put(columnName.replace(beta, ""),
demo.getProperty(columnName).replace(alpha, ""));
}
}
return aTCN;
}
public Properties getEC() {
if (eC== null) {
try {
exporterConfig = new Properties();
exporterConfig.load(ClassLoader.getSystemResourceAsStream("r2.properties"));
} catch (IOException e) {
LOG.emitError("", e.getMessage());
}
}
return eC;
}
}
I was unable to figure out the same. Let me know if any one has any solution.| Report Duplicate | Flag | PURGE
Amazon Intern Testing - 1of 1 vote
AnswersI was asked in an interview: You are given a dump file of IPv4 addresses. You are to find 4 most common occurring subnets. Lets say an IP address if of type a.b.c.d you have to find most common occurring four subnets of the form,
a.*.*.*
a.b.*.*
a.b.c.*
a.b.c.d
Here * matches anything.
My first solution was build an in memory hashtable. Given an IP address a.b.c.d split it as ["a","b","c","d"] and add "a", "a.b", "a.b.c", "a.b.c.d" to the hash table and count it. [There are optimizations possible like considering the entire IP address as a 32 bit unsigned integer and count it with masks and shifts]
Then the question got extended: "assume you can never hold everything in memory, how would you solve it?" Now, the very first solution that I could say was to do an external sort and then count it.
The next solution I gave was to split the IP addresses into buckets. The algorithm was,while there is an IP IP <- an IP address a <- first quadruple push IP to bucket[a]
The bucket which has maximum elements would give me the a.*.*.* solution. Now take each bucket and do the same. Even though this might give the correct result, in worst case I might end up having 255^4 buckets.
- miscanon July 15, 2016 in United States
This is indeed an open ended question with more than one correct answer. What would be the best way to solve this?| Report Duplicate | Flag | PURGE
Google Intern Algorithm - 0of 0 votes
AnswerGiven is an algebraic expression involving only positive integers and the operators +
- rahul123jadhaav March 30, 2016 in India
and - . Design a greedy O(n) and dyamnic O(n3) solution.
For example, 5 + 3 − 6 − 7, the maximum possible value of the
expression is 7. One way of achieving this value is by parenthesizing as follows: (5 +
(3 − (6 − 7)))| Report Duplicate | Flag | PURGE
StartUp Intern Coding - 0of 0 votes
AnswersGiven a set of numbers {x1, x2, x3, x4, ..., xN} (N>=3) a set of its pairwise sums is {x1+x2, x1+x3, x1+x4, x2+x3,x2+x4,x3+x4, ...,}. (That is s_k = x_i + x_j where i != j)
Restore a set of numbers given a set of its pairwise sums.
Note: you don't know given some k, to which i and j it refers, (i.e. input is given in undefined order)
EDIT: couldn't comment, so here is clarification
Example:S = {1, 5, 10, 100} (n elements) P = {6, 11, 101, 15, 105, 110} (n * (n - 1) / 2 elements)
Given P you have to restore S.
Note here means that if you knew which element in P corresponded to which pair of indices in S, you could just solve a simple linear equation
- emb February 22, 2016 in United Statesx1+x2=a{k1} x2+x3 = a{k2}, ...., x{n-1} + x{n} = a{k{n-1}, x{n} + x1 = a{k{n}}
| Report Duplicate | Flag | PURGE
Facebook Intern - 0of 0 votes
AnswersToday is school picture day and everybody,
- ritikashah017 February 11, 2016 in United States
including the teacher, has lined up in a single line for the class picture.
Design an O(n log n) Java code that computes the minimum number of swaps necessary to be in order| Report Duplicate | Flag | PURGE
Amazon Intern Java - -5of 5 votes
AnswersGiven is a large paper with n different points with coordinates (x1, y1),(x2, y2), . . . ,(xn, yn).
- ritikashah017 February 11, 2016 in United States
Keep folding at 45 degres| Report Duplicate | Flag | PURGE
Amazon Intern Java - 0of 0 votes
AnswerWe have board represented using matrix (i.e Board[N][N],
- anshkun January 22, 2016 in India for 1
We have right angle triangle with same height, base and area of four types.
Types can be distinguish using points
i.e {1,0,1,1}, {1,1,0,1} etc which makes a right angle triangle in one block. We have to identify total count each triangle type. There are multiple cases
1. Include every possible triangle shape one can overlap with other triangle cell
2. Include every possible triangle shape without overlap with other triangle cell
3. Include adjacent triangles only (exclude triangle which is adjacent to two triangles )
4.Include adjacent triangles only
i.e : Input pattern
110011
100101
110110
000001
We see one triangle is getting formed a[0][0],a[0][1] and a[1],[0]
Triangles are adjacent if vertical and horizontal values are one.| Report Duplicate | Flag | PURGE
HCL Intern Algorithm - 6of 6 votes
AnswersGiven a sorted array of size N of int32, find an element that repeats > ceil(N / 2) times. Your algo may assume that there will be always such element. Space/time O(1).
- emb January 18, 2016 in United States
Follow up question: Now element repeats > ceil(N / 4) times. Space/time O(1)| Report Duplicate | Flag | PURGE
Google Intern - 3of 3 votes
AnswersGiven a forest of balanced binary trees and two nodes, n1 and n2, find the closest common parent of n1 and n2. Nodes have parameters "parent", "left" and "right", and you cannot access the values of the nodes. If n1 and n2 are not on the same tree, return NULL.
- Matt Cooper December 26, 2015 in United States for Software Engineering
Try to do this in O(log(n)) time and O(1) space.| Report Duplicate | Flag | PURGE
Facebook Intern Trees and Graphs - -1of 3 votes
Answerswrite a method that takes in 2 int arrays of any size and returns an array that calculates the sum of both.
- J@sper November 26, 2015 in United States for -
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| Report Duplicate | Flag | PURGE
Google Intern Arrays - 1of 1 vote
AnswersGiven an array of positive integers (excluding zero) and a target number. Detect whether there is a set of consecutive elements in the array that add up to the target.
- m.mirzamo October 28, 2015 in United States
Example: a = {1, 3, 5, 7, 9}
target = 8
output = true ({3, 5})
or target = 15
output = true : {3, 5, 8}
but if target = 6, output would be false. since 1 and 5 are not next to each other.| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 0of 0 votes
AnswersGiven an array of integers. Modify the array by moving all the zeros to the end (right side). The order of the other elements doesn't matter.
- m.mirzamo October 28, 2015 in United States| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm Data Structures - 0of 0 votes
AnswersHow would you go about testing a distributed system such as Gmail, before releasing it to the public. How would you simulate realistic server load?
- Ray October 17, 2015 in United States| Report Duplicate | Flag | PURGE
Google Intern Distributed Computing