## Developer Program Engineer Interview Questions

- 0of 0 votes
Find out the least recent occurred message.

Suppose your are getting message in streams, and you add it using add("M1").

You need to find out the least recent occurred message at any point of time.

for example,

Add("M1')->Add("M2') then LROM=M1

Add("M1')->Add("M2')->Add("M1') then LROM =M2

Add("M1')->Add("M2')->Add("M1')->Add("M3')-> then LROM =M2

Hope question is clear.

- 0of 0 votes
There is an integer INPUT array {1,2,3,4,5}. Create an OUTPUT array such that each element in output array consists Product of all elements in INPUT array divided by element at that point. But you have to do it without using divide operator (/).

e.g

intput={1,2,3,4,5}

output[0]=(1*2*3*4*5)/1

output[1]=(1*2*3*4*5)/2 and so on.

Don't use divide operator

- -1of 5 votes
20

/ \

8 22

/ \ / \

5 3 4 25

/ \

10 14

traverse this binary tree vertically and its output will be

5

8 10

20 3 4

22 14

25

- 0of 0 votes
Chinese chess has 8*8=64 cells.And the point is (1,1),（1，2）,..............(8,8）.And the horse walks by diagonal line of two cells from where point it is.Calculate the shortest step(s) between two points for the horse to walk. Eg. (1,1) to (4,4). Horse go like this (1,1)>(2,3)>(4,4)

- 0of 0 votes
Chinese chess has 8*8=64 cells.And the point is (1,1),（1，2）,..............(8,8）.And the horse walks by diagonal line of two cells.Calculate the shortest step(s) between two points for the horse to walk. Eg. (1,1) to (4,4). Horse go like this (1,1)>(2,3)>(4,4)

- 1of 1 vote
There are different buildings standing close to each other. These are of same width but different height.

Suppose if rainfall happens, what will be the volume of water that get trapped on top of all these buildings together. ?

INPUT (Example)

No: of buildings : 4

heights of the buildings(in any units): 3 4 3 4

- 0of 0 votes
`You are given an mxn grid, where (0,0) refers top most left position and (m-1,n-1) the bottom most right. The grid is filled with ones. All positions in the grid that are blocked are filled with zeros. You are given this grid and are assured that there exists atleast one path from (0,0) to (m-1, n-1). Find the minimum distance of the path from (0,0) to (m-1, n-1) given that you are allowed to move only vertically, horizontally and diagonally`

- 0of 0 votes
If i have a graph which have n vertices and n-k edges than How many connected component it has ?

- 0of 0 votes
Write an function to judge whether the input String is a number?

For example: "-3.3425","80.0", both of them are number

- 0of 0 votes
what is the heartbleed attack in Network security

- 0of 0 votes
design a algo so that it receive an input

`787668 787787 787948 787980 788094 788124`

and produce the output the difference of two consecutive numbers

`119,161,32,114,30`

the input can varry to any length

- 0of 0 votes
desing a algo so that it receive an input

`787668 787787 787948 787980 788094 788124`

and produce the output the difference of two consecutive numbers

`119,161,32,114,30`

the input can varry to any length

- 0of 0 votes
If a matrix of type float is casted to char *, how is it represented in memory, how to access the array elements.

`float mtrx[200][200] ={ {0}}; char *ptr = (char*)(& mtrx[i][j]);`

- 0of 0 votes
How do a free() knows how much memory has to be free.Suppose

int *p=(int*)malloc(sizeof(int)*100);

after some operation,

free(p);

Now how free() function knows from where to where memory has to be free?

- 0of 0 votes
Write a c program to check number(0123456789) in array of string is valid or not

number is valid only if it is number or number padded with right space

for example char ex[10];

0123456789 valid

012345678a invalid

0123a56789 invalid

01234 invalid

012345678 valid

01234567 valid

12345 invalid

1234 678 invalid

123 4 5678 invalid

- 0of 6 votes
There are a large number of leaves eaten by caterpillars. There are 'K"' caterpillars which jump onto the leaves in a pre-determined sequence. All caterpillars start at position 0 and jump onto the leaves at positions 1,2,3...,N. Note that there is no leaf at position 0.

Each caterpillar has an associated 'jump-number'. Let the jump-number of the i-th caterpillar be A [i]. A caterpillar with jump number 7 keeps eating leaves in the order 1,241,3*1,... till it reaches the end of the leaves - i.e, it eats the leaves at the positions which are multiples of /'.

Given a set 'A' of 'IC elements. 'e<=15.,. 'N'<=109, we need to determine the number of uneaten leaves.

Input Format:

N -number of leaves

A - Given array of integers

Output Format:

An integer denoting the number of uneaten leaves.

Sample Input:

N = 10

A = [2,4,5]

Sample Output:

4

Explanation

1,3,7,9 are the leaves which are never eaten. All leaves which are multiples of 2, 4, and 5 have been eaten.

Java Code:`public class Solution { //need to complete the function below static int countUneatenLeave(int N, int[] A { } public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); final String fileName = System.getenv("OUTPUT_PATH"); BufferedWriter bw = new BufferedWriter(new FileWriter(fileName)); int res; int _N; _N = Integer.parseInt(in.nextLine()); int _A_size = Integer.parseInt(in.nextLine()); int[] _A = new int(_A_size]; int _A_item; for(int _A_i = 0; _A_i < _A_size; _A_i++) { _A_item = Integer.parseInt(in.nextLine()); _A[_A_i] = _A_item; } res = countUneatenLeaves(_N,_A); bw.write(String.valueOf(res)); bw.newLine(); bw.close(); } }`

- 1of 1 vote
Distributing Medals It's the medal distribution ceremony. 10^6 police officers, numbered from 1 to 10^6, are standing in a line. There are N (1<=N<=1000) iterations of medal distribution. In iteration i (0 < = i < N), count[i] ( 1 < = count[i] < = 100) medals are given to all officers from from[i] to to[i] ( 1 < = from[i] < = to[i] < = 10^6 )

If we sum up the number of medals received starting from the first officer, who would be the first officer for which the cumulative sum exceeds a given medal count THRESHOLD ( 1 < = THRESHOLD < = 10^9 )?

Input/Output Specifications Input format:

You are given 5 inputs:

input1 = N, the number of iterations

input2 = count, the array of medal counts in each iteration

input3 = from, the array of starting indices in each iteration

input4 = to, the array of ending indices in each iteration

input5 = THRESHOLD, the medal count threshold

Output format:

An integer, representing the number of the first officer such that the cumulative sum of medals starting from the first officer upto this officer exceeds THRESHOLD. The output should be -1 if such an officer does not exist.

- -2of 2 votes
Distributing Medals It's the medal distribution ceremony. 10^6 police officers, numbered from 1 to 10^6, are standing in a line. There are N (1<=N<=1000) iterations of medal distribution. In iteration i (0 < = i < N), count[i] ( 1 < = count[i] < = 100) medals are given to all officers from from[i] to to[i] ( 1 < = from[i] < = to[i] < = 10^6 )

If we sum up the number of medals received starting from the first officer, who would be the first officer for which the cumulative sum exceeds a given medal count THRESHOLD ( 1 < = THRESHOLD < = 10^9 )?

Input/Output Specifications Input format:

You are given 5 inputs:

input1 = N, the number of iterations

input2 = count, the array of medal counts in each iteration

input3 = from, the array of starting indices in each iteration

input4 = to, the array of ending indices in each iteration

input5 = THRESHOLD, the medal count threshold

Output format:

An integer, representing the number of the first officer such that the cumulative sum of medals starting from the first officer upto this officer exceeds THRESHOLD. The output should be -1 if such an officer does not exist.

- 1of 1 vote
We need to make a string of size n. Each character of the string is either ‘R’, ‘B’ or ‘G’. In the final string there needs to be at least r number of ‘R’, at least b number of ‘B’ and at least g number of ‘G’ (such that r + g + b <= n). We need to find number of such strings possible.

For example,

n = 4, r = 1, b = 1, g = 1.

Output:

36

- 0of 0 votes
Algorithm to check whether given sequence is arithmetic progression or geometric progression

- 0of 0 votes
Algorithm to check whether given series is arithmetic progression or geometric progression

- -3of 3 votes
I have two number A = 100 and B = 145;

I want to find all number that have digit of number is increase

Thanks

- 0of 0 votes
Given an array of strings as input, return an array of all strings that have repeated chars that appear together. For e.g. in "hello" l and in "summer" s is a repeated char that appears together. However in "robot" o is not a repeated char as it does not appear together.

repeatChars({"hello","robot","summer","elephant"}) = {"hello","summer"}

- -4of 6 votes
You have an array of integers(size N), such that each integer is present an odd number of time, except 3 of them(which are present even number of times). Find the three numbers.

Only XOR based solution was permitted.

Time Complexity: O(N)

Space Complexity: O(1)

Sample Input:

{1,6,4,1,4,5,8,8,4,6,8,8,9,7,9,5,9}

Sample Output:

1 6 8

- 0of 0 votes
Given a number, you have to replace digits of the number with a given character 'a' and print all such possible strings(replacing only 1 digit or more at a time). The constraint is that no 2 consecutive digits should be replaced.

- -1of 1 vote
what will output of this

`#include <iostream> #include<algorithm> using namespace std; class Sum { private: int s; public: Sum(int x):s(x) { } int getSum() { return s; } void operator()(int p) { s = s + p; } }; int main() { cout << "Hello World" << endl; int arr[] = {1,2,3,4,5,6,7,8}; Sum obj = for_each(arr,arr+7,Sum(1000)); cout<<obj.getSum()<<endl; return 0; }`

- 0of 0 votes
Write a method that takes a given string and replaces all occurrences of one string with another string, returning the number of replaces made. For instance given the string “Microsoft” if you were to replace all occurrences of “ic” with “MSFT” the result would be “MMSFTrosoft” with a return value of 1. As part of a final solution please provide unit tests done as well as any test cases ran. Please note that you may not use String.Replace or string::replace depending upon the language you use; you must write this functionality yourself.

- 0of 0 votes
Implement a class that does string manipulation by overloading the following operators: <<, >>, = and ==. For example consider the following code:

StrShift example;

example = “Microsoft”;

printf(“\”example << 2\” results in %s\n“, example << 2);

In the above code the output would be “ftMicroso” which shows the last two characters of the string “Microsoft” rotated to the left of the string. Please note that state is maintained so two calls of example << 1 would give the same end result as calling example << 2 once. Consideration will be given to correctness, design, code readability as well as any unit testing. As part of a final solution please submit test cases you used to verify correctness in addition to any unit tests done.

- 0of 0 votes
Write a class that represents a minimal heap. The heap class should at a minimum support the following methods:

- AllocTinyHeap() which should initialize the heap with a given amount of bytes

- DeleteTinyHeap() which frees all memory associated with the heap

- TinyAlloc() which allocates a given number of bytes on the heap if there is room

- TinyFree() which frees a specific location on the heap

You may define whatever parameters are necessary for the above methods as well as write any additional methods. Overall consideration will be given to correctness, design, code readability as well as any unit testing done. As part of a final solution please submit test cases you used to verify correctness in addition to any unit tests done.

- 0of 0 votes
I was asked to design a trading system, where there will be no of buyers and sellers will transact. The system need to have low latency, the buyers will quote no of shares, company name, price they want to buy, the sellers will quote the price they want to sell for given company, and no of shares. The system has to match the buyers and sellers and transact. This is more of design question.

I was thinking in terms of a hashmap kind a structure where the key will hash to the given company, and then there will be buckets for no of shares for buyers, with different buckets for prices, the idea is to look up in memory sellers, if a match is found then make the transaction. If the in memory data exceeds a limit implement a caching, and push the older data to the persistent store. The guy was'nt convinced this was a good design. Can someone suggest how is real time trading systems implemented, do they go for low latency queues.