## Software Developer Interview Questions

- 0of 0 votes
You are given a stream of numbers which represent the stock prices of a company with timestamp. You need to perform some set of operations on the stream of data efficiently as below: 1. findStockPriceAtGivenTimeStamp(Timestamp) 2. deleteAndGetMinimumStockPriceForToday() Timstamp: 1 2 3 . 4 . 5 Prices: 12 34 4 . 1 . 18

- 0of 0 votes
Write algorithm for java grep command for word matching in the following context.Given a file containing n words.Given a word w and a number k.Find k words in the file occuring before occurence of w.Assume that the average word size is m in the file

eg.

aaa

bbb

ccc

booking

alpha

beta

gamma

for k=3 and w = booking

the output should be [aaa,bbb,ccc,booking]

similarly for k =2 and w = beta

output should be [booking,alpha,beta]

Assume that the file size can grow very large

and try to get solution with space complexity lesser than O(n)

I suggessted solution for iterating through file until the word w is found and maintaiining a queue of size K

The time complexity of my solution was O(nm)

and space complexity was O(k) .Any answers to improve the time and space complexity

Apparently they were looking for a better implementation of grep

- 1of 1 vote
We start with a list of Integers. We can remove a group of integers from the list if the all but one equals the remaining number. This removal operation can be performed in the remaining number of list until no more operations can be performed.

Write a function which can accept an array of integers, and return the minimal number of remaining integers from performing this operation.

Example [1, 3, 5, 6] -> remove 1, 5, 6 , because 1 + 5 = 6, thus only [3] left, so return 1

[48, 20, 1, 3, 4, 6, 9, 24] -> remove 3, 6, 9 , because 3 + 6 = 9, and remove 4, 20, 24, 48, because 4 + 20 + 24 + 48, thus only [1] left, so return 1

int left(int[] nums){

}

- 0of 0 votes
Consider an N*N game board, with a black and white pieces that can be placed on it. You are given a board with placed pieces around it in a random spots.

You need to implement a function that determines if a piece (black or white) is captured on a given coordination (x, y).

A piece is defined as captured by the following rules:

1. If all sides (up, down, left & right) contains an opposite piece that surrounds/blocking it.

2. If some of the sides are blocked (for example, right and down) and the other ones are out of bound (OOB defined for coords: x: <= 0, y: <= 0) it's considered as blocked.

3. If one of the sides is empty, it's free.

4. If one of the sides contains the same piece type, and that piece is not captured (by the rules above), it's free.

5. Note that pieces may be captured in a clustered way (related to #4).

For example, consider the following coordinates:

coord(1,1) = B

coord(1,2) = W

coord(2,1) = W`X | 1 | 2 1 | B | W 2 | W |`

For the given coordination 1,1 the result would be `captured` (true).

Another example, consider the following coordinates:

coord(2,2) = W

coord(2,3) = W

coord(3,1) = W

coord(3,2) = B

coord(3,3) = B

coord(3,4) = W

coord(4,2) = W

coords(4,3) = W`X | 1 | 2 | 3 | 4 | 5 | 2 | E | W | W | W | E 3 | W | B | B | B | W 4 | E | W | W | W | E`

For the given coordination 3,2 (or 3,3) the result would be `true` (captured).

If we would either remove one of the W coords (thus making it empty), or change it to be a B piece, the result would be `false` (not captured).

As basic primitive, you are provided with a function that translates coordination into its state:`getState (x, y) == Black, White, Out Of Bound, Empty`

- 1of 1 vote
Explain the Data Structure which is well suited to implement UNIX commands like PWD, LS, MKDIR, CD in an imaginary OS. No code required.

- 0of 0 votes
Unsorted array and a position ‘P’. Return the element that is likely to come to the given location upon sorting the array. TC in O(n).

- 0of 0 votes
A thief trying to escape from a jail has to cross ‘N’ walls each with varying heights. He climbs ‘X’ feet every time. But, due to the slippery nature of those walls, every times he slips back by ‘Y’ feet. Now the input is given as (N, {H1, H2, H3,….Hn}, X, Y}. Calculate the total number of jumps required to cross all walls and escape from the jail.

- 0of 0 votes
transactions = [

{"payee": "BoA", "amount": 132, "payer": "Chase"},

{"payee": "BoA", "amount": 827, "payer": "Chase"},

{"payee": "Well Fargo", "amount": 751, "payer": "BoA"},

{"payee": "BoA", "amount": 585, "payer": "Chase"},

{"payee": "Chase", "amount": 877, "payer": "Well Fargo"},

{"payee": "Well Fargo", "amount": 157, "payer": "Chase"},

{"payee": "Well Fargo", "amount": 904, "payer": "Chase"},

{"payee": "Chase", "amount": 976, "payer": "BoA"},

{"payee": "Chase", "amount": 548, "payer": "Well Fargo"},

{"payee": "BoA", "amount": 872, "payer": "Well Fargo"},

There are multiple transactions from payee to payer. Consolidate all these transactions to minimum number of possible transactions.

HINT: Consolidate transitive transactions along with similar transactions

For Example in the above program, the result is a single transaction [ Boa -> 482 -> Wells Fargo ]

- 0of 0 votes
Design a space shooter program .

Note: The game includes spaceship , bullets and asteroids. Spaceship rotates in 180 degree generating bullets. The position of the bullets gets updated after certain time period every time . No Need to write the code for collision detection

Basic code in expected . Not the entire working code.

- 0of 0 votes
Given a list/array of "Assign" trees with integers, operators and variables, return the result of the requested "Result" tree expression.

Example:`"Assign" / \ "x" "+" / \ 2 3 "Assign" / \ "y" "-" / \ 5000 30 "Assign" / \ "z" "*" / \ 50 x "Return" \ "-" / \ z "*" / \ 1 y`

- 2of 2 votes
The array of integers in given . The array indicates nothing but the heights of the cylinders. The robotic arm has two ends-> left and right.

The left end points to the left end of the cylinder array and right end searched for the cylinder with least height.

ex:

array = {4,5,6,7,1,2}

left end => index 0

right end =>index 0->n giving index 4 with min height

Now the entire block is rotated by 180 degree.

now the array = { 1, 7, 6, 5, 4, 2}

now the left end moves forward.

and right end will search from left index onwards till the end of the array

so left index = 1

right index => 1-> n giving index 5 as min. height

again do the block rotate .

Write the code for this particular algorithm.

However, there is one condition

1. If there are duplicates in the array then the final order of those duplicates should remain the same.

ex. If the cylinder with height 4 is appearing at index 3 and 5 in the initial array then the cylinder at index 3 should always appear before the one at index 5 in the final array.

- 0of 0 votes
The array of integers in given . The array indicates nothing but the heights of the cylinders. The robotic arm has two ends-> left and right.

The left end points to the left end of the cylinder array and right end searched for the cylinder with least height.

ex:

array = {4,5,6,7,1,2}

left end => index 0

right end =>index 0->n giving index 4 with min height

Now the entire block is rotated by 180 degree.

now the array = { 1, 7, 6, 5, 4, 2}

now the left end moves forward.

and right end will search from left index onwards till the end of the array

so left index = 1

right index => 1-> n giving index 5 as min. height

again do the block rotate .

Write the code for this particular algorithm.

However, there is one condition

1. If there are duplicates in the array then the final order of those duplicates should remain the same.

ex. If the cylinder with height 4 is appearing at index 3 and 5 in the initial array then the cylinder at index 3 should always appear before the one at index 5 in the final array.

- 1of 1 vote
Generate a random number with UNIFORM DISTRIBUTION between [0,n) where n is given and excluded list is given. The randomly generated number should belong to the range [0, n) but should be excluded from the given excluded list. For example, n = 10 and excluded list ={2,3,0} then the random number should be from {1,4,5,6,7,8,9} such that any number from the list {1,4,5,6,7,8,9} has UNIFORM probablility of occuring

- 0of 0 votes
Perform left and right shift on string

- 0of 0 votes
Find max sum of sub array.

- 0of 0 votes
Implement stack using a queue.

- 0of 0 votes
Merge the overlapping intervals.

- 0of 0 votes
Reverse the words in string eg. 'The Sky is Blue'. then print 'Blue is Sky The'.

- 0of 0 votes
Find max sum of subarray

- 0of 0 votes
java program to interchage continous vowels in a string

ex:vowels

becomes vewols

continuous becomes cintonouuus

- 1of 1 vote
Consider an implementation of Strings consisting of an array where the first element of the array indicates the length of the String and the next elements represent the value of the ASCII characters in the String. Implement String concatenation and discuss shortcomings of this operation under this implementation of Strings.

- 0of 0 votes
Suppose that there exists a service to fetch Facebook posts through an interface defined by you, design the Facebook wall feed.

- 2of 2 votes
Given an array of ints and a value X, find wether there are 3 elements in the array such that their sum is X (return true/false).

- 0of 0 votes
Given two vectors that might be sparse, calculate their Dot product. You can assume any data structure to represent the vectors.

- 0of 0 votes
Given a matrix of characters where '_' represents an empty space, 'T' is a tree and 'H' is a house and a coordinate of that matrix, find the sum of the minimum distances from that coordinate to each house when considering that you can move through empty spaces and houses but not through trees.

- 0of 0 votes
Reverse a linked list.

- 0of 0 votes
Given two tree nodes and the root of a tree, find the distance between both nodes in the tree.

- 0of 0 votes
Given a String that contains parenthesis, remove the least amount of parenthesis from it such that it becomes balanced.

- 0of 0 votes
How would you store very large numbers that can't be store in a regular Integer or BigInteger, and make calculations

- 0of 0 votes
Design an application for people to find a place near them where they can join a team to play their favorite sport. Exp. Soccer teams open to join that are scheduled to play at a certain time and place. The application would search for the available teams to join within certain area playing within some given time period,