## Developer Program Engineer Interview Questions

- 0of 0 votes
Given a matrix of ‘O’ and ‘X’, find the largest sub rectangle surrounded by ‘X’

Example :

XXXXX

X0X0X

XXXXX

XXXXX

Output : largest rectangle size is 4 x 5

- 0of 0 votes
In your large programme, thereis memory leak, how will ypu find out where(Linux)

- 0of 0 votes
given 2 processes. Each having 4 threads. ! thread is having performance issue. How will you find out that thread (Linux)

- 0of 0 votes
given 2 processes , how to use a semaphore which is locked on 1 process and released in other(Linux)

- 0of 0 votes
There are IPCs in Linux- Pipe, Fifo, Shared Memory, Message Queue, Socket. Which cases which IPC to choose(Linux)

- 1of 1 vote
There are 2 threads . How you will synchronize in linux so that 1 thread prints even numbers and other thread prints odd numbers

hint: condition variable

- 0of 0 votes
Why to use singleton class? What is the advantage you get by restricting single object of a class.

eg.If you are using a logger class, if there are many objects of the class and you want to print that sequentially, you can achieve this with mutex. Why use singleton?

write code for thread safe singleton.

- 0of 0 votes
write commands for -

1>list processes

2>remove 2lines from file

3>there are multiple hirarachical direcories. Change the file extension all .c files to .cpp

4>chang time stamp of a file

5> run a script at a particular time

- 1of 1 vote
Write 2 functions to serialize and deserialize an array of strings. strings can contain any unicode character. Do not worry about string overflow.

- 0of 0 votes
This was a javascript interview.

There are two arrays:

var arr1 = [2,"undefined",7,"undefined", 10,"undefined","undefiend"];

var arr2 = [5,8,12,14];

They need to be merged such that arr1=[2,5,7,8,10,12,14]

This needs to be done in place and in constant time.

- 0of 0 votes
I was asked this question in an algorithm interview. Since my coding language was javascript I was asked to implement a hashmap n white board with collision detection.

I guess they were looking for a hashing algorithm that will create a linked list in case of a collision and also an equals method

- 0of 0 votes
Using Javascript write code to detect and remove a loop from a cylic linked list

- -2of 2 votes
#include<stdio.h>

#include<string.h>

char* minimumCost(char* input1[],int input2)

{

- -3of 3 votes
#include<stdio.h>

#include<string.h>

char* minimumCost(char* input1[],int input2)

{

- -2of 2 votes
#include<stdio.h>

#include<string.h>

char* minimumCost(char* input1[],int input2)

{

- 2of 2 votes
Two strings s1 and s2 are given. You have make a new string s3 such that it has both s1 and s2 as one of its subsequences and length of s3 is minimum.

input:

apple pear

output:

applear

7

- 0of 0 votes
write 3 threads..2 producer threads and 1 consumer thread..

Two players playing a game. they can type 1 or 2. if player1 and player2 both type 2, both get 4 points each..if both

type 1 they get 2 point each..if player1 types 1 and player2 types 2, then player2 gets 3 and player1 gets 1..if player1

types 2 and player1 types 1, than player2 gets 1 and player1 gets 3..

There will be 10 rounds.And their scores would get accumulated. If at the end of any round, any player is trailing by more

than 6 points the trailing player would not get a chance to type any input in the next round. However, subsequent rounds onwards

all players would be given chance to type inputs should he/she does not trail by more than 6 points.

Thread1 & 2 : They are producer threads..they will ask the user to type something..But whenever a miss occurs for a player

(because he was trailing by more than 6 points), the respective thread will not ask the user to type anything.Instead it

will assume that trailing player has typed 2. The threads will write the inputs into a buffer..

Thread3 : the consumer thread will read from the buffer and display the values entered at each round and scores accumulated

at the end of each round..The scoring will happen in Thread3 only..

You can not use sleep or delay statement anywhere in the code

- 0of 0 votes
The King's Land Sale - 2

You might have seen shopkeepers offering sale on their trade items to promote their business - like sale on electronic gadgets or sale on clothing and accessories etc. But have you ever come across something like sale of land ?

Yes, the king of Byteland has grown old and wants to sell away his territory as soon as possible. So he announced a sale on his plot. This drew attention of many land lords and everybody hurried to buy land at the cheapest prices. The king had declared that he would accept bids of only rectangular plots and one needs to mention the diagonally opposite corners(a, b) and (c, d) of the land he wishes to buy. They would write these 4 numbers (a, b, c, d) on a piece of paper, seal it in an airtight envelope and give it to the king.

The king received N such envelopes. As the process was hidden there were many envelopes containing plot descriptions that shared some (or even all) common area. The king now wants to know the union of the areas of all plots that have come under the bidding.

Note that the rectangles made by the plots are always aligned to the rectangular axes, their areas is always positive and c >= a and d >= b.

Note that the rectangles made by the plots are always aligned to the rectangular axes, their areas is always positive and c >= a and d >= b.

Constraints

1 ≤ T ≤ 20

1 ≤ N ≤ 20

-10000 ≤ a, b, c, d ≤ 10000

Input

The first line of the input contains the number of test cases T. The description of T test cases follow. Each test case starts with a line containing an integer N, the number of rectangular plots. Then N lines follow, each with 4 space separated integers, a b c d,(a, b) and (c, d) representing the diagonally opposite corners of the plots.

Output

For each test case print one line, the union of the areas of all the plots.

Explanation

1) The individual areas of both plots are 4 each. But they share a common area of 1 between them (between (1, 1) and (2, 2)). Therefore the total area is 4 + 4 - 1 = 7

2)Both the plots of no area in common. So we simply add their individual areas (6 + 9 = 15).

- 0of 0 votes
write a java program for below question.

suppose john has been give task of monitoring a radio which is jumping to random frequency on a hourly basis. joha has to find the maximum positive frequency difference of that radio in at most two selections.

examples :

1. suppose radio is tuned to 91MHz to 98MHz and then to 95MHZ.

In first tunning Df= f2-f1 =98-91=7 (positive frequency diff)

In second tunning Df= f2-f1 =95-98=-3 (negative frequency diff)

2. Input1: {2,30,15,10,8,25,80}

input2: 7

output:100

To have maximum frequency diff with at most two selections. john has to select 2MHZ and he has to drop it to 30MHZ and second selection, he has to pick 8MHz to 80Mhz.

so output is 28+72=100

Java method signature :

public static int maximumPositiveFrequency(int[] input1,int input2)

{

}

- 0of 0 votes
suppose john has been give task of monitoring a radio which is jumping to random frequency on a hourly basis. joha has to find the maximum positive frequency difference of that radio in at most two selections.

examples :

1. suppose radio is tuned to 91MHz to 98MHz and then to 95MHZ.

In first tunning Df= f2-f1 =98-91=7 (positive frequency diff)

In second tunning Df= f2-f1 =95-98=-3 (negative frequency diff)

2. Input1: {,30,15,10,8,25,80}

input2: 7

output:100

To have maximum frequency diff with at most two selections. john has to select 2MHZ and he has to drop it to 30MHZ and second selection, he has to pick 8MHz to 80Mhz.

so output is 28+72=100

- 0of 0 votes
Passing objects and correct the program:---

class OdemoA

{

int i,j;

void function1(int i)

{

System.out.println(i);

System.out.println("Inside function()");

}

void function2(Area a1)

{

if(a1!=null)

{

a1.i=203;

a1.j=115;

}

System.out.println(a1);

System.out.println("end of function2()");

}

public static void main(String args[])

{

OdemoA d1 = new OdemoA();

Area a2 = new Area();

d1.function2(a2);

System.out.println(a2.i);

System.out.println("end main");

}

}

- -1of 1 vote
I realized this algorithm for generating combinations. It works in the following way, if we have the input:

[A, B, C]

The combinations will be

[A], [B], [C]. [A, B], [A, C], [B, C], [A, B, C].

While if we have in input:

[1,1,2,3]

The combinations will be:

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

However, this algorithm has a running time of good only when the input is a list of size 4, if the list is of size 5 or more (when there are 5 different elements ( for example 80 A, 150 B , 80 C , 30 D , 20 E)) the program stops and gives me java.lang.OutOfMemory (I increased the memory for in java). One problem could be the fact that I have used LinkedList, but I'm not sure.

Is there a better solution?

private List<Elemento> combinazioneMassima = new ArrayList<>();

private Log logger = LogFactory.getLog(Combinazioni3.class);

public Combinazioni3(List<Elemento> generaCombinazioneMassima) {

this.combinazioneMassima = generaCombinazioneMassima;

}

public void combine() {

this.findAllCombinations(combinazioneMassima);

}

private static class Node{

int lastIndex = 0;

List<Elemento> currentList;

public Node(int lastIndex, List<Elemento> list) {

this.lastIndex = lastIndex;

this.currentList = list;

}

public Node(Node n) {

this.lastIndex = n.lastIndex;

this.currentList = new ArrayList<Elemento>(n.currentList);

}

}

public void findAllCombinations(List<Elemento> combinazioni) {

Date dataInizio = new Date();

List<List<Elemento>> resultList = new ArrayList<List<Elemento>>();

LinkedList<Node> queue = new LinkedList<Node>();

int n = combinazioni.size();

ArrayList<Elemento> temp = new ArrayList<Elemento>();

temp.add(combinazioni.get(0));

queue.add(new Node(0, temp));

// add all different integers to the queue once.

for(int i=1;i<n;++i) {

if(combinazioni.get(i-1) == combinazioni.get(i)) continue;

temp = new ArrayList<Elemento>();

temp.add(combinazioni.get(i));

queue.add(new Node(i, temp));

}

// do bfs until we have no elements

while(!queue.isEmpty()) {

Node node = queue.remove();

if(node.lastIndex+1 < n) {

Node newNode = new Node(node);

newNode.lastIndex = node.lastIndex+1;

newNode.currentList.add(combinazioni.get(node.lastIndex+1));

queue.add(newNode);

}

for(int i=node.lastIndex+2;i<n;++i) {

if(combinazioni.get(i-1) == combinazioni.get(i)) continue;

// create a copy and add extra integer

Node newNode = new Node(node);

newNode.lastIndex = i;

newNode.currentList.add(combinazioni.get(i));

queue.add(newNode);

}

GestoreRegole gestoreRegole = new GestoreRegole();

gestoreRegole.esegui(node.currentList);

}

}

- -1of 1 vote
I realized this algorithm for generating combinations. It works in the following way, if we have the input:

[A, B, C]

The combinations will be

[A], [B], [C]. [A, B], [A, C], [B, C], [A, B, C].

While if we have in input:

[1,1,2,3]

The combinations will be:

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

However, this algorithm has a running time of good only when the input is a list of size 4, if the list is of size 5 or more (when there are 5 different elements ( for example 80 A, 150 B , 80 C , 30 D , 20 E)) the program stops and gives me java.lang.OutOfMemory (I increased the memory for in java). One problem could be the fact that I have used LinkedList, but I'm not sure.

- 0of 0 votes
This is a sample program to find the maximum contiguous sum in an array.

`int maxSubArraySum(int a[], int size) { int max_so_far = a[0], i; int curr_max = a[0]; for (i = 1; i < size; i++) { curr_max = max(a[i], curr_max+a[i]); max_so_far = max(max_so_far, curr_max); } return max_so_far; }`

Now modify this to print the start and end indices.

- 1of 1 vote
Given two numbers a=12, b =36 write a method that return an integer value c=3612, with out using arithmetic and string operations.

- 0of 0 votes
write a java program display the sub string from a string without using string function

- 0of 0 votes
given an array with elements check if just by exchanging two elements of the array we get a sorted array.

- 0of 4 votes
you have a stream of bytes (1010101101011110100010......)to send over the net. but if you compress it. you will be charged less for less data usage. please try to compress it in a way that you can decompress at other end ahd you dont loss data

- -1of 1 vote
consider a battlefield to be made up of square cells of unit dimensions. a soldier on the battlefield can move from a cell to all(8) of it's neighboring cells. soldier has a gun with with him which he can shoot the targets up to any distance along any of the 8 possible directions (north,east,west,south,north-east,north- west,south- east,south- west). also some sell are bulletproof which prevents bullets to pass but soldier can walk over them as if it were a normal cell.he can destroy the target from a bulletproof cell but not from a cell behind it.

position of a target/ soldier can be given by the cell, they are on.given the position of the target, starting position of a target and position of all the bullet proof cells. you have to tell the position of closest shooting point i.e the cell from which, the soldier can shoot the target and is closest to the starting position of the soldier. if there are more than such cells, output all of them.

Input/output specifications :

Input specifications :

I) size of the battlefield { integer pair (N,M) : battlefield will be of N*M size )

II) staring position of the soldier {integer pair (i,j)}

III) position of the target {integer pair (x,y) : position of the cell on which target is mounted}

IV) position of the all bullet proof cells { list of integer pair a#b : each element in the list is a position of bullet proof cells }

output specifications :

sequential list of integer pair i#j (cell) that are closest shoot points and must fallow row wise traversal.

Note: if the output list contains four shoot points : (2,1), (1,2), (3,2), (2,4) on a 4x4 battle field.

then the correct output will be {1#2,2#1,2#4,3#2} not {1#2,2#1,3#2,2#4}

Examples:

Input : {2,2} {2,1} {2,2} {1#1,1#2}

output : 2#1

below is the method signature in java:

public static String[] nearest_shoot_point(int[] input1,int[] input2,int[] input3String[] input4){

}

- 0of 0 votes
Given a 2 dimensional point of a rectangle and its area, find permutations of all the other 3 points of the rectangle in 2-D space.

Ex:- Given X=(0,0) and A=1

(0,1),(1,0),(1,1)

(0,-1),(-1,0),(-1,-1)