Posts

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

Void pointers: Difference between c and c++

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?  

Number is palindrome or not

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.

Sum of four elements equals X

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.

All possible IP Address combinations

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)

Difference in program size

What is the difference in terms of program size in case of these two types of declarations int a[100]; or, int a[100]={10};

Exchange gold coins

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.