Count set bits in an integer

Write an efficient program to count number of 1s in binary representation of an integer. Examples Input : n = 6 Output : 2 Binary representation of 6 is 110 and has 2 set bits Input : n = 13 Output : 3 Binary representation of 11 is 1101 and has 3 set bits 1.… Read More »

The Great Tree-List Recursion Problem.

Asked by Varun Bhatia. Question: Write a recursive function treeToList(Node root) that takes an ordered binary tree and rearranges the internal pointers to make a circular doubly linked list out of the tree nodes.

Function to check if a singly linked list is palindrome

Given a singly linked list of characters, write a function that returns true if the given list is palindrome, else false. METHOD 1 (Use a Stack) A simple solution is to use a stack of list nodes. This mainly involves three steps. 1) Traverse the given list from head to tail and push every visited… Read More »