## Software Engineer / Developer Interview Questions

- 0of 0 votes
What is the following program trying to do?

`#define SIZE (1<<31) // 2 Gb int main() { char *p=malloc(SIZE); memset(p, 0, SIZE); }`

a. Trying to crash OS by allocating lot of memory

b. Trying to calculate amount of system memory

c. Trying to allocate virtual memory and makesure memory is in physical memory

d. It is a useless program because the system will not satisfy memory request

- 0of 0 votes
Implement printf() library function using system-calls assuming a single argument which is a string

eg: printf("Hello world\n");`void printf(char *str)`

- 0of 0 votes
Implement sleep() in kernel mode using C-pseudo code

`void sleep(int seconds) {}`

- 0of 0 votes
Implement a trivial spinlock and spinunlock functions using C-pseudo code eg: spinlock(&lock);

`void spinlock(int *lock){}`

`void spinunlock(int *lock){}`

- 0of 0 votes
Which one of the following applies to multi-core system?

a. Multiple users can use the system at the same time

b. The kernel can run in SMP mode

c. Multiple tasks can execute in parallel without the need for scheduling

d. semaphores and mutexes should be replaced with spinlock

- 0of 0 votes
The user space program running in foreground mode is hung. How will you debug the hang without exiting or killing the program?

- 0of 0 votes
What are the differences between interrupt and exception?

- 0of 0 votes
Explain how page fault and segmentation fault is handled/resolved

- 1of 1 vote
Given a multidimensional array like below:

`0 1 0 0 3 0 3 3 0 0 0 0 0 0 2 0 0 1 0 2 0 0 0 0 0`

"objects" are considered groups of numbers that touch along top, left, right, or bottom edges.

Find the number of objects.

For example given the above array, your code should detect 4 unique "Objects". {1,3,3}, {3}, {1}, and {2, 2}.

- 0of 0 votes
To design classes and methods for casino cards games, what would you consider when doing it?

- 1of 1 vote
Write a method that takes a binary tree and return whether the tree is sorted.

- 0of 0 votes
In a programming language,we have a conditional statement like "a ? b : c",(you can assume all the expressions here could be represented by single character).The task is to generate a syntax tree like this.

a

b c

Here are more examples of the input and output,

a ? (b ? c : d) : e

a

b e

c d

a ? b : (c ? d :e)

a

b c

d e

- 0of 0 votes
How to split a string using spaces with a given condition, the string inside quotes (") will not be split.

- -3of 3 votes
Write a method to return first five 10 digit prime numbers

- 1of 1 vote
Write a method to return first five 10 digit prime numbers.

- 1of 1 vote
Given an array of integers. We have to find the max element of the array, which is at multiple places in the array and return any one of the indices randomly.

- 0of 0 votes
Which is faster?

while(1) {}

or

while(2) {}

I said both have same speed as the expression inside while should finally evaluate to true or false. in this case both evaluates to true and there are no extra instructions inside the while so both have same speed of execution. Interviewer said while (1) is faster than while (2).

I do not agree . do you ?

By the way interviewer was a senior manager (i,e. does not code on day-to-day basis)

- 0of 0 votes
Come up with an algorithm for mapping the following scenario:

You have a source LED which has the following possible output combinations.

1. OFF

2. ON- Having RED SOLID color

3. ON- Having a GREEN BLINKING (one flash every second)-> This will result in LED turning OFF->ON and then OFF->ON

every one second.

When the source LED changes it's state (ON->OFF, OFF->ON, or changes COLOR ), you will get an interrupt.

As part of the interrupt handling, you will have to drive a single LED which has these possible values:

OFF-> when the source LED is OFF

RED-> when the source LED is RED SOLID

GREEN->when the source LED is green flashing.

Give the algorithm of only mapping these scenario and not the interrupt handling.

- 0of 0 votes
Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-pairs of parentheses.

EXAMPLE:

input: 3 (e.g., 3 pairs of parentheses)

output: ()()(), ()(()), (())(), ((()))

This question is from "Cracking the coding interview" (Fourth Edition) and I think that I found mistake in the answer.

- 10of 10 votes
Output top N positive integer in string comparison order. For example, let's say N=1000, then you need to output in string comparison order as below:

1, 10, 100, 1000, 101, 102, ... 109, 11, 110, ...

- 2of 2 votes
Find the longest sequence of prefix shared by all the words in a string.

"abcdef abcdxxx abcdabcdef abcyy" => "abc"

- 3of 5 votes
Given a function

getRandomTripplet()

which returns a random triplet of letters from a string. You don't know the string using calls to this function you have to correctly guess the string. the length of the string is also given.

Lets say the string is helloworld the function getRandomTriplet will return things like

hlo

hew

wld

owo

the function maintains the relative order of the letters. so it will never return

ohl since h is before o in the string.

owe since w is after e

The string is not known you are only given length of the string.

- 0of 0 votes
Give a function

getRandomTripplet()

which returns a random triplet of letters from a string. You don't know the string using calls to this function you have to correctly guess the string. the length of the string is also given.

Lets say the string is helloworld the function getRandomTriplet will return things like

hlo

hew

wld

owo

the function maintains the relative order of the letters. so it will never return

ohl since h is before o in the string.

owe since w is after e

The string is not known you are only given length of the string.

- 0of 0 votes
given a binary tree, assign a new next pointer to each node, such that next pointer points to any node which is right side of the node(ie it may point to its sibling right node , or a left node of next subtree).

if no node on right or if the node itself if right most, the next points to null`6`

`/ \`

`7-------->2`

`/ \ / \`

`1 - ->5-->4 ->13`

- 4of 4 votes
Given a NxN matrix which contains all distinct 1 to n^2 numbers, write code to print sequence of increasing adjacent sequential numbers.

ex:

1 5 9

2 3 8

4 6 7

should print

6 7 8 9

- 0of 0 votes
Given is a matrix arr[n][n], find a submatrix sub[m][m] such summation of all the elements in submatrix is maximum.

Given condition,

1. m <= n

2. m >= 2

3. consider positive, negavive and zero integers in arr[n][n]

4. User provide n.

- 0of 0 votes
float range is only 4 byte but if apply the more than 4 byte also execute why?

- 0of 0 votes
all the problem are easy solve using printf &scanf

but my question is what is the necessity of using other input&output function

- 0of 0 votes
if apply same input for float and double .some time the vale is display &some time display not same .why this kind of output display..how to rectify the problem

- -1of 1 vote
Power set P(S) of a set S is the set of all subsets of S. For example S = {a, b, c} then P(s) = {{}, {a}, {b}, {c}, {a,b}, {a, c}, {b, c}, {a, b, c}}.

If S has n elements in it then P(s) will have 2^n elements`public List<List<int>> ComputePowerSet(int[] nums) { List<List<int>> powerSet = new List<List<int>>(); if (nums == null) return powerSet; bool[] bits = new bool[nums.Length]; bool overFlowBit = false; while (!overFlowBit) { List<int> lst = new List<int>(); for (int i = 0; i < nums.Length; i++) { if (bits[i]) lst.Add(nums[i]); } //function PlusOne returns false if the end is reached i.e. 2^n if (!PlusOne(bits)) overFlowBit = true; powerSet.Add(lst); } return powerSet; } public bool PlusOne(bool[] bits) { bool carry = true; //add i i.e. true to the bits int i = bits.Length-1; while (i >= 0 && carry) { bool b = bits[i]; bits[i] = b ^ carry; carry = b & carry; i--; } //if carry is true implies reached the end i.e. 1111 + 1 = 0000, carry = 1 return !carry; }`