a[5] = [10, 12, 3, 4, 15]
int* const exp1 = &a;
int const* exp2 = &a;
for (int i = 0; i < 5; i++)
{
print("Value %d", *exp1++);
print("Value %d", *exp2++);
}
What will be the output?
int main()
{
while (1)
{
char* m = malloc(100);
if (m == NULL)
{
print("Unable to allocate memory");
}
}
return 0;
}
What will this code print?
When will it stop?
Which memory is allocated (Virtual or Physical)?
Memory hierarchy of OS?
How malloc works
Round 1 Q 2
string m = "aabababbaababab";
string n = "aab";
Find the count of all substrings of n which are in m.
e.g., aab, aba, baa = 2 + 4 + 1 = 7
Given two unsigned 32-bit integers, write a function to find their average without using any extra space and return a 32-bit unsigned int.
Define a stack with normal operations such as push, pop, top, and a new operation max which always returns the maximum element in the stack.
Given a 2D array, assume that we are reading it in row-major order and column-major order. Which would be better/faster?
Define memory hierarchy in OS.
Given a sorted array A = {1, 2, 3, 4, 5}, the array can be rotated by k elements.
e.g., K=2: A = {4, 5, 1, 2, 3}
K=1: A = {5, 1, 2, 3, 4}
K=4: A = {2, 3, 4, 5, 1}
Give an O(log n) solution to find element X in the array (The element will always be present in the array).
Modified level order traversal: print elements in a zig-zag order.
Implement Stack using an array.
Round 4 Q 2
Lowest Common Ancestor in a Binary Search Tree.
Round 4 Q 3
Given an array A = {12, 11, 13, 9, 10, 55, 32, 54}.
Find the largest subarray which contains all consecutive elements.
eg: {12, 11, 13, 9, 10}
Round 5 Q 1
Discussion on Mutex and Semaphore.
Round 5 Q 2
Questions on my previous work experience and debugging methods.
Round 5 Q 3
Discussion on Locks and Deadlocks.
Round 5 Q 4
Given a sequence S = 0102030405...
Given 3 threads as follows:
- Thread 1 zero(): Will print zero.
- Thread 2 even(): Will print even numbers 2, 4, 6, 8.
- Thread 3 odd(): Will print odd numbers 1, 3, 5, 7.
Design a synchronization mechanism so that we get the above sequence.
Round 5 Q 5
Design a Stack class apart from push, pop, top, and isEmpty. One more operation is allowed: findMin, which returns the minimum element at any given time.
Round 5 Q 6