首页 > 代码库 > Cipe Coding Summary Part1

Cipe Coding Summary Part1

1. Colorful Number:
A numbercan be broken into different sub-sequence parts. Suppose a number 3245 can bebroken into parts like 3 2 4 5 32 24 45 324 245. And this number is a colorfulnumber, since product of every digit of a sub-sequence are different. That is,3 2 4 5 (3*2)=6 (2*4)=8 (4*5)=20 (3*2*4)= 24 (2*4*5)= 40. But 326 is not acolorful number as it generates 3 2 6 (3*2)=6 (2*6)=12. You have to writea function that tells if the given number is a colorful number or not.

Steps

1. 3245 can be grouped as {(3, 2, 4, 5), (32, 24, 45), (324, 245)}, found we have length-1 arraylist and each length is in non-increasing order.

 


2. Well-ordered String:
You know a password is well-ordered string. Well-ordered string means that the order of the characters is in an alphabetical increasing order. Like “abEm” is a well-ordered number. However, “abmE” is not a well-order number. Given an input# that tells you also how many digits are in the password, print all possible passwords.

Steps

1. recursive solution, return condition if(pos=num.length) return;

2. record last add char as prev, each recursive call, add continue char start at prev+1 so that string will be well-ordered.


3. Desirable Number
A number is called ‘desirable‘ if all the digits are strictly ascending eg: 159 as 1<5<9. You know that your rival has a strictly numeric password that is ‘desirable‘. Your close ally has given you the number of digits (N) in your rival‘s password. WAP that takes in‘N‘ as input and prints out all possible ‘desirable‘ numbers that can be formed with N digits.

Steps

Same as last question just switch char to digit

 

4. Telephone Number
Print all valid phone numbers of length n subject to following constraints:
If a number contains a 4, it should start with 4
No two consecutive digits can be same
Three digits (e.g. 7,2,9) will be entirely disallowed, take as input

Steps

1. recursive solution.  set certain condition continue;


5. SMS
You are given a telephone keyboard
0-0, 1-1, 2-ABC2, 3-DEF3, 4-GHI4, 5-JKL5, 6-MNO6,7-PQRS7, 8-TUV8, 9-WXYZ9, *-space, #-char separater
if you type "2", you will get ‘A‘, that is "2"-‘A‘, "22"-‘B‘ ,"222"-‘C‘, "2222"-‘D‘
However, the digits can repeated many times
"22222"-you get ‘A‘ again
You can use "#" to separate characters, for example.
"2#22", you get "AB"
However, you may also have consecutive different digits without separator:"23"-‘AD‘
If you type "*", it means space.
You a given a sequence of digits, translate it into a text message

Steps

HashMap

 


6. Keypad Permutation
Phone has letters on the number keys. for example, number 2 has ABC on it, number 3 has DEF, 4 number has GHI,... , and number 9 has WXYZ. Write a program that will print out all of the possible combination of those letters depending on the input.

 


7. The stepping number:
A number is called as a stepping number if the adjacent digits are having a difference of 1. For eg. 8,343,545 are stepping numbers. While 890, 098 are not. The difference between a ‘9’ and ‘0’ should not be considered as1. Given start number(s) and an end number (e) your function should list out all the stepping numbers in the range including both the numbers s & e.

Steps

Recursive solution, Separate edge case which lastdigit == 0 || lastdigit == 9.


8. Two Primes
Goldbach‘s conjecture : Every even integer greater than 2 can be expressed as the sum of two primes. Write a function which takes a number as input, verify if is an even number greater than 2 and also print at least one pair of prime numbers.

Steps

new method to check if isPrime.


9. FindingWords
Write a program for a word search. If there is an NxN grid with one letter in each cell. Let the user enter a word and the letters of the word are said to be found in the grid either the letters match vertically, horizontally or diagonally in the grid. If the word is found, print the coordinates of the letters as output.

LeetCode problem


10. Spiral Matrix
Given aNXN matrix, starting from the upper right corner of the matrix start printingvalues in a counter-clockwise fashion.
E.g.: Consider N = 4
Matrix= {a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p}
Your function should output: dcbaeimnoplhgfjk

LeetCode problem


11. Largest Sum Sub Array
Find the largest sum contiguous sub array. The length of the returned sub array must beat least of length 2.

LeetCode Problem


12. Advisered Average Number
Write a program to display the advisered average for the list of numbers my omitting the three largest number in the series.
E.g:3,6,12,55,289,600,534,900,172. avg=(3+6+12+55+289+172) /6and eliminating534,900,600


13. Count And Say
First,let user input a number, say 1. Then, the function will generate the next 10numbers which satisfy this condition: .
1, 11,21,1211,111221,312211...
explanation: first number 1, second number is one 1, so 11. Third number is two1(previous number), so 21. next number one 2 one 1, so 1211 and so on...

LeetCode Problem


14. Valid Password
In 1-9 keypad one key is not working. If someone enters a password then not working key will not be entered. You have given expected password and entered password. Check that entered password is valid or not. Ex: entered 164, expected 18684 (you need to take care as when u enter18684 and 164 only both will be taken as 164 input)

 

 


15. Verify Password
Verify if the given password is valid/invalid
1. must be 5-12 characters long -google 1point3acres
2. must contain at least one number and one lowercase character
3. a sequence must not be followed by the same sequence (like 123123qs isinvalid, 123qs123 is valid)


16. Snake Sequence
You are given a grid of numbers. A snakesequence is made up of adjacent numbers such that for each number, the numberon the right or the number below it is +1 or -1 its value. For example,
1 3 2 6 8
-9 7 1 -1 2
1 5 0 1 9 . visit 1point3acres.com for more.
In this grid, (3, 2, 1, 0, 1) is a snake sequence. Given a grid, find thelongest snake sequences and their lengths (so there can be multiple snakesequences with the maximum length).


17. Mountain Point
Given a M * N matrix, if the element in thematrix is larger than other 8 elements who stay around it, then named thatelement be mountain point. Print all the mountain points.


18. Additive Number
Anadditive sequence is 1,2,3,5,8,13 where T(n) = T(n -1) + T(n - 2). A numberrange is given to you. Find the additive sequence number in that range.
Given the start and an ending integer as userinput, generate all integers with the following property.


19. Fibbonaci Number
There is one kind of numbers call FibbonaciNumber, which satisfy the following situation:
A. can be spilt into several numbers;
B. The first two number are the same, thenext number is equal to the sum of previous two
eg. 112 (2 = 1 + 1), 12,122,436(12 + 12 = 24,12 + 24 = 36)
If you are given a range by the user, findall numbers that are Fibbonaci numbers.


20. Coin Change
Somethingcost $10.25 and the customer pays with a $20 bill, the program will print outthe most efficient "change-breakdown" which is 1 five, 4 ones, and 3quarters. Find the minimum number of coins required to make change for a givensum (given unlimited cumber of N different denominations coin)


21. Separate the number
Print the sequences from the input given bythe user separated by semicolon
e.g.: 4678912356012356
output: 4;6789;123;56;0123;56;


22. Find Max/Min Number
Take a series of integers as input till azero is entered. Among these given integers, find the maximum of the oddnumbers and the minimum of the even integers (not including zero) and printthem.


23. Swapping String
Given two strings, you need to transpose thefirst string to the second string by means of only swaps between 2 consecutivecharacters in the first string. This must be performed by doing a series ofthese swaps in order to get the second string.


24. Mingo
A random generator (like a speakerstanding in a group housie game calls out a number) generates out any numberfrom 1 to 1000. There is a 10X10 matrix. A random generator assigns valuesto each block of this matrix(within 1 to 1000 obviously).
Whenever, a row or a column or a diagonal is fully filled in this 10x10 fromthe numbers called out by the speaker, its called a ‘Mingo‘. Write aprogram that will find first Mingo, then second Mingo, then thirds Mingo...andso forth.

Cipe Coding Summary Part1