c Interview Questions | Glassdoor

c Interview Questions

270

interview questions shared by candidates

c Interview Questions

Sort: RelevancePopular Date

Find the minimum depth of binary search tree

10 Answers

isn't this? int mindepth(node* root) { if(root==NULL) return 0; return 1 + min(mindepth(root->left),mindepth(root->right)); }

You wouldn't get an on-site interview with this answer. Your code is not optimal, although it looks short. Here is the trick: you don't have to traverse entire tree to find out the minimum. think about this example. L side of the root node has only one item, so the deep is 1, R side of the root has one million items. Why do you have to traverse through all one million nodes, if you can get the min from the L side right away?

It can be solved using the previous recursive code and also can be solved using Breadth First Traversal, by starting the traversal from the root of the tree, and when reach a leaf then this is the min depth return the number of steps from the root to this leaf

Convert a binary search tree to a sorted, circular, doubly-linked list, in place (using the tree nodes as the new list nodes).

8 Answers

Given two integer arrays. Find the Largest Common sub array. For example, arr1 = {1,2,3,2,3,2} arr2={2,2,3,3,4,5}, the largest common sub array is {2,2,3,3}

8 Answers

Define binary search tree. Develop a procedure to verify a binary search tree.

6 Answers

Asked to implement a function that takes an integer and returns whether or not the number had an odd or even number of 1 bits.

6 Answers

Assume that you are given the head and tail pointers of a doubly linked list where each node can also have a single child pointer to another similar doubly linked list. There are no cycles in this structure outside of the traditional double links. Write a procedure in C++ that flattens this structure into a single list.

7 Answers

identify the number of 1s in an integer is odd or even

7 Answers

Given a page size and a number, align the number with the nearest page. (Note: This was a phone interview question. The interviewer and I used an online document to share ideas about this problem.

5 Answers

How to remove a node from a singly-linked list when only given the pointer to the node

6 Answers

Find k largest/smallest number in a series of numbers. What data-structures will you use? Code it on white board.

5 Answers
110 of 270 Interview Questions