Вы находитесь на странице: 1из 2

Question 01

Have the function PentagonalNumber(num) read num which will be a positive integer and


determine how many dots exist in a pentagonal shape around a center dot on the Nth iteration.
For example, in the image below you can see that on the first iteration there is only a single dot,
on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are
31 dots. 

Your program should return the number of dots that exist in the whole pentagon on the Nth
iteration. 

Question No. 02
Have the function MaximalSquare(strArr) take the strArr parameter being passed which will be
a 2D matrix of 0 and 1's, and determine the area of the largest square submatrix that contains all
1's. A square submatrix is one of equal width and height, and your program should return
the area of the largest submatrix that contains only 1's. For example: if strArr is ["10100",
"10111", "11111", "10010"] then this looks like the following matrix: 

For the input above, you can see the bolded 1's create the largest square submatrix of size 2x2, so
your program should return the area which is 4. You can assume the input will not be empty. 
Sample Test Case
Input:{"0111", "1111", "1111", "1111"}
Output:9

Question No, 03
Have the function LongestWord(sen) take the sen parameter being passed and return the largest
word in the string. If there are two or more words that are the same length, return the first word
from the string with that length. Ignore punctuation and assume sen will not be empty. 
Question No. 04
Have the function ClosestEnemyII(strArr) read the matrix of numbers stored in strArr which
will be a 2D matrix that contains only the integers 1, 0, or 2. Then from the position in the matrix
where a 1 is, return the number of spaces either left, right, down, or up you must move to reach
an enemy which is represented by a 2. You are able to wrap around one side of the matrix to the
other as well. For example: if strArr is ["0000", "1000", "0002", "0002"] then this looks like the
following: 

For this input your program should return 2 because the closest enemy (2) is 2 spaces away from
the 1 by moving left to wrap to the other side and then moving down once. The array will contain
any number of 0's and 2's, but only a single 1. It may not contain any 2's at all as well, where in
that case your program should return a 0. 

Question No. 05
Have the function LetterChanges(str) take the str parameter being passed and modify it using
the following algorithm. Replace every letter in the string with the letter following it in the
alphabet (ie. c becomes d, z becomes a). Then capitalize every vowel in this new string (a, e, i, o,
u) and finally return this modified string. 

Вам также может понравиться