Linkedin Interview Questions
- 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 - 0of 0 votes
AnswersThere is a particular sequence that only uses numbers 1, 2, 3, 4 and no two adjacent numbers are the same.
- abc October 16, 2014 in India
Write a program that given n1 1s, n2 2s, n3 3s, n4 4s will output the number of such sequences using all these numbers.
Output your answer modulo 1000000007 (10^9 + 7).| Report Duplicate | Flag | PURGE
Linkedin Site Reliability Engineer Algorithm - 1of 1 vote
Answers/* In "the 100 game," two players take turns adding, to a running
- you.win September 24, 2014 in United States for Mobile
total, any integer from 1..10. The player who first causes the running
total to reach or exceed 100 wins.
What if we change the game so that players cannot re-use integers?
For example, if two players might take turns drawing from a common pool of numbers
of 1..15 without replacement until they reach a total >= 100. This problem is
to write a program that determines which player would win with ideal play.
Write a procedure, "Boolean canIWin(int maxChoosableInteger, int desiredTotal)",
which returns true if the first player to move can force a win with optimal play.
Your priority should be programmer efficiency; don't focus on minimizing
either space or time complexity.
*/
Boolean canIWin(int maxChoosableInteger, int desiredTotal) {
// Implementation here. Write yours
}| Report Duplicate | Flag | PURGE
Linkedin Senior Software Development Engineer Algorithm - 4of 4 votes
AnswersGiven a binary tree where all the right nodes are leaf nodes, flip it upside down and turn it into a tree with left leaf nodes.
Keep in mind: ALL RIGHT NODES IN ORIGINAL TREE ARE LEAF NODE.
- PrateekS. July 29, 2014 in United States/* for example, turn these: * * 1 1 * / \ / \ * 2 3 2 3 * / \ * 4 5 * / \ * 6 7 * * into these: * * 1 1 * / / * 2---3 2---3 * / * 4---5 * / * 6---7 * * where 6 is the new root node for the left tree, and 2 for the right tree. * oriented correctly: * * 6 2 * / \ / \ * 7 4 3 1 * / \ * 5 2 * / \ * 3 1 */
| Report Duplicate | Flag | PURGE
Linkedin - 2of 2 votes
AnswersPrint a tree in Level Order with a newline after each depth
- PrateekS. July 29, 2014 in United States/** * Sample input: * * 1 * / \ * 3 5 * / \ \ * 2 4 7 * / \ * 9 8 * * Expected output: * 1 * 3 5 * 2 4 7 * 9 8 * ========== */
| Report Duplicate | Flag | PURGE
Linkedin Algorithm - 1of 1 vote
AnswersWrite a program that gives count of common characters presented in an array of strings..(or array of character arrays)
- satya June 16, 2014 in United States
For eg.. for the following input strings..
aghkafgklt
dfghako
qwemnaarkf
The output should be 3. because the characters a, f and k are present in all 3 strings.
Note: The input strings contains only lower case alphabets| Report Duplicate | Flag | PURGE
Linkedin Algorithm - 0of 2 votes
AnswersGiven a string array ex: [1, 2, 3], find the permutation in best time.
- Invhelper May 05, 2014 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Coding - 0of 0 votes
Answers
- sh88990 May 02, 2014 in United States/* This class will be given a list of words (such as might be tokenized * from a paragraph of text), and will provide a method that takes two * words and returns the shortest distance (in words) between those two * words in the provided text. * Example: * WordDistanceFinder finder = new WordDistanceFinder(Arrays.asList("the", "quick", "brown", "fox", "quick")); * assert(finder.distance("fox","the") == 3); * assert(finder.distance("quick", "fox") == 1); * /
| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 0of 0 votes
Answerspublic interface FirstCommonAncestor {
- gul2u April 30, 2014 in United States
/**
* Given two nodes of a tree,
* method should return the deepest common ancestor of those nodes.
*
* A
* / \
* B C
* / \ \
* D E M
* / \
* G F
*
* commonAncestor(D, F) = B
* commonAncestor(C, G) = A
*/
public Node commonAncestor(Node nodeOne, Node nodeTwo)
{
}
}
class Node {
final Node parent;
final Node left;
final Node right;
public Node(Node parent, Node left, Node right, data) {
this.parent = parent;
this.left = left;
this.right = right;
this.data = data
}
boolean isRoot() {
return parent == null;
}
}| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersFind the maximum sum subset in an array with negative integers
- intervyou April 23, 2014 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 0of 0 votes
Answersfind the Maximum product subset with negative and positive integer
- intervyou April 23, 2014 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 1of 1 vote
AnswersGiven a list of tuples representing intervals, return the range these intervals
- Tonytan4ever April 16, 2014 in United States for Tools
covered.
e.g:
[(1,3), (2,5),(8,9)] should return 5| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 0of 0 votes
AnswersGiven a sorted array with duplicates and a number, find the range in the
- JobSeeker April 09, 2014 in United States
form of (startIndex, endIndex) of that number. For example,
find_range({0 2 3 3 3 10 10}, 3) should return (2,4).
find_range({0 2 3 3 3 10 10}, 6) should return (-1,-1).
The array and the number of duplicates can be large.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer in Test - 1of 1 vote
AnswersWord Wrap / String Justification algorithm.
- code_monkey April 07, 2014 in United States
Given a set of words and a length.
You are required to print the words such that the words on each line end almost on the same column and the number of trailing spaces at the end is minimized.
Given aaa bb cc ddddd and length is 5 print the following output.
aaa
bb cc
ddddd| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
Answers
- shoudaw April 02, 2014 in United States/* * Returns true if the input string is a number and false otherwise */ public boolean isNumber(String toTest) { // implementation here }
| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
Answers
- shoudaw April 02, 2014 in United States/** * Implement a method which takes an integer array and returns an integer array (of equal size) in * which each element is the product of every number in the input array with the exception of the * number at that index. * * Example: * [3, 1, 4, 2] => [8, 24, 6, 12] */ public int[] selfExcludingProduct(int[] input) { // implementation... }
| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - -1of 1 vote
AnswerProgram to count all Response codes individually per database ( slideshare_backedn_fe01 is one db) in the given log file'
- swathi1243 March 09, 2014 in United States
output should like this
{
backend : backend name
{
200: 20
503: 3 where 3 is count of response codes 503
}
}
once again logfile looks like this
May 29 13:53:13 127.0.0.1 haproxy[27326]: 164.85.131.129:15592 [29/May/2013:13:53:13.671] slideshare slideshare_backend/fe01 1/0/1/106/296 200 451 - - --VN 1526/1526/837/402/0 0/0 {www.slideshare.net|Mozilla/5.0 (Windows NT 5.1; rv:10.0.4) Gecko/20100101 Firefox/10.0.4|http://www.slideshare.net/slideshow/embed_code/11959978?hostedIn=slideshare&referer=http://www.slideshare.net/goulart.sousa|} {2471317690|||pingback/embed_or_homepageplayerhits|s11959978/a8717995|} "GET /pingback/embed_or_homepageplayerhits/11959978?ref=http%3A%2F%2Fwww.slideshare.net
%2Fgoulart.sousa&_=1369853592559 HTTP/1.1"
May 29 13:53:13 127.0.0.1 haproxy[27326]: 217.129.26.81:50910 [29/May/2013:13:53:13.724] slideshare slideshare_backend/fe02 17/0/0/1/246 200 3291 - - --VN 1529/1529/839/435/0 0/0 {www.slideshare.net|Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)|http://www.slideshare.net/inexita/4|} {1098476889 1090975733|||||} "GET /images/fadedlogo.jpg?829e162373dc3b1cc145ba5b62aba32c8c804b67 HTTP/1.1"
May 29 13:53:13 127.0.0.1 haproxy[27326]: 79.154.237.97:50310 [29/May/2013:13:53:13.758] slideshare autosuggest_backend/solrsearch10_01 13/0/0/3/212 200 526 - - ---- 1528/1528/17/3/0 0/0 {autosuggest.slideshare.net|Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36|http://www.slideshare.net/faroviejo/las-10-ciudades-ms-grandes-del-mundo-y-la-paz-bcs|} {|||||} "GET /?q=las?10?ciudades?ma*&rows=5&wt=json&sort=frequency%20desc&fq=%2Bresults%3A%5B10%20TO%20*%5D&json.wrf=jQuery17209988682114053518_1369853526684&_=1369853590254 HTTP/1.1"| Report Duplicate | Flag | PURGE
Linkedin Site Reliability Engineer Algorithm - 2of 2 votes
Answers/**
- duskan February 22, 2014 in United States
* Returns a^b, as the standard mathematical exponentiation function
*/
public double pow(double a, int b) {}
Interviewer looking for log(n) solution, right on first attempt.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 1of 1 vote
Answers/**
- duskan February 22, 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, one 6 at depth2)
*/
/**
* This is the interface that represents nested lists.
* You should not implement it, or speculate about its implementation.
*/
public interface NestedInteger
{
// Returns true if this NestedInteger holds a single integer, rather than a nested list
public boolean isInteger();
// Returns the single integer that this NestedInteger holds, if it holds a single integer
// Returns null if this NestedInteger holds a nested list
public Integer getInteger();
// Returns the nested list that this NestedInteger holds, if it holds a nested list
// Returns null if this NestedInteger holds a single integer
public List<NestedInteger> getList();
}| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
Answerspublic interface Permutations {
- Anon February 19, 2014 in United States
/**
* Generate all permutations of given sequence of elements.
* Return a list of all distinct permutations.
*
* E.g.
* generate([1, 2, 3]) -> [1, 2, 3], [1, 3, 2], [2, 3, 1], [2, 1, 3], [3, 1, 2], [3, 2, 1]
*/
vector<vector<int>> generate(vector<int> items);
}| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Coding - 0of 0 votes
Answerspublic interface InfluencerFinder {
- Anon February 19, 2014 in United States
/**
* Given a matrix of following between N LinkedIn users (with ids from 0 to N-1):
* followingMatrix[i][j] == true iff user i is following user j
* thus followingMatrix[i][j] doesn't imply followingMatrix[j][i].
* Let's also agree that followingMatrix[i][i] == false
*
* Influencer is a user who is:
* - followed by everyone else and
* - not following anyone himself
*
* This method should find an Influencer by a given matrix of following,
* or return -1 if there is no Influencer in this group.
*/
int getInfluencer(boolean[][] followingMatrix)| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Arrays - 0of 0 votes
AnswersFill in the following methods:
- abhinav February 09, 2014 in United Statespublic interface PointsOnAPlane { /** * Stores a given point in an internal data structure */ void addPoint(Point point); /** * For given 'center' point returns a subset of 'm' stored points that are * closer to the center than others. * * E.g. Stored: (0, 1) (0, 2) (0, 3) (0, 4) (0, 5) * * findNearest(new Point(0, 0), 3) -> (0, 1), (0, 2), (0, 3) */ Collection<Point> findNearest(Point center, int m); }
| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
Answers
- juny February 04, 2014 in United Statespublic interface Intervals { /** * Adds an interval [from, to] into internal structure. */ void addInterval(int from, int to); /** * Returns a total length covered by intervals. * If several intervals intersect, intersection should be counted only once. * Example: * * addInterval(3, 6) * addInterval(8, 9) * addInterval(1, 5) * * getTotalCoveredLength() -> 6 * i.e. [1,5] and [3,6] intersect and give a total covered interval [1,6] * [1,6] and [8,9] don't intersect so total covered length is a sum for both intervals, that is 6. * * _________ * ___ * ____________ * * 0 1 2 3 4 5 6 7 8 9 10 * */ int getTotalCoveredLength(); }
| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
Answers/**
- juny January 31, 2014 in United States
* Return the smallest character that is strictly larger than the search character,
* If no such character exists, return the smallest character in the array
* @param sortedStr : sorted list of letters, sorted in ascending order.
* @param c : character for which we are searching.
* Given the following inputs we expect the corresponding output:
* ['c', 'f', 'j', 'p', 'v'], 'a' => 'c'
* ['c', 'f', 'j', 'p', 'v'], 'c' => 'f'
* ['c', 'f', 'j', 'p', 'v'], 'k' => 'p'
* ['c', 'f', 'j', 'p', 'v'], 'z' => 'c' // The wrap around case
* ['c', 'f', 'k'], 'f' => 'k'
* ['c', 'f', 'k'], 'c' => 'f'
* ['c', 'f', 'k'], 'd' => 'f'
*/| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 1of 1 vote
AnswersFind minimum distance between two words (order preserved) in a big string.
- techpanja January 29, 2014 in United States
For e.g 1. "hello how are you" - distance between "hello" and "you" is 3.
e.g 2. "hello how are hello you" - distance is 1
e.g 3. "you are hello" - distance is -1. Order of "hello" and "you" should be preserved.
e.g 4. "hello how are hello" - distance is -1 since "you" didnt occur even once.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 0of 0 votes
AnswersFind all the repeating sub-string sequence of specified length in a large string sequence. The sequences returned i.e. the output must be sorted alphabetically.
- techpanja January 21, 2014 in United States
For e.g.
Input String: "ABCACBABC"
repeated sub-string length: 3
Output: ABC
Input String: "ABCABCA"
repeated sub-string length: 2
Output: AB, BC, CA| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 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 - 1of 1 vote
AnswersYou have two arrays of integers, where the integers do not repeat and the two arrays have no common integers.
- Billy Jim October 05, 2013 in United States
Let x be any integer in the first array, y any integer in the second. Find min(Abs(x-y)). That is, find the smallest difference between any of the integers in the two arrays.
Assumptions: Assume both arrays are sorted in ascending order.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
AnswersMaximum value Continuous Subsequence:
- pirate July 25, 2013 in United States
Given array A[n] find continuous subsequence a[i]..a[j] for which sum of elements in the subsequence is maximum.
Ex: {-2, 11, -4, 13, -5, -2} --> 11 - 4 +13 = 20
{1, -3, 4, -2, -1, 6} --> 4 -2 -1 +6 = 7
Time complexity should O(nlogn)| Report Duplicate | Flag | PURGE
Yahoo Microsoft Linkedin Software Engineer / Developer Algorithm Arrays - 0of 0 votes
AnswersGiven a sorted integer array and a number, find the start and end indexes of the number in the array.
- bvinay84 July 11, 2013 in United States
Ex1: Array = {0,0,2,3,3,3,3,4,7,7,9} and Number = 3 --> Output = {3,6}
Ex2: Array = {0,0,2,3,3,3,3,4,7,7,9} and Number = 5 --> Output = {-1,-1}
Complexity should be less than O(n)| Report Duplicate | Flag | PURGE
Linkedin Software Engineer in Test Algorithm