## Senior Software Development Engineer Interview Questions

- 0of 0 votes
Given 3 sorted arrays. Find(x,y,z), (where x is from 1st array, y is from 2nd array, and z is from 3rd array), such that x<y<z.

x = element(s) from array 1

y= element(s) from array 2

z = element(s) from array 3

I can have more than 1 elements from each array. But at least 1 from each array is mandatory and elements from .`int[] arr1 = {3}; int[] arr2 = {11, 13, 16}; int[] arr3 = {45}; Correct Output : 7 (3,11,45) (3,13,45) (3,13,16,45) (3,16,45) (3,11,13,45) (3,11,16,45) (3,11,13,16,45)`

Need to find the number of such sequences.

- 1of 1 vote
You have two servers. Both of these servers have an identical file with billion characters except for one single character. These servers are connected over a very slow connection.

How do you find the different character?

My ans: split those files in to batches of characters of 10,000 (say), now calculate checksum and compare the checksums for the chunks of 10,000 character lines. So now you are just comparing 'ints' and not the files per say. (remember the connection is very slow)

His question: How do you optimize this?

- 0of 0 votes
Write a Java Program in which a class takes four integer arguments as input(a, b, c and d). Do addition of (a+b) on one thread, addition of (c+d) on another thread and multiplication of(a+b) * (c+d)) on main thread.

Like: Thread1 = (a+b)

Thread2 = (c+d)

Main Thread = (Thread1 * Thread2)

- -1of 1 vote
Given a few pairs of names in the order child, father. The input is a person name and level number. The output should be the number of children in that particular level for the person given.

Example:

Input:

[

{Ram, Syam},

{Akil, Syam},

{Nikil, Ram},

{Subhash, Ram},

{Karthik, Akil}

];

Syam 2

Output: 3 (Syam has Ram and Akil in level 1 and in level 2 he have Nikil, Subhash, Karthik. So the answer is 3).

- 0of 0 votes
Create a RESTful microservice that implements a card shuffling algorithm, as defined below. Should have evidence of test-driven development with unit tests. Use best practices of interfaces and generics for abstraction, preferably implementing a strategy pattern for deploy-time dependency injection of a shuffling algorithm.

Requirements:

· Create a microservice that stores and shuffles card decks.

· A card may be represented as a simple string such as “5-heart”, or “K-spade”.

· A deck is an ordered list of 52 standard playing cards.

· Expose a RESTful interface that allows a user to:

· PUT an idempotent request for the creation of a new named deck. New decks are created in some initial sorted order.

· POST a request to shuffle an existing named deck.

· GET a list of the current decks persisted in the service.

· GET a named deck in its current sorted/shuffled order.

· DELETE a named deck.

· Design your own data and API structure(s) for the deck.

· Persist the decks in-memory only, but stub the persistence layer such that it can be later upgraded to a durable datastore.

· Implement a simple shuffling algorithm that simply randomizes the deck in-place.

· Implement a more complex algorithm that simulates hand-shuffling, i.e. splitting the deck in half and interleaving the two halves, repeating the process multiple times.

· Allow switching the algorithms at deploy-time only via configuration.

- 0of 0 votes
public interface FirstCommonAncestor {

/**

* Given two nodes of a tree,

* method should return the deepest common ancestor of those nodes.

*

* A

* / \

* B C

* / \ \

* D E H

* / \

* G F

*

* commonAncestor(D, F) = B

* commonAncestor(C, G) = A

* commonAncestor(E, B) = B

*/

Node commonAncestor(Node one, Node two);

}`class Node { final Node parent; final Node left; final Node right; public Node(Node parent, Node left, Node right) { this.parent = parent; this.left = left; this.right = right; } boolean isRoot() { return parent == null; } }`

- 0of 0 votes
With given Binary Tree below, traverse the tree and print the tree from bottom up order

1

/ \

2 3

/\ /\

4 5 6 7

output: 4567231

Hint: the traverse is called "Level Order Tree Traversal"

I hope someone memorize this traversal and pass the exam and all these companies judging canditates with one algorithm could think they hired the best canditate.

- 1of 1 vote
determine whether a word is in a stored list;

the list doesn't fit into memory;

no disk access allowed, for lookups, memory access only;

no false positives allowed, false negatives ok

- 1of 1 vote
Design a service to generate unique 64 bit IDs

- 0of 0 votes
Write a code to convert from long type time to date using java?

Eg: 324561092314 to 02/20/2015

- 0of 0 votes
Write a code to find index of integer item in an integer array using java? Note : Complexity should be less than O(n) or with out using any for loop.

- 3of 3 votes
Given an array of 1 billion numbers with just a few 100 missing, find all the missing numbers. you have only enough memory to store only 10k elements

- 0of 0 votes
You are designing the client side of a Survey website. Provide the list of classes and methods you will use to break the problem down. Also, provide the API interaction with server.

- -1of 1 vote
You are given the arrival and departure times of airplanes at an airport for a single day. Schedules for the airplanes remain the same across all days. You are to determine the number of gates the airport should have so that no plane spends time waiting for a gate.

arr = [9:30, 11:15, 16:30]

dep = [11:45, 11:30, 16:45]

Arr array is sorted by time. And departure array is sorted by corresponding arrival times. Plane 'i' arrives at time arr[i] and departs at time dep[i]

Notes:

After some questions, it was decided that minute was the smallest unit of time we cared about. Gate was considered occupied on the arriving minute, but empty on the departing minute. And that the arrival and departure times could be represented as such as integers. e.g. Day runs from minute 0 to minute 1339 (since using a zero-based index). So our example times represented as:

arr = [570, 675, 990]

dept = [705, 690, 1005]

- 0of 0 votes
Given a list L of numbers from 0 to n, and another number k = [0-9], find how many times k appears in L. If the target number in L is more than one digit, treat each digit separately. For example, k=0 appears twice in L = [0,10].

- 1of 1 vote
Two friends Kohli and Dhoni want to test their friendship to check how compatible they are. Given a list of n movies numbered 1,2,3....n and asked both of them to rank the movies.

Design an algorithm to find compatibility difference between them.

Compatibility difference is the number of mis-matches in the relative rankings of the same movie given by them i.e. if Kohli ranks Movie 3 before Movie 2 and Dhoni ranks Movie 2 before Movie 3 then its a relative ranking mis-match Compatibility difference is the maximum number of mis-matches

Sample Input

5

31245

32415

Sample Output

2

Explanation

Movies are 1,2,3,4,5. Kohli ranks them 3,1,2,4,5, Dhoni ranks them 3,2,4,1,5. Compatibility difference is 2 because Kohli ranks movie 1 before 2,4 but Dhoni ranks it after.

- 2of 2 votes
Swap the elements in Kth position from the start and end of a link list.

ex:

input: list: 1,2,4,5,7,8 & K=2

output: 1,7,4,5,2,8

- 0of 0 votes
Basic background questions, describe a situation where you proposed a design and it was opposed. What did you do to convince people that your design was sound. Describe a situation where something you suggested resulted in improved process or caused a big positive impact on the company, etc.

- 0of 0 votes
Implement a TwoSum interface that has 2 methods: Store and Test. Store adds an integer to an internal data store and Test checks if an integer passed to Test is the sum of any two integers in the internal data store. Once you provide an answer interviewer will ask the O complexity of the solution and ask you to optimize it.

I provided 2 solutions, one with O(n-square) and another O(n). However the O(n) solution used 2 internal data stores. I was asked to preserve O(n) but not use the second internal store`public interface TwoSum { /* * Stores input in an internal data structure. */ public void Store(int input); /* * Returns true if there is any pair of numbers in the internal data structure which * have sum val, and false otherwise. * For example, if the numbers 1, -2, 3, and 6 had been stored, * the method should return true for 4, -1, and 9, but false for 10, 5, and 0 */ public bool Test(int val); } public class TwoSumImpl : TwoSum { private List<int> _store = new List<int>(); private List<int> _sums = new List<int>(); public void TwoSumImp() { } //-3,-2,3,5,7 //-5,0,1,-2,-3,8, public void Store(int input) { if(!_store.Contains(input)) { _store.Add(input); } } public bool Test(int val) { for(int i=0; i<_store.Count;i++) { if(_store[i] < 0) //store[i] is negative { diff = val + Math.Abs(_store[i]); if(_store.Contains(diff)) { return true; } } else //store[i] is positive { diff = val - _store[i]; if(_store.Contains(diff)) { return true; } return false; } } }`

- 0of 0 votes
Given an integer array A of size N. Find the number of increasing sub-sequences of this array with length >= 1 and GCD = 1.

A sub-sequence of an array is obtained by deleting some (or none) elements and maintaining the relative order of the rest of the elements.

Example:-

[1] = 1

[1,2] = 2

[1,2,3] = 5

- 0of 0 votes
There is a famous algorithm on geeksforgeeks to specify the minimum number of insertions to convert a string to palindrome.

http://www.geeksforgeeks.org/dynamic-programming-set-28-minimum-insertions-to-form-a-palindrome/

But the question that was asked to me was one step ahead, interviewer asked to tell the characters that need to be appended to the string to make it a palindrome.

- 0of 0 votes
LRU Cache

- 1of 1 vote
WAP to take one element from each of the array add it to the target sum. Print all those three-element combinations.

/*

A = [1, 2, 3, 3]

B = [2, 3, 3, 4]

C = [1, 2, 2, 2]

target = 7

*/

Result:

[[1, 2, 4], [1, 3, 3], [1, 3, 3], [1, 3, 3], [1, 3, 3], [1, 4, 2], [2, 2, 3], [2, 2, 3], [2, 3, 2], [2, 3, 2], [3, 2, 2], [3, 2, 2]]

- 1of 1 vote
Find the anagrams from a list of strings

Input : {"tea", "ate", "eat", "apple", "java", "vaja", "cut", "utc"}

Output : {"tea", "ate", "eat","java", "vaja", "cut", "utc"}

- 0of 0 votes
You are given an scenario where there is an Worker object. Each Worker object has one mandatory field unique id workerId and their are few other non unique and not mandatory Ids : DeptId and UnitID.

Design an cache for your Worker objects considering the fact that most of the queries on your cache will be on unitId. If the there is an query for an Worker which is not available in your cache then that data will be fetched from the server.

Design an cache such that there will be minimum number of server calls. Imagine there are 100;s of such non unique ids non mandatory Ids in the Worker object and you have to design the cache so that your client can query on any given id with minimum calls to server.

Your Worker object looks like this:

Worker1=> workerid=1, deptId=>765, unitId=>123 Name=“” Surname=“” Data=“”

Worker2=> workerid=2 , deptId=>765 Name=“” Surname=“” Data=“”

Worker3=> workerid=3, unitid=>123 Name=“” Surname=“” Data=“”

so when your client queries using unitId getWorkersbyUnitId(123) it should return Worker1 and Worker3.

If query is on deptId 765 then it should return Worker1 and Worker2

You can assume there is never an query on individual workerId.

other information given while discussion is you can query the server using any id and all the worker objects of that id will be fetched by that single call: Example there are 10 workers associated with untId: 99 then server call to getserverUnitIdWorkers(99)-> will output list of 10 workers. Each unitId or any other non mandatory id has approximate 8 to 10 workers associated with it. And there are millions of such unitIds.

- 0of 0 votes
Find out if there is cycle in Directed graph

- -1of 1 vote
Given billions of Rectangle, find rectangle with minimum area overlapping to a given point P(x,y)

There is a simple way to achieve answer in O(n) by processing each rectangle sequentially, but optimize it further provided large number of Rectangle array.

- 2of 2 votes
Write a code to reverse the words in a sentence.

- 1of 1 vote
what is the best sorting algorithm in terms of complexity and why?

- 0of 0 votes
What is the best way to merge unsorted list and generate a single sorted list ?

I was giving an option of inserting into Binary tree from both list and retrieve it.what is the best solution