Interview questions

Software Developer interview questions – page 16

945 questions. Tap “Show answer” to check yourself.

  1. Find the intersection point of two linked list

  2. You are given file pointer and integer n, write c code for printing last "n" lines in that file

  3. What is deadlock? Conditions for that? What are the methods to prevent it? Write code to prevent the deadlock for OS, considering that there are two processes P0 and P1 in OS and they are requesting resources dynamically

  4. WAP to check if the binary tree is height-balanced and write testcases

  5. A process doesn't require additional processors to carry out 40% of > it's execution since 40% is mostly sequential. Determine how many > additional processors are required to execute the process in 150s if > the process takes 300s to execute on a single processor. > > a)5 > b)8 > c)6 > d)7

  6. Time complexity of a function f(m) is O(m). If the array[i...n] > contains either 1 or 0 in each of it's locations, determine the worst > case time complexity of the following piece of code written in C-like > language. > > counter=0; > for(i=0; i=n; i++){ > if(a[i]==1) > counter++; > else{ > f(counter); > counter=0; > > } > } > > * i=n was given in the condition of for loop > > a) O(n^2) > b) O(n^2 logn) > c) O(nlogn) > d) O(n)

  7. Increasing the RAM increases the efficiency of the CPU. The reason > is > a) Virtual memory increases > b) Number of page Page faults decreases > c) Page segmentation decreases > d) Increasing the amount of memory increases the speed of fetching > data

  8. Merge two sorted linked list and write testcases

  9. Which of the following numbers cannot be represented accurately in > binary? > a) 0.1 b) 6.5 c) 1/16 d)1.32 e) 0.590625 (not sure abt option e) > > 1. a only > 2. a and b > 3. a, b and d > 4. a, b and e > (not sure about option 3)

  10. Given a string s[1...n] and a reverse function reverse(s, i, k) > which reverses the character sequence from i to k (inclusive of both) > in string s, determine what the following operations result in. > 1 > reverse(s, 1, k) > reverse(s, k+1, n) > reverse(s, 1, n) > > a) Reverses the string > b) Rotates the String left k positions > c) Rotates the String right k positions > d) None of the above

  11. If len is the length of the string and num is the number of > characters printed on the screen > Give the relation between num and len. > > void abc (char *s){ > if(s[0]=='') > return; > > abc(s+1); > abc(s+1); > printf("%c ", s[0]); > > } > > a) num=2^len > b )num=2^len-1 > c) num=2*len-1 > d) None of the above

  12. Insert an element into a sorted circular linked list. (Consider all cases, inserting in the beginning, end and middle)

  13. Given a node in a binary tree, find the leftmost node in the same level

  14. WAP to print a matrix spirally. I told him I knew the problem so he skipped it

  15. Search for an element in a rotated sorted array (of course in sublinear time!)

  16. Nice DP problem. Given an amount and an array containing possible coin denominations, determine the smallest no of coins in which the amount may be formed. Assume you have infinite units of each denomination

  17. Given a linked list, swap its nodes pairwise. A good test of pointer manipulation with many edge

  18. Given an array, bring all its distinct elements to the top in any order, the rest of the array is not

  19. Given a linked list, invert every two nodes in the list.Eg. Given a ­> b ­> c ­> d, result should be b ­> a ­> d ­> c

  20. A file or a directory can be represented as a node. The node has properties like ID no, parent ID no, name, no of children( 0 for a file). The entire file structure is represented as a linked list of the nodes. Only thing known to us is that the parent directory will always come before the children in the LL. It need not come immediately before.We have to implement a GUI such that when I press on the + button next to the root directory, I see its children folders and files. The child directories have a + button next to them and can be expanded similarly.Write a pseudocode to implement this in minimum time and space.I suggested the use of a tree, wrote a code to convert it to a tree

  21. "Compress a text string in place". Having seen the famous string expansion in place problem many times, I promptly said run length encoding (i.e. compress aaaaaabbbbbccc to a6b5c3 for example). He asked me to code it and write a few test cases for it. The most important test case in my opinion is the following:

  22. Given a binary search tree and a no. N in the tree, print the leftmost node at the same level as N

  23. There is a roller which can have two types of wood blocks, 49 cm and 50 cm. Given two sensors 50 cm apart which call a function ring( ) whenever the sensor changes state, write the function ring( ) to calculate the number of blocks of boh types

  24. Given a room with points pertaining to different groups, check whether the connection is planar or non­planar i.e. while connecting all the points in the same group, the wires of different groups should not overlap

  25. Find the nth power of a number in shortest computational time

  26. Given a node in a binary tree, find the leftmost node in the same level. I wrote the pseudocode, and testcases

  27. Find the nth largest number in a binary tree

  28. Given 5 points in a plane, prove that there will be atleast two points such that their midpoint is an integer

  29. Two numbers are stored in two linked lists, with one digit in each node. Add the numbers and return the resultant sum in a linked list. eg. if LL1= 2 ­> 3 ­> 5, LL2= 1­>4­>5, result should be LL3= 3­>8­>0

  30. Check the no of repeated occurences of a substring in a string

Companies that ask Software Developer questions