Created
March 10, 2016 16:43
-
-
Save ryanorsinger/3bfa2f52812515c6a669 to your computer and use it in GitHub Desktop.
Coding Challenge Programming Problems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Coding Challenges. Complete these in the language of your choice. | |
1. Count the number of Fibonacci numbers in given range. First few Fibonacci | |
numbers | |
are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 141, .. | |
Range is 10 to 100 | |
http://www.geeksforgeeks.org/count-fibonacci-numbers-given-range-log-time/ | |
2. Count factorial numbers in a given range | |
A number F is a factorial number if there exists some integer I >= 0 such that F = I! | |
(that is, F is factorial of I). Examples of factorial numbers are 1, 2, 6, 24, 120, …. | |
Write a program that takes as input two long integers ‘low’ and ‘high’ where | |
0 < low < high and finds count of factorial numbers in the closed interval [low, high]. | |
Input: low = 2, high = 720 | |
http://www.geeksforgeeks.org/count-factorial-numbers-in-a-given-range/ | |
3. Find smallest values of x and y such that ax – by = 0 | |
Given two values ‘a’ and ‘b’ that represent coefficients in “ax – by = 0″, find the | |
smallest values of x and y that satisfy the equation. It may also be assumed that | |
x > 0, y > 0, a > 0 and b > 0. | |
Input: a = 25, b = 35 | |
http://www.geeksforgeeks.org/find-smallest-values-of-x-and-y-such-that-ax-by-0/ | |
4. Find the smallest twins in given range | |
Given a range [low..high], print the smallest twin numbers in given range (low and high | |
inclusive). Two numbers are twins if they are primes and their difference is 2. | |
Example: | |
Input: low = 10, high = 100 | |
Output: Smallest twins in given range: (11, 13) | |
Both 11 and 13 are prime numbers and difference | |
between them is two, therefore twins. And these | |
are the smallest twins in [10..100] | |
Input: low = 50, high = 100 | |
http://www.geeksforgeeks.org/find-the-smallest-twin-numbers-in-given-range/ | |
5. Find four elements a, b, c and d in an array such that a+b = c+d | |
Given an array of distinct integers, find if there are two pairs (a, b) and (c, d) such that | |
a+b = c+d, and a, b, c and d are distinct elements. If there are multiple answers, then | |
print any of them. | |
Input: {3, 4, 7, 1, 2, 9, 8} | |
http://www.geeksforgeeks.org/find-four-elements-a-b-c-and-d-in-an-array-such-that-ab-cd/ | |
1. Count numbers from 1 to n that have 4 as a digit. Given a number n, find count of all numbers from 1 to n that have 4 as a digit. | |
Examples | |
Input: n = 5 | |
Output: 1 | |
Output 4 has only '4' as a digit | |
Input: n = 50 | |
Output: 14 | |
Problem: Determine the ouput for input of n = 328 | |
2. Given a number n, check if n is a Fibonacci number | |
Problem: Check which of the following numbers are Fibonacci | |
89 | |
233 | |
375 | |
601 | |
1597 | |
4183 | |
3. Check if a given number is "Fancy". | |
a fancy number is one which when rotated 180 degrees is the same. Given a number, find whether it is fancy or not. 180 degree rotations of 6, 9, 1, 0, and 8 are 9, 6, 1, 0, 8 respectively. | |
Example: | |
Input n = 96 | |
Output true | |
Input n = 996 | |
Output false | |
Problem: Check which of the following numbers are fancy: | |
6001009 | |
68089 | |
484 | |
4. Count trailing zeroes in factorial of a number. Given an integer n, write a function that returns the 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 2.43290200817664E18 has 4 trailing zeroes | |
Problem: How many trailing zeroes in factorial for input n = 100? | |
5. Find next greater number with same set of digits | |
Given a number n, find the smallest number that has same set of digits as n and is greater than n. If x is the greatest possible number with its set of digits, then print "not possible". | |
Examples: | |
Input n = "218765" | |
Output "251678" | |
Input n = "1234" | |
Output n = "1234" | |
Input "4321" | |
Output "Not Possible" | |
Problem: find next greater number with same set of digits for n = "534976" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment