Determine whether a number is palindrome or not without using extra space. Don't forget to mention whether your Algo will work for negative numbers or not.
Given an array of integers, find all combination of four elements in the array whose sum is equal to a given value X. For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and X = 23, then your function should print “3 5 7 8″ (3 + 5 + 7 + 8 = 23). Note: Numbers should not be overlapping. eg(3,5,7,4) will generate 3+5=8 and 5+7=12 , for sum equals 20, 5 is overlapping.
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135" , return ["255.255.11.135", "255.255.111.35"] . (Order does not matter)
In a monetary system each coin has an integer number written on it. A coin ' n ' can be exchanged in a bank into three coins: n/2 , n/3 and n/4 . But these numbers are all rounded down. You can also sell coins for dollars and their exchange rate is 1:1. You have one gold coin. What is the maximum amount of dollars you can get for it? eg: for a coin with value 120 you can get 144 dollars. Suggest an algorithm to solve the problem.
The successive elements of an unsorted array differ by either + 1 or -1. How will u search for an integer k in this array ? eg: 4,5,4,4,5,6,7,8,7 for each element 'n' the next element is always n+1 or n-1.
Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle . A sub-rectangle is any contiguous sub-array of size or greater located within the whole array. As an example, the maximal sub-rectangle of the array: is in the lower-left-hand corner: and has the sum of 15.
Given two unsorted array, check if both will create the same bst. eg: 2, 1, 4, 0 and 2, 1, 0, 4 will both form same BST. 2 / \ 1 4 / 0 but, 2,1,4,0 and 2,0,1,4 will not.
Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. Examples: 1 / \ 2 3 / \ / \ 4 5 6 7 The tree has 5 vertical lines Vertical-Line-1 has only one node 4 => vertical sum is 4 Vertical-Line-2: has only one node 2=> vertical sum is 2 Vertical-Line-3: has three nodes: 1,5,6 => vertical sum is 1+5+6 = 12 Vertical-Line-4: has only one node 3 => vertical sum is 3 Vertical-Line-5: has only one node 7 => vertical sum is 7 So expected output is 4, 2, 12, 3 and 7
You are given a singly link-list such that each node of this list is also a head of another link list of the same type. So, suggest an algorithm to flatten the linked-list in single level link-list. struct node { void *data; /* could be anything */ struct node *next; struct node *down; };
Given a BST and a number 'N' there can be several paths from root of the bst to leaves such that sum of data of all the nodes will make number 'N'. Suggest an efficient algorithm to find out the path of least length.
Given an arbitrary binary tree, convert it to a binary tree that holds Children Sum Property. You can only increment data values in any node. For example, the below tree doesn’t hold the children sum property, convert it to a tree that holds the property. 50 / \ / \ 7 2 / \ /\ / \ / \ 3 5 1 30
Write a function to connect all the adjacent nodes at the same level in a binary tree. Structure of the given Binary Tree node is like following. struct node { int data; struct node* left; struct node* right; struct node* nextRight; } Initially, all the nextRight pointers point to garbage values. Your function should set these pointers to point next right for each node. You can use only constant extra space. Consider this example for your solution: 1 / \ 2 3 / \ / \ 4 5 6 7 / \ / \ 8 9 10 11 nextRight for node with value 9 will be 10 and not NULL.
It is possible, to find integers greater than 1 that satisfy the "perfect cube" equation a^3 = b^3 + c^3 + d^3 (e.g. a quick calculation will show that the equation 12^3 = 6^3 + 8^3 + 10^3 is indeed true). This problem requires that you write a program to find all sets of numbers {a,b,c,d} which satisfy this equation for a <= N.
Let's assume that we have a pair of numbers ( a , b ). We can get a new pair ( a + b , b ) or ( a , a + b ) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k , that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n .
Given a Binary Tree where each node has positive and negative values. Convert this to a tree where each node contains the sum of the left and right sub trees in the original tree. The values of leaf nodes are changed to 0. For example, the following tree 10 / \ -2 6 / \ / \ 8 -4 7 5 should be changed to 20(4-2+12+6) / \ 4(8-4) 12(7+5) / \ / \ 0 0 0 0