Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
Posts
Void pointers: Difference between c and c++
- Get link
- X
- Other Apps
By
Admin
-
I'm trying to understand the differences between C and C++ with regards to void pointers. the following compiles in C but not C++ : int * p = malloc ( sizeof ( int )); However, here: void foo ( void * vptr ) { } int main () { int * p = ( int *) malloc ( sizeof ( int )); foo ( p ); return 0 ; } Both C++ and C compile it with no complain. Why?
Sum of four elements equals X
- Get link
- X
- Other Apps
By
Admin
-
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.
Exchange gold coins
- Get link
- X
- Other Apps
By
Admin
-
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.
[Adobe]Search for an element in unsorted array
- Get link
- X
- Other Apps
By
Admin
-
Maximum sum 2-d subarray
- Get link
- X
- Other Apps
By
Admin
-
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.
[AMAZON] Vertical sum of nodes
- Get link
- X
- Other Apps
By
Admin
-
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
Find the Least Length Path Which Sums to S
- Get link
- X
- Other Apps
By
Admin
-
Convert a Binary Tree To hold Children Sum Property
- Get link
- X
- Other Apps
By
Admin
-
Connect nodes of a binery tree at same Level
- Get link
- X
- Other Apps
By
Admin
-
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.
perfect cubes
- Get link
- X
- Other Apps
By
Admin
-
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.