Posts

creating linked list from leaf nodes of a tree

Create a singly linked list from the Leaf nodes from a binary tree. Tree may be balanced or not. Linked list should be created using nodes of tree only.(However you can take extra fields in node of tree)

Cisco:swap bits in pair

Given a byte, write code to swap every two bits in pair. Eg: Input: 10 01 11 01 Output: 01 10 11 10

Google interview : Interleaved string

Three strings say A,B,C are given to you. Check weather 3rd string is interleaved from string A and B. Ex: A="abcd" B="xyz" C="axybczd". answer is yes.

maximum and minimum element in an array

You are provided with an array. Find the maximum and minimum numbers in less number of comparisons.

Google interview puzzle

You are given a biased coin. Find unbiased decision out of it?

level wise linked list of nodes of binary tree

Given a binary tree build a linked list of all its nodes such that the nodes of a level appear before the nodes of the next level?

make all elements 0 in an array

Given an array of two elements having value 0 and 1, Make both elements 0, specifications : i) it is guaranted that one element is 0 but we do not know its position. ii) we can’t say about another element it can be 0 or 1. iii) we can only complement the element. iv) no other operation is allowed (and, or, multi, division…. etc.)

Amazon interview question

Given an unsorted array and two numbers, find the minimum distance between them. For example, if the array is {1,2, 10, 2, 3, 5, 2, 1, 5} distance between 2 and 5 is 1.

matrix multiplication

Is there a way to multiply matrices in lesser than o(n^3) time complexity?

remove duplicates from sorted linked list

Write a C program to remove duplicates from a sorted linked list.

implement atoi function

Write your own C program to implement the atoi() function

nth node from end of a linked list

Write a C program to return the nth node from the end of a linked list.

Copy of a linked list

How to create a copy of a linked list? Write a C program to create a copy of a linked list.

Compare two linked list

How to compare two linked lists? Write a C program to compare two linked lists.

middle of linked list

How will you find the middle of the linked list?

reverse a doubly linked list

Write a program to reverse a doubly linked list.

Find two unique elements

Given an array in which all numbers except two are repeated once. (i.e. we have 2n+2 numbers and n numbers are occurring twice and remaining two have occurred once). Find those two numbers in the most efficient way.

Malloc and Free in c

void * ptr ; size_t size = BUFSIZ ; ptr = malloc ( size ) ; /* some further execution happens here... */ /* now the buffer size needs to be doubled */ size *= 2 ; ptr = realloc ( ptr , size ) ; What is potential error in these set of c statements?

sizeof operator in c

How will you implement your own sizeof() operator in c?

print 1 to n

Write a code in C to print 1 to n without using any loop and inbuilt function.